Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl use strict; use warnings; use List::Util "shuffle"; my %dict; my $clear = qx/clear/; my $word; my $dorw; my $words; my %guesses; sub load_dict { open my $dictfile, "/usr/share/dict/words" or die "error $!"; /^([a-z]{3,6})\n/ && push @{$dict{length($1)}}, "$1" while <$dictfi +le>; } sub subwords { [ grep $dorw =~ join(".*", sort split(//, $_)), @{$dict +{$_[0]}} ] } sub set_word { $word = $dict{6}[rand @{$dict{6}}]; $dorw = join "", sort split //, $word; $words = { map {; $_ => subwords($_) } 3..6 }; @guesses{@{$words->{$_}}} = ("_" x $_) x @{$words->{$_}} for 3..6; $^T = time(); return; } my $guess = ''; sub show { print $clear; print "\n",(time-$^T),"\n\n"; print join(" ", ($guess eq '-show' ? @{$words->{$_}} : @guesses{@{$ +words->{$_}}})), "\n\n" for 3..6; print join(" ", shuffle(split //, $word)), "\n"; } sub guess { chomp($guess = <STDIN>); $guesses{$guess} = $guess if exists $guesses{$guess}; set_word if $guess eq '-new'; } print "Enter guesses, -show, or -new. Press Enter to start.\n"; <STDIN>; load_dict(); set_word(); for (;;) { show(); guess() }

In reply to word twist by ysth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found