046 Goldbach s other conjecture.sf 404 B

12345678910111213141516171819202122
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # Edit: 25 July 2021
  4. # https://github.com/trizen
  5. # What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
  6. # https://projecteuler.net/problem=46
  7. # Runtime: 0.307s
  8. 3..Inf `by` 2 -> lazy.grep{ .is_composite }.each {|n|
  9. 1..isqrt(n>>1) -> any {|i|
  10. is_prime(n - 2*i*i)
  11. } && next
  12. say n
  13. break
  14. }