I propose a golf for the shortest code to generate the 100 possible combinations for a Master Lock combination lock when the last number is known.[1]
When the last number is known, the first number has the same remainder as the last number when divided by 4. The second number is one of the possible first numbers plus 2 (wrapping to 0 at 40). The range of numbers is 0 to 39.
Example output if the last number is 19:
3-5-19
3-9-19
3-13-19
...
39-33-19
39-37-19
39-1-19
My current attempt is posted below. Enjoy :)
(I suspect further restrictions can be made to the key space to reduce the number of possible combinations (ie first and last number can't be the same) but this initial iteration does not consider these.)
[1] With reference to:
http://www.dontforward.com/masterlock.htm
http://www.fusor.us/lockpick.html
My attempt, 81 characters ...
master_lock_combo(19);
sub master_lock_combo
{
#0 1 2 3 4 5
#12345678901234567890123456789012345678901234567890
@x=grep{$_[0]%4==$_%4}0..39;for $i(@x){for
(map{($_+2)%40}@x){print"$i-$_-$_[0]\n"}}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.