Subject:
|
Re: Reasonable assignment for a third grader?
|
Newsgroups:
|
lugnet.off-topic.geek
|
Date:
|
Thu, 12 Apr 2001 13:58:44 GMT
|
Viewed:
|
80 times
|
| |
| |
In article <slrn9dbcub.q9.dan@dodge.rv.tis.com>,
Dan Boger <dan@peeron.com> wrote:
> I couldn't help it... and it's my first attempt at a one liner :)
>
> perl -ne 'BEGIN{for('a'..'z'){$v{$_}=$v{uc$_}=++$c}}$t=0;for(split//){$t+=$v{$_}};print"$_"if$t==100;' /usr/dict/linux.words
Neither could I. This one's on sloaris, and I apologize for my mediocre coding
style. It's still much more readable than that perl mess ever hoped to be, but
probably took me longer. :)
#include <stdio.h>
int fd;
FILE *fi;
char buf[20];
int len;
int counter;
int sum;
int main(void)
{
fi = fopen("/usr/dict/words", "r"); /* open the words file */
fgets(buf, 20, fi); /* okay, so I coulda tossed these in the */
len = strlen(buf); /* loop. Sue me. */
while (!feof(fi))
{
sum = 0;
for(counter = 0; counter < (len-1); counter++)
{
sum = sum + buf[counter] - (int)'a' + 1; /* I like this trick*/
} /* len -1 to skip */
if (sum == 100) /* the cr */
{
printf("100 score for: %s", buf); /* but it's still */
} /* there, so no \n. */
fgets(buf, 20, fi);
len = strlen(buf);
}
fclose(fi);
}
It finds 220 such words out of the 25,000 in the Sloaris /usr/dict/words,
none of which start with k, x, or z.
-JDF
--
J.D. Forinash ,-.
foxtrot@cc.gatech.edu ( <
The more you learn, the better your luck gets. `-'
|
|
Message has 1 Reply:
Message is in Reply To:
20 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|