Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Inputing vectors into a scrabble-esque game

by GrandFather (Saint)
on Oct 31, 2019 at 00:12 UTC ( [id://11108145]=note: print w/replies, xml ) Need Help??


in reply to Inputing vectors into a scrabble-esque game

For purposes of maintenance and code validation the @letter initialization code may be better written:

my @letters = ('a') x 9, ('b') x 2, ('c') x 2, ('d') x 4, ('e') x 12, ('f') x 2, ('g') x 4, ('h') x 2, ('i') x 9, ('j') x 1, ('k') x 1, ('l') x 4, +('m') x 2, ('n') x 6, ('o') x 8, ('p') x 2, ('q') x 1, ('r') x 6, ('s') x 4, +('t') x 6, ('u') x 4, ('v') x 2, ('w') x 2, ('x') x 1, ('y') x 2, ('z') x 1;

and of course you should always use strictures.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: Inputing vectors into a scrabble-esque game
by johngg (Canon) on Nov 02, 2019 at 16:40 UTC

    Perhaps you can save some fiddly typing map'ing the product of two source arrays to produce the @letters array. It doesn't look quite as straightforward but might be less prone to typos.

    use 5.026; use warnings; my @letters = do { my @chars = ( q{a} .. q{z} ); my @counts = ( 9, 2, 2, 4, 12, 2, 4, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1 ); map { ( $chars[ $_ ] ) x $counts[ $_ ] } 0 .. 25; }; say join q{}, @letters;

    Produces:-

    aaaaaaaaabbccddddeeeeeeeeeeeeffgggghhiiiiiiiiijkllllmmnnnnnnoooooooopp +qrrrrrrssssttttttuuuuvvwwxyyz

    I hope this is of interest.

    Cheers,

    JohnGG

      But way less verifiable with a quick look. Keystrokes are much less important than understanding. The long winded suggestion I made is easy to understand even if you don't speak Perl and is easy to check. Anything that breaks the obvious one to one visual mapping between the letter and its repeat count is a step backwards for maintainability and easy understanding.

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-19 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found