Re: challenge: phone number to words

• To: mathgroup at smc.vnet.net
• Subject: [mg20901] Re: challenge: phone number to words
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Sat, 20 Nov 1999 01:07:14 -0500 (EST)
• References: <812a4q\$1ec@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Daniel,

w[l_]:=StringJoin /@ Distribute[Characters at {"0", "1", "ABC", "DEF", "GHI",
"JKL", "MNO", "PRS", "TUV","WXY"}[[l + 1]], List]

w[l_]:=StringJoin /@ Distribute[Characters@(ToString /@ {0, 1, ABC, DEF,
GHI, JKL, MNO, PRS, TUV, WXY})[[l + 1]], List]

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

Daniel Reeves <dreeves at eecs.umich.edu> wrote in message
news:812a4q\$1ec at smc.vnet.net...
> My colleague and I were having a "C vs Mathematica" debate and ended up
> having a contest to see who could write the most compact program to take a
> list of digits and return all the possible words corresponding to it on a
>
> Here's his C version, at 333 bytes:
>
> #include <stdio.h>
> #define R argc
> #define V argv
> int main(int R, char *V[]) {
> int i,c; char *a="_0___1___ABC_DEF_GHI_JKL_MNO_PRS_TUV_WXY_";
> for(i=1;i<R;i++) V[i]=a+1+4*(*V[i]-'0');for(;;){for(c=1,i=1;i<R;i++){
> printf("%c%s",*V[i],R-1==i?"\n":"");if(c){c=0;if('_'==*++V[i]){
> if(R-1==i)return 0;c=1;while ('_'!=*(V[i]-1)) --V[i];}}}}}
>
>
> And here's my Mathematica version, at 125 bytes:
>
> w[l_]:=StringJoin/@Distribute[Extract[Characters/@{"0","1","ABC",
> "DEF","GHI","JKL","MNO","PRS","TUV","WXY"},List/@l+1],List]
>
>
> So I thought I'd challenge the group to improve on either of these...
>
> --    --    --    --    --    --    --    --    --    --    --    --
> Daniel Reeves               http://ai.eecs.umich.edu/people/dreeves/
>
> "The idea of programming in a low level language like C will seem as
> specialized and esoteric as programming in microcode or assembler
> seems today."  -- Stephen Wolfram, creator of Mathematica
>
>
>
>

```

• Prev by Date: What kind of math problem is this?
• Next by Date: RE: Question on plotting parametric surfaces
• Previous by thread: Re: challenge: phone number to words
• Next by thread: Re: Directory of the open notebook