in reply to (Golf) Master lock combinations

Just golfing your code further gets me 72:

#0 1 2 3 4 5 6 +7 #123456789012345678901234567890123456789012345678901234567890123456789 +012 for$i(@x=grep$_[0]%4==$_%4,0..39){map{print"$i-",($_+2)%40,"-$_[0]\n"} +@x}

Update: I think I have had a Masterlock with the first number equal to the last.

Replies are listed 'Best First'.
Re^2: (Golf) Master lock combinations
by hv (Prior) on Jun 24, 2005 at 02:48 UTC

    Another minor refinement:

    #0 1 2 3 4 5 6 #123456789012345678901234567890123456789012345678901234567890123456789 for$i(@x=map$_*4+$_[0]%4,0..9){map{print"$i-",($_+2)%40,"-$_[0]\n"}@x}

    Hugo

      A further minor refinement, that exploits the "-" seperator:

      #0 1 2 3 4 5 6 #123456789012345678901234567890123456789012345678901234567890123456789 for$i(@x=map$_*4+$_[0]%4,0..9){map{print$i,2-$_%40,"-$_[0]\n"}@x}

      The other solutions posted that use map to construct the list, rather than grep an existing list, is a nice touch.

        sorry ppl,

        For now I can't do better than hv.

        This example works fine with 19 (and any other number which module is 3, but don't work with 0, 1 or 2 - 17,18 or 20 as last part).

        Is show 202-20 when it should print 20-38-20, for example.