Last Friday of each month: Difference between revisions

→‎{{header|Common Lisp}}: Add implementation.
(→‎{{header|Common Lisp}}: Add implementation.)
Line 375:
Fri Dec 28 2012
</lang>
 
=={{header|Common Lisp}}==
{{works with|CLISP}}
The command-line argument processing is the only `CLISP`-specific code.
 
<lang lisp>(defun friday-before (year month day)
(let*
((timestamp (encode-universal-time 0 0 12 day month year))
(weekday (nth 6 (multiple-value-list (decode-universal-time timestamp))))
(fri (- timestamp (* (+ (mod (+ weekday 2) 7) 1) 86400))))
(multiple-value-bind (_ _ _ d m y) (decode-universal-time fri)
(list y m d))))
(defun last-fridays (year)
(append (loop for month from 2 to 12 collecting (friday-before year month 1))
(list (friday-before (1+ year) 1 1))))
 
(let* ((year (read-from-string (car *args*))))
(format t "~{~{~a-~2,'0d-~2,'0d~}~%~}" (last-fridays year)))</lang>
 
Sample run for the year 2015:
{{Output}}
<pre>2015-01-30
2015-02-27
2015-03-27
2015-04-24
2015-05-29
2015-06-26
2015-07-31
2015-08-28
2015-09-25
2015-10-30
2015-11-27
2015-12-25</pre>
 
=={{header|D}}==
1,481

edits