Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

WESUN 5 letter food puzzle from 12 Aug 2001

by idnopheq (Chaplain)
on Aug 12, 2001 at 18:43 UTC ( [id://104248]=CUFP: print w/replies, xml ) Need Help??

Hi, All!

While listening to Weekend Edition Sunday, the puzzle offered up for next week made for a fun, toss-off bit of perl.

Name a well-known international food in five letters. Move the first two letters to the end. The result will be another well-known international food in five letters. What foods are these? They are both foods that originated overseas, but are now popular in the United States and around the world.

I wrote this script in about 5 minutes, but it took me about an hour to find a dictionary to help with the answer. Anyway, peruse and enjoy! Any advice of more efficient means to accomplish this is solicited and welcome!

UPDATE: I've been thinking that the substrs could be replaced with pack and unpack, and I just figured out how. UPDATE 2: I also changed the lengthy comment to pod.

#!/usr/bin/perl -w #-*-cperl-*- use strict; =pod puzzle.pl - print a list of five letter words for a puzzle answer usage: puzzle.pl [dictionary_file] This script addresses the 12 August 2001 puzzle from Weekend Edition Sunday puzzle ( http://www.npr.org/programs/wesun/puzzle/ ) Name a well-known international food in five letters. Move the first two letters to the end. The result will be another well-known international food in five letters. What foods are these? They are both foods that originated overseas, but are now popular in the United States and around the world. We cycle through a dictionary file, either one provided on the command line or the standard dictionary ( /usr/share/dict/words on many *nix ). We find words that fit the above criteria and print them out. You'll have to do the definition legwork, unless you want to write some tool to do that, too. =cut my $dictionary = $ARGV[0] || "/usr/share/dict/words"; open ( DICT, "< $dictionary" ) or die "Cannot open $dictionary: $!\n"; my %fives; foreach ( <DICT> ) { # go through the dictionary chomp; # strip the /n $fives{$_} = undef # slap them into a hash if ( length $_ == 5 ); # we only want 5 letter words } close DICT; foreach my $word ( keys %fives ) { # cycle thru the 5 letter words $_ = pack ( # put it back together "A3 A2", ( # back-end first unpack ( # split it, moving ahead 2 "x2 A3 X5 A2", # take 3, go back 5 $word # and take 2 ) ) ); print $word , "\t" , $_ , "\n" # print the result & orig. word if ( exists $fives{$_} ); # if the result is a real word }

HTH
--
idnopheq
Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.

Replies are listed 'Best First'.
Re: WESUN 5 letter food puzzle from 12 Aug 2001
by dmmiller2k (Chaplain) on Aug 22, 2001 at 17:10 UTC

    You don't mean Sasal and Salsa, do you?

    dmm

    Just call me the Anti-Gates ...
    
      I got chili and lichi, one of the alternate answers ... never heard of sasal before, tho salsa is one of my condiments of choice.

      The hard part was finding a dictionary to get even a single match. I think I went through four before I found one with lichi in it.

      HTH
      --
      idnopheq
      Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.

        I think the most likely answer is tapas and pasta.

        I found 60 matches in my word list, although most of them are not foods, of course. perl -lne'/^(..)(.)(..)$/and$w{"$2$3$1"}=$w{"$3$1$2"}=$_;print"$w{$_} $_"if$w{$_}' wordlist

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://104248]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2025-12-06 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (85 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.