Advertisement
zvoulgaris

Alchemical Reduction drill

Sep 10th, 2019
1,534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.55 KB | None | 0 0
  1. # Alchemical Reduction drill
  2.  
  3. function reduce(x::Char, y::Char)
  4.   if (x != y) && ((x == lowercase(y)) || (y == lowercase(x)))
  5.     return ""
  6.   else
  7.     return string(x,y)
  8.   end
  9. end
  10.  
  11. function reduce(z::AbstractString, n::Int64)
  12.   for i = 2:n
  13.     x = z[i-1]
  14.     y = z[i]
  15.     new = reduce(x, y)
  16.  
  17.     if length(new) == 0
  18.       return string(z[1:(i-2)], z[(i+1):end]), 1
  19.     end
  20.   end
  21.  
  22.   return z, -1
  23. end
  24.  
  25. function main(z::AbstractString)
  26.   while true
  27.     n = length(z)
  28.     z, flag = reduce(z, n)
  29.     if flag == -1; return z; end
  30.   end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement