This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_prime?(num) | |
2.upto(num-1) { |i| return false if ((num % i) == 0) } | |
true | |
end | |
def this_prime(position) | |
results = [] | |
i = 2 | |
until results.count == position | |
results << i if is_prime?(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_sq_diff(max) | |
sum_sqs = 0 | |
sq_sums = 0 | |
1.upto(max) { |i| sum_sqs += i**2 } | |
1.upto(max) { |i| sq_sums += i } | |
p sq_sums**2 - sum_sqs | |
end |
NewerOlder