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

Re^2: list of four digit lock combinations without repeated digits

by Lotus1 (Vicar)
on Jun 22, 2018 at 14:58 UTC ( [id://1217206]=note: print w/replies, xml ) Need Help??


in reply to Re: list of four digit lock combinations without repeated digits
in thread list of four digit lock combinations without repeated digits

I tried out your glob approach at number generation to understand it. Thanks for posting. I'm always trying to learn more about the usage of glob(). I found I could simplify your $globStr declaration like this:

use warnings; use strict; my $digit_pattern = '{0,1,2,3,4,5,6,7,8,9}' x 4; print "$_\n" foreach glob $digit_pattern;

When I saw your solution I realized I didn't need to test for the key existence in the hash. I could simply assign to the key. Thanks again.

Edit:

sort keys { map { $_ => 1 } grep { ! m{(.).*\1} } map { join q{}, sort split m{} } glob $globStr };
I forgot to mention before an optimization I noticed: if there is a repeated digit in the number then there's no need to split and sort it. If you put the grep line after the map, join, sort, split line then it will filter out the repeats before the split(). The split, sort and assign to a hash approach is the exact same one that I took but mine were inside a foreach loop instead of in a map (loop).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-19 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found