To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.off-topic.geekOpen lugnet.off-topic.geek in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Off-Topic / Geek / 2928
2927  |  2929
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:
  Re: Reasonable assignment for a third grader?
 
(...) not going into a holy war, it's a mess cause I Wanted it to be :) the original form was 10 lines, and quite readable :) (...) keyboards kissers - not sure if 'kissers' is a word, but I think 'keyboards' should qualify... :) (24 years ago, 12-Apr-01, to lugnet.off-topic.geek)

Message is in Reply To:
  Re: Reasonable assignment for a third grader?
 
(...) I couldn't help it... and it's my first attempt at a one liner :) perl -ne 'BEGIN{for('a'..'z')...f$t==100;' /usr/dict/linux.words comes out with 498 words out of 45402 in the file... pretty fast too :) (24 years ago, 12-Apr-01, to lugnet.off-topic.geek)

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
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR