Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
20
Task/Self-describing-numbers/Nim/self-describing-numbers.nim
Normal file
20
Task/Self-describing-numbers/Nim/self-describing-numbers.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import strutils
|
||||
|
||||
proc count(s, sub): int =
|
||||
var i = 0
|
||||
while true:
|
||||
i = s.find(sub, i)
|
||||
if i < 0:
|
||||
break
|
||||
inc i
|
||||
inc result
|
||||
|
||||
proc isSelfDescribing(n): bool =
|
||||
let s = $n
|
||||
for i, ch in s:
|
||||
if s.count($i) != parseInt("" & ch):
|
||||
return false
|
||||
return true
|
||||
|
||||
for x in 0 .. 4_000_000:
|
||||
if isSelfDescribing(x): echo x
|
||||
Loading…
Add table
Add a link
Reference in a new issue