Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #35989
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: When Gregorian replaced Julian |
| Date | 2015-01-24 06:32 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <m9ve97$ifb$1@dont-email.me> (permalink) |
| References | <m9s42m$n26$1@dont-email.me> |
WJ wrote:
> Using cal, find the month when England adopted the Gregorian
> calendar.
>
> In Emacs Lisp:
>
> (catch 'exit
> (dolist (year (number-sequence 1750 1799))
> (princ year)
> (dolist (month (number-sequence 1 12))
> (let* ((cal (shell-command-to-string (format "cal %s %s" month year)))
> (num-days (length (cdr (split-string cal "[^0-9]+" t)))))
> (princ (format " %s" num-days))
> (when (< num-days 28)
> (terpri) (princ cal)
> (throw 'exit 0))))
> (terpri)))
>
> Output:
>
> 1750 31 28 31 30 31 30 31 31 30 31 30 31
> 1751 31 28 31 30 31 30 31 31 30 31 30 31
> 1752 31 29 31 30 31 30 31 31 19
> September 1752
> S M Tu W Th F S
> 1 2 14 15 16
> 17 18 19 20 21 22 23
> 24 25 26 27 28 29 30
>
> Show your Forth code.
Gauche Scheme:
(use srfi-42) ;; first-ec
(use gauche.process)
(use srfi-13) ;; string-tokenize
(first-ec 'I-failed-to-find-it
(: year 1750 1800)
(begin (newline) (display year))
(: month 1 13)
(:let cal (call-with-input-process
(format "cal ~a ~a" month year) port->string))
(:let num-days (length (cdr (string-tokenize cal #[\d]))))
(begin (format #t " ~s" num-days))
(if (< num-days 28))
(print "\n" cal))
1750 31 28 31 30 31 30 31 31 30 31 30 31
1751 31 28 31 30 31 30 31 31 30 31 30 31
1752 31 29 31 30 31 30 31 31 19
September 1752
S M Tu W Th F S
1 2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread
When Gregorian replaced Julian "WJ" <w_a_x_man@yahoo.com> - 2015-01-23 00:19 +0000 Re: When Gregorian replaced Julian Mark Wills <markwills1970@gmail.com> - 2015-01-23 01:57 -0800 Re: When Gregorian replaced Julian "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-01-23 20:23 -0500 Re: When Gregorian replaced Julian "WJ" <w_a_x_man@yahoo.com> - 2015-01-24 06:32 +0000
csiph-web