June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
30
Task/Self-describing-numbers/Red/self-describing-numbers.red
Normal file
30
Task/Self-describing-numbers/Red/self-describing-numbers.red
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
Red []
|
||||
|
||||
;;-------------------------------------
|
||||
count-dig: func ["count occurence of digit in number"
|
||||
;;-------------------------------------
|
||||
s [string!] "number as string"
|
||||
sdig [char!] "search number as char"
|
||||
][
|
||||
cnt: #"0" ;; counter as char for performance optimization
|
||||
|
||||
while [s: find/tail s sdig][cnt: cnt + 1]
|
||||
return cnt
|
||||
]
|
||||
|
||||
;;-------------------------------------
|
||||
isSDN?: func ["test if number is self describing number"
|
||||
s [string!] "number to test as string "
|
||||
][
|
||||
;;-------------------------------------
|
||||
|
||||
ind: #"0" ;; use digit as char for performance optimization
|
||||
|
||||
foreach ele s [
|
||||
if ele <> count-dig s ind [return false]
|
||||
ind: ind + 1
|
||||
]
|
||||
return true
|
||||
]
|
||||
|
||||
repeat i 4000000 [ if isSDN? to-string i [print i] ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue