Last active
August 29, 2015 14:10
-
-
Save lqez/e0acd5fcf8db9ec985b7 to your computer and use it in GitHub Desktop.
Let's try monkeysort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import shuffle | |
s = list('typewriter') | |
tried = 0 | |
while(True): | |
tried += 1 | |
shuffle(s) | |
if ''.join(s) == 'eeiprrttwy': | |
break | |
print tried, s |
P R O F I T
use List::Util 'shuffle';
@s = split //, 'typewriter';
$tried = 0;
while (1) {
@s = shuffle(@s);
last if join( '', @s ) eq 'eeiprrttwy';
$tried++;
}
print "$tried [@s]\n";
___DATA__
$ time perl a.pl
653881 [e e i p r r t t w y]
1.235 secs
노잼.. i cri..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ time python monkeysort.py
206832 ['e', 'e', 'i', 'p', 'r', 'r', 't', 't', 'w', 'y']
real 0m1.416s
user 0m1.289s
sys 0m0.044s