Skip to content

Instantly share code, notes, and snippets.

@zwilderrr
Created January 17, 2018 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zwilderrr/4a7929fedf15649d23779c4a0e7e114f to your computer and use it in GitHub Desktop.
Save zwilderrr/4a7929fedf15649d23779c4a0e7e114f to your computer and use it in GitHub Desktop.
def num_seq(seq)
split_seq = seq.to_s.chars.map(&:to_i)
index = 0
range = 0
groups = []
until index >= split_seq.length || range >= split_seq.length
if both_odd_or_even(split_seq, index, range)
range += 1
else
groups << split_seq[index..range - 1].join.to_i
index = range
end
end
groups << split_seq[index...split_seq.length].join.to_i
end
def both_odd_or_even(split_seq, index, range)
((split_seq[index] * 3 % 2 == 0) && (split_seq[range] * 3 % 2 == 0)) || ((split_seq[index] * 3 % 2 != 0) && (split_seq[range] * 3 % 2 != 0))
end
num_seq(12134343433332)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment