acer

32827 Reputation

29 Badges

20 years, 134 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Sorry, it isn't clear to me whether you want the numbers 8,4,4,7 or the pools like "tuv", etc. I'm trying to write code below that is more understandable than maximally efficient -- hope that's ok.

> t2 := "abc": t3 := "def": t4 := "ghi": t5 := "jkl":
> t6 := "mno": t7 := "pqrs": t8 := "tuv": t9 := "wxyz":
> T:=[t2,t3,t4,t5,t6,t7,t8,t9]:

> dec := proc(w::string,T)
>    local c, t, S;
>    for c in w do
>       for t from 2 to 9 do
>          if StringTools:-Search(c,T[t-1]) > 0 then
>             S[c]:=T[t-1];
>             break;
>          end if;
>       end do;
>    end do;
>    seq(S[c], c in op(w));
> end proc:

> dec( "this", T );

                  "tuv", "ghi", "ghi", "pqrs"

> dec( "abraham", T );

        "abc", "abc", "pqrs", "abc", "ghi", "abc", "mno"

I was wondering whether you were going to ask a tougher variant of your original question, such as how to find all phrases (of say 2-letter through 7-letter words) from a seven or 10 digits phone number.

I haven't this sort of fun since a code theme a few years ago.

acer

Sorry, it isn't clear to me whether you want the numbers 8,4,4,7 or the pools like "tuv", etc. I'm trying to write code below that is more understandable than maximally efficient -- hope that's ok.

> t2 := "abc": t3 := "def": t4 := "ghi": t5 := "jkl":
> t6 := "mno": t7 := "pqrs": t8 := "tuv": t9 := "wxyz":
> T:=[t2,t3,t4,t5,t6,t7,t8,t9]:

> dec := proc(w::string,T)
>    local c, t, S;
>    for c in w do
>       for t from 2 to 9 do
>          if StringTools:-Search(c,T[t-1]) > 0 then
>             S[c]:=T[t-1];
>             break;
>          end if;
>       end do;
>    end do;
>    seq(S[c], c in op(w));
> end proc:

> dec( "this", T );

                  "tuv", "ghi", "ghi", "pqrs"

> dec( "abraham", T );

        "abc", "abc", "pqrs", "abc", "ghi", "abc", "mno"

I was wondering whether you were going to ask a tougher variant of your original question, such as how to find all phrases (of say 2-letter through 7-letter words) from a seven or 10 digits phone number.

I haven't this sort of fun since a code theme a few years ago.

acer

And, for longer words,

> with(StringTools):
> with(PatternDictionary):
> dict:=Create('builtin'):
> L:=select(IsLower,select(IsAlpha,[seq](Get(dict,i),
>                                        i=1..Size(dict)-1))):

> t2 := "abc": t3 := "def": t4 := "ghi": t5 := "jkl":
> t6 := "mno": t7 := "pqrs": t8 := "tuv": t9 := "wxyz":

> findem := proc()
> global L;
> local i, T, numfound, thist, sol, thiswordlist, z, n;
>    n := nargs;
>    thiswordlist := select(z->length(z)=n,L);
>    T:=combinat:-cartprod([seq([LengthSplit(args[i],1)],
>                               i=1..nargs)]):
>    numfound:=0:
>    while not T[':-finished'] do
>       thist := cat(op(T[':-nextvalue']()));
>       if member(thist,thiswordlist) then
>          numfound:=numfound+1;
>          sol[numfound]:=thist;
>       end if;
>    end do:
>    if numfound > 0 then
>       convert(sol,list);
>    else NULL;
>    end if;
> end proc:

> findem(t4,t7);

                                   ["is"]

> findem(t2,t6);

                                ["am", "an"]

> findem(t3,t6);

                             ["do", "em", "en"]

> findem(t6,t2,t3,t2);

> findem(t2,t6,t6);

                        ["bon", "boo", "con", "coo"]

> findem(t6,t4,t6,t3);

                          ["mind", "mine", "nine"]

acer

And, for longer words,

> with(StringTools):
> with(PatternDictionary):
> dict:=Create('builtin'):
> L:=select(IsLower,select(IsAlpha,[seq](Get(dict,i),
>                                        i=1..Size(dict)-1))):

> t2 := "abc": t3 := "def": t4 := "ghi": t5 := "jkl":
> t6 := "mno": t7 := "pqrs": t8 := "tuv": t9 := "wxyz":

> findem := proc()
> global L;
> local i, T, numfound, thist, sol, thiswordlist, z, n;
>    n := nargs;
>    thiswordlist := select(z->length(z)=n,L);
>    T:=combinat:-cartprod([seq([LengthSplit(args[i],1)],
>                               i=1..nargs)]):
>    numfound:=0:
>    while not T[':-finished'] do
>       thist := cat(op(T[':-nextvalue']()));
>       if member(thist,thiswordlist) then
>          numfound:=numfound+1;
>          sol[numfound]:=thist;
>       end if;
>    end do:
>    if numfound > 0 then
>       convert(sol,list);
>    else NULL;
>    end if;
> end proc:

> findem(t4,t7);

                                   ["is"]

> findem(t2,t6);

                                ["am", "an"]

> findem(t3,t6);

                             ["do", "em", "en"]

> findem(t6,t2,t3,t2);

> findem(t2,t6,t6);

                        ["bon", "boo", "con", "coo"]

> findem(t6,t4,t6,t3);

                          ["mind", "mine", "nine"]

acer

I second the sentiment: unless you have some special circumstance then at the very least try using the Standard GUI.

Do you know that you can configure the Standard GUI to deal in quite familiar looking Worksheets, using 1D notation input? (Those are not defaults, but you can set them as GUI options and even save them as global preferences.)

In Classic, you can also first issue plotsetup(maplet) and get a Java-based plotter that supports more 2D Math. That plotter will show nicely typeset subscripts using your original example's syntax plot(y[r]^2,labels=[y[r],x[c]]) . But it will not display the plots inlined in the worksheet, and that may be less desirable for you.

acer

I second the sentiment: unless you have some special circumstance then at the very least try using the Standard GUI.

Do you know that you can configure the Standard GUI to deal in quite familiar looking Worksheets, using 1D notation input? (Those are not defaults, but you can set them as GUI options and even save them as global preferences.)

In Classic, you can also first issue plotsetup(maplet) and get a Java-based plotter that supports more 2D Math. That plotter will show nicely typeset subscripts using your original example's syntax plot(y[r]^2,labels=[y[r],x[c]]) . But it will not display the plots inlined in the worksheet, and that may be less desirable for you.

acer

@quanta I'll try and find time to give it a shot on Win7. (My cygwin's gcc is doing ABI=32, I think. But with some time I ought to be able to figure out using mingw for it. Maybe I can get the ABI=64 for gmp using the appropriate msvc++. Finding time is often the problem.)

If you enjoy reading older articles on this site, there are some interesting ones available under various "tag" pages. I like the performance and blog tags.

Maybe you were remembering this old post.

acer

@dalmas64

In your other posts, it was shown that supplying Optimization:-Maximize with the optional argunment method=branchandbound generates the correct solution (for your other differing univariate examples).

@dalmas64

In your other posts, it was shown that supplying Optimization:-Maximize with the optional argunment method=branchandbound generates the correct solution (for your other differing univariate examples).

@Robert Israel Thanks, Robert. I don't know why I forgot that.

@Robert Israel Thanks, Robert. I don't know why I forgot that.

Preben is quite correct about the cause.

Another solution is to keep the locals declared as they are, but to change the optional argument to SingularValues to be,

   output = [':-U', ':-S', ':-Vt']

acer

Preben is quite correct about the cause.

Another solution is to keep the locals declared as they are, but to change the optional argument to SingularValues to be,

   output = [':-U', ':-S', ':-Vt']

acer

@bhornsby89 Your worksheet now has it with three with() calls, inside the procedure body. Don't code with(...) inside a proc. It is not guaranteed to work at all.

Instead, try doing it exactly as was suggested and code it with `uses`.

So, replace your three with() calls inside the proc body to be instead the single line,

   uses LinearAlgebra, Statistics, combinat:

@bhornsby89 Your worksheet now has it with three with() calls, inside the procedure body. Don't code with(...) inside a proc. It is not guaranteed to work at all.

Instead, try doing it exactly as was suggested and code it with `uses`.

So, replace your three with() calls inside the proc body to be instead the single line,

   uses LinearAlgebra, Statistics, combinat:
First 454 455 456 457 458 459 460 Last Page 456 of 601