Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mid(x,y)
- midpoint = (x + y) / 2.0
- end
- def prime(value,n)
- check = true
- num = sqrt(value,n)
- n = num.round
- start = 2
- while start <= n
- if value % start == 0
- check = false
- end
- start = start + 1
- end
- check
- end
- def sqrt(n,d)
- #n is the square root value to the determined
- #d is the difference inputed
- low = 0
- #low means the starting point of the iteration
- high = n
- guess = (high + low) / 2.0
- until (guess*guess) - n <= d && (guess*guess) -n >= 0 do
- if (guess*guess) - n > d
- high = guess
- end
- if (guess*guess) - n < 0
- low = guess
- end
- guess = (low + high)/2
- end
- guess
- end
- value = prime(81,0.0000000003)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement