Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- #
- round() {
- echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
- }
- is_prime() {
- n="$1"
- if [[ "$n" -lt 2 ]]; then
- echo "false"
- return 0
- elif [[ "$n" -eq 2 ]]; then
- echo "true"
- return 0
- elif (( "$n" % 2 == 0 )); then
- echo "false"
- return 0
- fi
- result=true
- search_limit=$(echo "sqrt($n)" | bc)
- for i in $(seq 3 $search_limit 2); do
- echo $i
- if (( $n % $i == 0 )); then
- result=false
- break
- fi
- done
- echo $result
- }
- is_prime "61"
- count=1
- for ((i=1; i<=200; i++)); do
- r=$(shuf -i 63235-3548569 -n 1)
- result=$(is_prime $r)
- echo "$count | $r | $result"
- count=$((count + 1))
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement