Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Happy-numbers/Tcl/happy-numbers.tcl
Normal file
16
Task/Happy-numbers/Tcl/happy-numbers.tcl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
proc is_happy n {
|
||||
set seen [list]
|
||||
while {$n > 1 && [lsearch -exact $seen $n] == -1} {
|
||||
lappend seen $n
|
||||
set n [sum_of_squares [split $n ""]]
|
||||
}
|
||||
return [expr {$n == 1}]
|
||||
}
|
||||
|
||||
set happy [list]
|
||||
set n -1
|
||||
while {[llength $happy] < 8} {
|
||||
if {[is_happy $n]} {lappend happy $n}
|
||||
incr n
|
||||
}
|
||||
puts "the first 8 happy numbers are: [list $happy]"
|
||||
Loading…
Add table
Add a link
Reference in a new issue