Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Help uberfish get extra credit!


ghost's Avatar
0 0

hey… so our math teacher is offering extra credit. heres the situations:

a=1 b=2 c=3 . . . z=26

find single words that add up to 100 exactly.

for example: pussy.

lol. i have around 8.. and whoever comes up with the most in class gets 20 extra credit points. help is appreciated!


ghost's Avatar
0 0

where can i learn programming skills. i only know html.


ghost's Avatar
0 0

attitude


ghost's Avatar
0 0

could be pretty easy if you had a good wordlist. write the program to reach each letter then assign it a value, then add up the vaule, if it is equal to 100, print it to a file.

easy 20ppts extra credit.


richohealey's Avatar
Python Ninja
0 0

i did this in 8 lines of python


ghost's Avatar
0 0

shit eh rich? only 8? not really optimizing these days then?

lol, u python freak u


ghost's Avatar
0 0

hehe, beat you richo. i did it in 7 of php (assuming you dont count the lines for { and } , i could move them. if python used { } rather than tabbing, i'd still win)

:D

[edit]

down to 6 lines now, but only with a REALLY NASTY hack


spyware's Avatar
Banned
0 0

only_samurai wrote: down to 6 lines now, but only with a REALLY NASTY hack

Does it loop through ALL possibilities?

Also: markupaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa


ghost's Avatar
0 0

it uses a wordlist, just like richo's. i was trying to beat him


spyware's Avatar
Banned
0 0

-cL wrote: He need actual words so why would he loop through non-existent words like fsfgofdgn?

Meh, I was thinking of first making a word list with all the 100-words and then comparing it to a word list. Not optimal though.


ghost's Avatar
0 0

just because im a code whore… its now down to 5 lines of php code.


ghost's Avatar
0 0

only_samurai wrote: just because im a code whore… its now down to 5 lines of php code.

only_samurai linked me to this and challenged my php-manhood, so I stepped up and now have a single line of PHP code to do this.

Required: A text file (wordlist.txt) with each word on a new line. Capitalization, non-alpha characters are automatically removed. This of course can be fixed without haivng to add a new line (regex ftw).

markupforeach( explode("\n",file_get_contents("wordlist.txt")) as $word ) if( array_sum(array_map('ord',str_split(preg_replace('/[^a-zA-Z]?/i','',strtolower($word)))))-(96*strlen(preg_replace('/[^a-zA-Z]?/i','',strtolower($word)))) == 100 ) echo $word;

Basically I use file_get_contents to load entire file into a string, explode on /n, then have an if statement where I lowercase the string, remove non alpha characters, split the string (into an array of characters), run array_map() using ord() as my callback (ord converts a character to its ASCII value), run array_sum() to total up the array, then subtract 96 (lowercase 'a' is 97 in ASCII) times the length of the lowercased, non-alpha stripped string (the same string we split earlier). The if statement compares that to 100 and if true, we echo our word.

More can be done on the echo statement to remove window's trailing /r and formatting issues, but mreh I've proved my fu.


ghost's Avatar
0 0

i think i would have eventually gotten there. nicely done mate. :D


ghost's Avatar
0 0

lol.. i'm getting lets see…no where with this =p =D

but i'm gunna keep trying!

(feel free to post a few results:P)