aboutsummaryrefslogtreecommitdiff
path: root/challenge-138/abigail/tcl
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-11-14 13:03:11 +0100
committerAbigail <abigail@abigail.be>2021-11-14 13:03:11 +0100
commitc1db8bac0eaafcc7e7c94d712ce24dc69b776c53 (patch)
tree76f34f10adc27d237e343671818fe451490f0906 /challenge-138/abigail/tcl
parent14510de14e1f435b1439c451a2fa5cb9971a7c78 (diff)
downloadperlweeklychallenge-club-c1db8bac0eaafcc7e7c94d712ce24dc69b776c53.tar.gz
perlweeklychallenge-club-c1db8bac0eaafcc7e7c94d712ce24dc69b776c53.tar.bz2
perlweeklychallenge-club-c1db8bac0eaafcc7e7c94d712ce24dc69b776c53.zip
Solutions for week 138 in 14 languages.
Diffstat (limited to 'challenge-138/abigail/tcl')
-rw-r--r--challenge-138/abigail/tcl/ch-1.tcl38
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-138/abigail/tcl/ch-1.tcl b/challenge-138/abigail/tcl/ch-1.tcl
new file mode 100644
index 0000000000..7e613636bd
--- /dev/null
+++ b/challenge-138/abigail/tcl/ch-1.tcl
@@ -0,0 +1,38 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: tclsh ch-1.tcl < input-file
+#
+
+set lookup [list [list 261 261 260 260 261 261 261] \
+ [list 262 262 261 260 261 262 262]]
+
+set SUNDAY 0
+set MONDAY 1
+set TUESDAY 2
+set WEDNESDAY 3
+set THURSDAY 4
+set FRIDAY 5
+set SATURDAY 6
+
+set Anchors [list $TUESDAY $SUNDAY $FRIDAY $WEDNESDAY]
+
+proc doomsday year {
+ upvar 1 Anchors anchors
+ set anchor [lindex $anchors [expr ($year / 100) % 4]]
+ set y [expr $year % 100]
+ return [expr ((($y / 12) + ($y % 12) + (($y % 12) / 4)) + $anchor) % 7]
+}
+
+proc is_leap year {
+ if {($year % 400 == 0) || ($year % 4 == 0) && ($year % 100 != 0)} {
+ return 1
+ }
+ return 0
+}
+
+while {[gets stdin year] >= 0} {
+ puts [lindex $lookup [is_leap $year] [doomsday $year]]
+}