Skip to content

Instantly share code, notes, and snippets.

@msgodf
Created April 14, 2011 08:36
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 msgodf/919132 to your computer and use it in GitHub Desktop.
Save msgodf/919132 to your computer and use it in GitHub Desktop.
A reduce solution to Conway's "Look and Say" sequence
def lookandsay(seq)
seq.reduce{|s, v| s = [[1, s]] if s != s.to_a;if s.last.last == v then s[ s.length - 1 ] = [ s.last.first + 1 , v] else s.push [1, v] end; s}.flatten
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment