aboutsummaryrefslogtreecommitdiff
path: root/challenge-153/abigail/tcl/ch-2.tcl
blob: 05299954e665d35c4bac39c150dbf9f97e71f81d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/local/opt/tcl-tk/bin/tclsh

#
# See https://theweeklychallenge.org/blog/perl-weekly-challenge-153
#

#
# Run as: tclsh ch-2.tcl < input-file
#

set fac [list 1]
for {set n 1} {$n <= 9} {incr n} {
    lset fac $n [expr $n * [lindex $fac [expr $n - 1]]]
}

while {[gets stdin num] >= 0} {
    set sum 0
    set n   $num
    while {$n > 0} {
        set sum [expr $sum + [lindex $fac [expr $n % 10]]]
        set n   [expr int ($n / 10)]
    }
    puts [expr $sum == $num ? 1 : 0]
}