challenges

my solutions to various "programming challenge" problems
git clone https://wehaveforgeathome.hates.computer/challenges.git
Log | Files | Refs | LICENSE

019.pez (932B)


      1 #! /usr/bin/env pez
      2 # real  0m0.008s
      3 # user  0m0.000s
      4 # sys 0m0.008s
      5 
      6 : incIfSunday ( sundays days -- sundays days )
      7   7 mod dup 0= if
      8     swap 1+ swap
      9   then
     10 ;
     11 
     12 : advanceAYear ( year sundays days -- year sundays days )
     13   # jan
     14   incIfSunday
     15   31 +
     16 
     17   # feb
     18   incIfSunday
     19   28 +
     20   # leap years are crazy
     21   2 pick 4 mod 0= if
     22     1+
     23     2 pick 100 mod 0= if
     24       2 pick 400 mod 0 <> if
     25         1-
     26       then
     27     then
     28   then
     29 
     30   # march
     31   incIfSunday
     32   31 +
     33 
     34   # april
     35   incIfSunday
     36   30 +
     37 
     38   # may
     39   incIfSunday
     40   31 +
     41 
     42   # june
     43   incIfSunday
     44   30 +
     45 
     46   # july
     47   incIfSunday
     48   31 +
     49 
     50   # aug
     51   incIfSunday
     52   31 +
     53 
     54   # sep
     55   incIfSunday
     56   30 +
     57 
     58   # oct
     59   incIfSunday
     60   31 +
     61 
     62   # nov
     63   incIfSunday
     64   30 +
     65 
     66   # dec
     67   incIfSunday
     68   31 +
     69 ;
     70 
     71 : loopThroughYears ( days -- sundays )
     72   0 swap
     73   2001 1901 do
     74     i -rot advanceAYear rot drop
     75   loop
     76   drop
     77 ;
     78 
     79 # jan 1, 1900 was a monday
     80 1900 0 1 advanceAYear -rot drop drop loopThroughYears . cr