Created
January 17, 2018 17:54
-
-
Save zwilderrr/4a7929fedf15649d23779c4a0e7e114f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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