## Programming 1

Put your programming skills to the test in these challenges.

### Re: Programming 1

I have not done this one yet but i think i will do it differently.

It are single words. Letters are hustled but not encoded.if you replace al letters by ascii value and then sort all the words in numerical form (acs/desc what you want). The words in the scrambled list and in the given list will appear as the same number or have the same value if you will. Then just look em up. so;

for every unscrambled word to look up and in the wordlist:
- replace all letters with ascii value
- sort(all words)
- sort(the word list)

Using arrays this would be fairly simple.

Using byte of math you could also reduce the length of the target list before the loop up:
by calculating the average of all numbers in the list you can discard the upper or lower half of the list.

Am i right or making a mistake?
dm79
New User

Posts: 6
Joined: Fri Apr 18, 2008 3:34 pm
Blog: View Blog (0)

### Re: Programming 1

Quite possibly a mistake. Plus it sounds more complicated than just plain ol' sorting. For example, a "word" that contained two '9's would be equal to a single lowercase 'r.' Of course this is a rough example.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.

fashizzlepop
Developer

Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)

### Re: Programming 1

fashizzlepop wrote:Quite possibly a mistake. Plus it sounds more complicated than just plain ol' sorting. For example, a "word" that contained two '9's would be equal to a single lowercase 'r.' Of course this is a rough example.

You probaly right. I make it to complicated. Gona do it now so ill know in a hour.

Thanks for the reply.
dm79
New User

Posts: 6
Joined: Fri Apr 18, 2008 3:34 pm
Blog: View Blog (0)

### Re: Programming 1

May I ask what language you plan on using? For example, in Perl, this can be done extremely easily as it has a built in "sort" command.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.

fashizzlepop
Developer

Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)

### Re: Programming 1

fashizzlepop wrote:May I ask what language you plan on using? For example, in Perl, this can be done extremely easily as it has a built in "sort" command.

Have done it already. Done it in visual basic Fast and easy. Used arrays and regular sorting of letters instead of numbers. Worked perfectly. I have a tendency to make things harder then they are:)

Thx for the input on this!
dm79
New User

Posts: 6
Joined: Fri Apr 18, 2008 3:34 pm
Blog: View Blog (0)

### Re: Programming 1

No problem, and stay sexy. Oh wait, you are using VB? Never mind. Very NOT sexy.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.

fashizzlepop
Developer

Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)

### Re: Programming 1

I have just done this in PHP, it requires a deft copy and paste manuever... but certainly doable in the time allotted.

Has anyone else done this in PHP? The following function is at the core of my solution... but not enough to be a spoiler.

Code: Select all
`function characterCount(\$word){   \$counts = array();   foreach(count_chars(strtolower(\$word), 1) as \$char => \$count)   {     \$counts[] = (chr(\$char).':'.\$count);   }   return(implode(',', \$counts));} `

tremor77

Posts: 1097
Joined: Wed Mar 31, 2010 12:00 pm
Location: New York
Blog: View Blog (0)

### Re: Programming 1

fashizzlepop wrote:No problem, and stay sexy. Oh wait, you are using VB? Never mind. Very NOT sexy.

LOL. You got me there. Used VB instead of C++ / Perl who are much sexier. I know. I am an opportunist and I will use whatever gets the job done at minimal effort. VB was fast, forgiving with arrays/data typing and it did the trick. If speed and 100% accuracy was crucial I would have done it in C++.

And by the way: it takes milliseconds at run time to resolve the the list. Thats not a problem as well.

Keep up the grove:)
dm79
New User

Posts: 6
Joined: Fri Apr 18, 2008 3:34 pm
Blog: View Blog (0)

### Re: Programming 1

dm79 wrote:
fashizzlepop wrote:No problem, and stay sexy. Oh wait, you are using VB? Never mind. Very NOT sexy.

LOL. You got me there. Used VB instead of C++ / Perl who are much sexier. I know. I am an opportunist and I will use whatever gets the job done at minimal effort. VB was fast, forgiving with arrays/data typing and it did the trick. If speed and 100% accuracy was crucial I would have done it in C++.

And by the way: it takes milliseconds at run time to resolve the the list. Thats not a problem as well.

Keep up the grove:)

No worries. That's why I like Perl, it's quick and dirty AND very forgiving too.

I originally did it in PHP with a form and POST lol... Worked fine for me too.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.

fashizzlepop
Developer

Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)

### Re: Programming 1

I'm a complete noob but I did it with a method kind of similar to what DM79 is suggesting. Chucked the word list into Excel, split the words so that it was one letter per cell, used CODE() to get a numerical value for each letter, and took the product of each row to give me a unique number for each word.

There are a few things that you need to iron out, but I'm not going to give it all away

Took me about 45 mins, which considering I haven't got a clue what I'm doing is probably about 100 times less than the rest are going to take me...

Though I'd just chuck it out there as how a non-programmer did it.
New User

Posts: 1
Joined: Wed Sep 08, 2010 2:00 am
Blog: View Blog (0)

PreviousNext