Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Look-and-say-sequence/Nim/look-and-say-sequence.nim
Normal file
19
Task/Look-and-say-sequence/Nim/look-and-say-sequence.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
iterator lookAndSay(n: int): string =
|
||||
var current = "1"
|
||||
yield current
|
||||
for round in 2..n:
|
||||
var ch = current[0]
|
||||
var count = 1
|
||||
var next = ""
|
||||
for i in 1..current.high:
|
||||
if current[i] == ch:
|
||||
inc count
|
||||
else:
|
||||
next.add $count & ch
|
||||
ch = current[i]
|
||||
count = 1
|
||||
current = next & $count & ch
|
||||
yield current
|
||||
|
||||
for s in lookAndSay(12):
|
||||
echo s
|
||||
Loading…
Add table
Add a link
Reference in a new issue