Skip to content

Instantly share code, notes, and snippets.

@serghost
Last active May 4, 2016 15:02
Show Gist options
  • Save serghost/30fb0130a31b468e59c939f027930be9 to your computer and use it in GitHub Desktop.
Save serghost/30fb0130a31b468e59c939f027930be9 to your computer and use it in GitHub Desktop.
Look-and-say ruby variant
def next_node(current_node)
array_of_digits = current_node.to_s.split('')
result = []
array_of_digits.chunk { |n| n }.each do |digit, ary|
result << ary.size
result << digit
end
result.join.to_i
end
def print_sequence(depth, start_node)
node = start_node
p node
1.upto(depth) do
node = next_node(node)
p node
end
end
print_sequence(10, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment