Skip to content

Instantly share code, notes, and snippets.

@masak
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/11136998 to your computer and use it in GitHub Desktop.
Save masak/11136998 to your computer and use it in GitHub Desktop.
Python and Perl 6 are kinda similar :)
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
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
$ 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), "|"
}'
|-----|
||
$ 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