Advertisement
zvoulgaris

Pandigital Squares

Sep 29th, 2020 (edited)
3,300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.69 KB | None | 0 0
  1. # pandigital squares drill
  2.  
  3. const digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
  4.  
  5. function is_pandigital(n::Integer)::Bool
  6.     n_string = string(n);
  7.     if length(n_string) != 10; return false; end
  8.  
  9.     for digit in digits
  10.         if !contains(n_string, digit); return false; end
  11.     end
  12.  
  13.     true
  14. end
  15.  
  16. function main()
  17.     a = floor(Int64, sqrt(1000000000)); # no point testing numbers less than this one
  18.     b = floor(Int64, sqrt(9999999999)); # no point testing numbers larger than this one
  19.  
  20.     for i = a:b
  21.         n = i^2;
  22.  
  23.     if (n % 3 == 0) && (n % 10 != 0) # expediting process by mitigating search space...
  24.             is_pandigital(n) && println(n)
  25.     end
  26.     end
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement