fork download
  1. ; five weekends
  2.  
  3. (define (range . args)
  4. (case (length args)
  5. ((1) (range 0 (car args) (if (negative? (car args)) -1 1)))
  6. ((2) (range (car args) (cadr args) (if (< (car args) (cadr args)) 1 -1)))
  7. ((3) (let ((le? (if (negative? (caddr args)) >= <=)))
  8. (let loop ((x(car args)) (xs '()))
  9. (if (le? (cadr args) x)
  10. (reverse xs)
  11. (loop (+ x (caddr args)) (cons x xs))))))
  12. (else (error 'range "unrecognized arguments"))))
  13.  
  14. (define-syntax fold-of
  15. (syntax-rules (range in is)
  16. ((_ "z" f b e) (set! b (f b e)))
  17. ((_ "z" f b e (v range fst pst stp) c ...)
  18. (let* ((x fst) (p pst) (s stp)
  19. (le? (if (positive? s) =)))
  20. (do ((v x (+ v s))) ((le? p v) b)
  21. (fold-of "z" f b e c ...))))
  22. ((_ "z" f b e (v range fst pst) c ...)
  23. (let* ((x fst) (p pst) (s (if (< x p) 1 -1)))
  24. (fold-of "z" f b e (v range x p s) c ...)))
  25. ((_ "z" f b e (v range pst) c ...)
  26. (fold-of "z" f b e (v range 0 pst) c ...))
  27. ((_ "z" f b e (x in xs) c ...)
  28. (do ((t xs (cdr t))) ((null? t) b)
  29. (let ((x (car t)))
  30. (fold-of "z" f b e c ...))))
  31. ((_ "z" f b e (x is y) c ...)
  32. (let ((x y)) (fold-of "z" f b e c ...)))
  33. ((_ "z" f b e p? c ...)
  34. (if p? (fold-of "z" f b e c ...)))
  35. ((_ f i e c ...)
  36. (let ((b i)) (fold-of "z" f b e c ...)))))
  37.  
  38. (define-syntax list-of (syntax-rules ()
  39. ((_ arg ...) (reverse (fold-of
  40. (lambda (d a) (cons a d)) '() arg ...)))))
  41.  
  42. (define (unique eql? xs)
  43. (cond ((null? xs) '())
  44. ((null? (cdr xs)) xs)
  45. ((eql? (car xs) (cadr xs))
  46. (unique eql? (cdr xs)))
  47. (else (cons (car xs) (unique eql? (cdr xs))))))
  48.  
  49. (define (julian year month day)
  50. (let* ((a (quotient (- 14 month) 12))
  51. (y (+ year 4800 (- a)))
  52. (m (+ month (* 12 a) -3)))
  53. (+ day
  54. (quotient (+ (* 153 m) 2) 5)
  55. (* 365 y)
  56. (quotient y 4)
  57. (- (quotient y 100))
  58. (quotient y 400)
  59. (- 32045))))
  60.  
  61. (define (list-minus xs ys)
  62. (let loop ((xs xs) (zs (list)))
  63. (cond ((null? xs) zs)
  64. ((member (car xs) ys) (loop (cdr xs) zs))
  65. (else (loop (cdr xs) (cons (car xs) zs))))))
  66.  
  67. (display (list-of (list m y)
  68. (y range 1900 2101)
  69. (m in '(1 3 5 7 8 10 12))
  70. (= (modulo (julian y m 1) 7) 4)))
  71. (newline)
  72.  
  73. (display (length (list-of (list m y)
  74. (y range 1900 2101)
  75. (m in '(1 3 5 7 8 10 12))
  76. (= (modulo (julian y m 1) 7) 4))))
  77. (newline)
  78.  
  79. (display (reverse (list-minus (range 1900 2101) (unique =
  80. (list-of y
  81. (y range 1900 2101)
  82. (m in '(1 3 5 7 8 10 12))
  83. (= (modulo (julian y m 1) 7) 4))))))
  84. (newline)
  85.  
  86. (display (length (list-minus (range 1900 2101) (unique =
  87. (list-of y
  88. (y range 1900 2101)
  89. (m in '(1 3 5 7 8 10 12))
  90. (= (modulo (julian y m 1) 7) 4))))))
  91. (newline)
Success #stdin #stdout 0.28s 51960KB
stdin
Standard input is empty
stdout
((3 1901) (8 1902) (5 1903) (1 1904) (7 1904) (12 1905) (3 1907) (5 1908) (1 1909) (10 1909) (7 1910) (12 1911) (3 1912) (8 1913) (5 1914) (1 1915) (10 1915) (12 1916) (3 1918) (8 1919) (10 1920) (7 1921) (12 1922) (8 1924) (5 1925) (1 1926) (10 1926) (7 1927) (3 1929) (8 1930) (5 1931) (1 1932) (7 1932) (12 1933) (3 1935) (5 1936) (1 1937) (10 1937) (7 1938) (12 1939) (3 1940) (8 1941) (5 1942) (1 1943) (10 1943) (12 1944) (3 1946) (8 1947) (10 1948) (7 1949) (12 1950) (8 1952) (5 1953) (1 1954) (10 1954) (7 1955) (3 1957) (8 1958) (5 1959) (1 1960) (7 1960) (12 1961) (3 1963) (5 1964) (1 1965) (10 1965) (7 1966) (12 1967) (3 1968) (8 1969) (5 1970) (1 1971) (10 1971) (12 1972) (3 1974) (8 1975) (10 1976) (7 1977) (12 1978) (8 1980) (5 1981) (1 1982) (10 1982) (7 1983) (3 1985) (8 1986) (5 1987) (1 1988) (7 1988) (12 1989) (3 1991) (5 1992) (1 1993) (10 1993) (7 1994) (12 1995) (3 1996) (8 1997) (5 1998) (1 1999) (10 1999) (12 2000) (3 2002) (8 2003) (10 2004) (7 2005) (12 2006) (8 2008) (5 2009) (1 2010) (10 2010) (7 2011) (3 2013) (8 2014) (5 2015) (1 2016) (7 2016) (12 2017) (3 2019) (5 2020) (1 2021) (10 2021) (7 2022) (12 2023) (3 2024) (8 2025) (5 2026) (1 2027) (10 2027) (12 2028) (3 2030) (8 2031) (10 2032) (7 2033) (12 2034) (8 2036) (5 2037) (1 2038) (10 2038) (7 2039) (3 2041) (8 2042) (5 2043) (1 2044) (7 2044) (12 2045) (3 2047) (5 2048) (1 2049) (10 2049) (7 2050) (12 2051) (3 2052) (8 2053) (5 2054) (1 2055) (10 2055) (12 2056) (3 2058) (8 2059) (10 2060) (7 2061) (12 2062) (8 2064) (5 2065) (1 2066) (10 2066) (7 2067) (3 2069) (8 2070) (5 2071) (1 2072) (7 2072) (12 2073) (3 2075) (5 2076) (1 2077) (10 2077) (7 2078) (12 2079) (3 2080) (8 2081) (5 2082) (1 2083) (10 2083) (12 2084) (3 2086) (8 2087) (10 2088) (7 2089) (12 2090) (8 2092) (5 2093) (1 2094) (10 2094) (7 2095) (3 2097) (8 2098) (5 2099) (1 2100) (10 2100))
201
(1900 1906 1917 1923 1928 1934 1945 1951 1956 1962 1973 1979 1984 1990 2001 2007 2012 2018 2029 2035 2040 2046 2057 2063 2068 2074 2085 2091 2096)
29