Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Inputing vectors into a scrabble-esque game

by johngg (Canon)
on Nov 02, 2019 at 16:40 UTC ( [id://11108248]=note: print w/replies, xml ) Need Help??


in reply to Re: Inputing vectors into a scrabble-esque game
in thread Inputing vectors into a scrabble-esque game

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

Replies are listed 'Best First'.
Re^3: Inputing vectors into a scrabble-esque game
by GrandFather (Saint) on Nov 03, 2019 at 10:03 UTC

    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://11108248]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found