Advertisement
caubert

isPrime

Feb 25th, 2020 (edited)
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.48 KB | None | 0 0
  1. {{/* Now try to find the Prime using Square Root as well */}}
  2. {{ $noPrime := false }}
  3. {{ $n := (parseArgs 1 "" (carg "int" "int" -1 10000 ) ).Get 0 }}
  4. {{ if le $n 1 }}
  5.     {{/* breaks here */}}
  6.     {{ $noPrime = true }}
  7. {{ else }}
  8.     {{- range seq 2 $n }}
  9.         {{- if not (mod $n .) }}
  10.             {{/* breaks here */}}
  11.             {{- $noPrime = true }}
  12.         {{- end }}
  13.     {{- end }}
  14. {{ end }}
  15. {{ if not $noPrime }}
  16.     {{ printf "%d is a prime" $n }}
  17. {{ else }}
  18.     {{ printf "%d is not a prime" $n }}
  19. {{ end }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement