Skip to content

Instantly share code, notes, and snippets.

Created September 29, 2010 16:43
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 anonymous/603084 to your computer and use it in GitHub Desktop.
Save anonymous/603084 to your computer and use it in GitHub Desktop.
pmichaud@orange:/zip/parrot$ cat oh.pir
.loadlib 'math_ops'
.sub 'main' :main
.local pmc hash
hash = new ['Hash']
# loop from 'A' to 'J', create a key of random length and store it
# in the hash
$I0 = ord 'A'
loop1:
if $I0 > 74 goto done1
$S0 = chr $I0
$I1 = rand 10
inc $I1
$S1 = repeat $S0, $I1
hash[$S1] = 1
inc $I0
goto loop1
done1:
# now iterate the hash and display its keys
$P0 = iter hash
loop2:
unless $P0 goto done2
$S0 = shift $P0
say $S0
goto loop2
done2:
.end
pmichaud@orange:/zip/parrot$ RELEASE_2_7_0/parrot oh.pir
EEE
HHHHHH
AA
GGGGG
JJJJJJJJJJ
IIIIII
DDDDDD
BBBBB
FF
CCCCCCCCCC
pmichaud@orange:/zip/parrot$ RELEASE_2_8_0/parrot oh.pir
AAAAAAAA
BB
CC
DDDDD
EEEE
FFFFFFFF
GGGGGG
HHHHHHHHHHH
IIIIIII
JJJJJ
pmichaud@orange:/zip/parrot$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment