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) |