zvoulgaris

Two Simple Tasks

Jan 5th, 2021 (edited)
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.79 KB | None | 0 0
  1. # Two simple tasks drill - https://programmingpraxis.com/2021/01/05/two-simple-tasks
  2.  
  3. function task1(n::Int64) # I could probably do this in Rust too!
  4.     x = 1;
  5.     m = 5;
  6.  
  7.     while x <= n
  8.         print(x, " ")
  9.         x *= m;
  10.         m = ifelse(m == 5, 2, 5);
  11.     end
  12. end
  13.  
  14. function task2(n::Int64 = 2673) # it's highly unlikely we'll find anything beyond 2673.
  15.     for x = 1:n
  16.         x11 = x / 11;
  17.         x11r = round(x11);
  18.  
  19.         if x11 == x11r
  20.             digits = map(x -> parse(Int64, x), split(string(x), ""));
  21.             s = digits[1]^2;
  22.  
  23.             if length(digits) == 2
  24.                 s += digits[2]^2;
  25.             else
  26.                 s += digits[2]^2 + digits[3]^2;
  27.             end
  28.  
  29.             if s == x11; print(x, " "); end
  30.         end
  31.     end
  32. end
  33.  
  34.  
Add Comment
Please, Sign In to add comment