Advertisement
zvoulgaris

2Max drill

Jun 5th, 2020
1,185
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 2Max drill
  2.  
  3. function DigitsOf(N::Int64)
  4.     X = split(string(N), "")
  5.     return map(x -> parse(Int64, x), X)
  6. end
  7.  
  8. function FindIntsWithEqualSum(x::Array{Int64, 1})
  9.     n = length(x)
  10.     mnc = div(n * (n-1), 2)
  11.     z = Array{Int64}(undef, n)
  12.     for i = 1:n; z[i] = sum(DigitsOf(x[i])); end
  13.     X = Array{Int64}(undef, mnc, 2)
  14.     c = 0
  15.  
  16.     for i = 1:(n-1)
  17.         for j = (i+1):n
  18.             if z[i] == z[j]; c += 1; X[c,:] = [x[i], x[j]]; end
  19.         end
  20.     end
  21.  
  22.     return X[1:c,:], c
  23. end
  24.  
  25. function main(x::Array{Int64, 1})::Int64
  26.     n = length(x)
  27.     X, c = FindIntsWithEqualSum(x)
  28.  
  29.     if c == 0
  30.         return -1
  31.     else
  32.         return maximum(sum(X, dims = 2))
  33.     end
  34. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement