Skip to content

Instantly share code, notes, and snippets.

@joejag
Created May 7, 2022 15:01
Show Gist options
  • Save joejag/f88161111b1fd59143b434e1b392a52c to your computer and use it in GitHub Desktop.
Save joejag/f88161111b1fd59143b434e1b392a52c to your computer and use it in GitHub Desktop.

Implement a function that outputs the Look and Say sequence:

1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
import itertools
def look_any_say(num):
result = ""
for n, amount in itertools.groupby(str(num)):
result += f"{len(list(amount))}{n}"
return int(result)
import unittest
class TestSpiralMethods(unittest.TestCase):
def test_one(self):
self.assertEqual(look_any_say(1), 11)
def test_two(self):
self.assertEqual(look_any_say(11), 21)
def test_big(self):
self.assertEqual(look_any_say(31131211131221), 13211311123113112211)
unittest.main(exit=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment