Last active
August 29, 2015 14:00
-
-
Save masak/11136998 to your computer and use it in GitHub Desktop.
Python and Perl 6 are kinda similar :)
This file contains 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
given open('words') -> $f { | |
LEAVE { $f.close } | |
for $f.lines -> $line { | |
next if $line.chars == 1; | |
if $line.flip eq $line { | |
say $line | |
} | |
} | |
} | |
# timings: 22.992 23.286 21.584 22.870 21.848 22.146 21.613 22.186 21.841 22.497 | |
# average: 22.2863 | |
# standard deviation: 0.600852551703734 |
This file contains 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
with open('words') as f: | |
for line in f: | |
line = line.rstrip() | |
if len(line) == 1: | |
continue | |
if line[::-1] == line: | |
print line | |
# timings: 0.303 0.182 0.192 0.197 0.185 0.170 0.180 0.146 0.209 0.206 | |
# average: 0.197 | |
# standard deviation: 0.041464844547319 |
This file contains 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
$ perl6 -e 'sub mp($c, $w) { [$c - $w, $c + $w] }; | |
my $SCALING = 5; | |
for mp(22.2863, 0.600852551703734), mp(0.197, 0.041464844547319) -> [$l, $h] { | |
say " " x ($l * $SCALING - 1), "|", "-" x (($h - $l) * $SCALING - 1), "|" | |
}' | |
|-----| | |
|| |
This file contains 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
$ perl6 -e 'say "Rakudo is {22.2683 / 0.197} as slow as Python on this task."' | |
Rakudo is 113.037056 as slow as Python on this task. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment