Skip to content

Instantly share code, notes, and snippets.

@nanase
Created March 19, 2016 08:01
Show Gist options
  • Save nanase/2b882fac8ecc8547f81f to your computer and use it in GitHub Desktop.
Save nanase/2b882fac8ecc8547f81f to your computer and use it in GitHub Desktop.
試し割りで素数判定するParrotのプログラム書いてみた
.sub main :main
.param pmc args
$I0 = args
if $I0 >= 2 goto check1
say 'No input value specified.'
end
check1:
$S0 = args[1]
$I1 = $S0
$S1 = $I1
if $S0 == $S1 goto check2
say 'Please specify a integer.'
end
check2:
print $I1
print ' is '
check3:
if $I1 < 2 goto not_prime
if $I1 == 2 goto prime
$I2 = $I1 % 2
if $I2 == 0 goto not_prime
$N0 = sqrt $I1
$I3 = 3
loop_begin:
if $I1 == $I3 goto prime
$I4 = $I1 % $I3
if $I4 == 0 goto not_prime
$N1 = $I3
if $N1 >= $N0 goto prime
$I3 += 2
goto loop_begin
prime:
say 'prime number.'
end
not_prime:
say 'not prime number.'
end
.end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment