Given a moment, determine the moment that would be after a gigasecond has passed.
A gigasecond is 10^9 (1,000,000,000) seconds.
While Common Lisp doesn't care about indentation and layout of code, nor whether you use spaces or tabs, this is an important consideration for submissions to exercism.io. Excercism.io's code widget cannot handle mixing of tab and space characters well so using only spaces is recommended to make the code more readable to the human reviewers. Please review your editors settings on how to accomplish this. Below are instructions for popular editors for Common Lisp.
Use the following commands to ensure VIM uses only spaces for indentation:
:set tabstop=2 :set shiftwidth=2 :set expandtab
(or as a oneliner
:set tabstop=2 shiftwidth=2 expandtab). This can
be added to your
~/.vimrc file to use it all the time.
Emacs is very well suited for editing Common Lisp and has many powerful add-on packages available. The only thing that one needs to do with a stock emacs to make it work well with exercism.io is to evaluate the following code:
(setq-default indent-tabs-mode nil)
This can be placed in your
order to have it set whenever Emacs is launched.
One suggested add-on for Emacs and Common Lisp is SLIME which offers tight integration with the REPL; making iterative coding and testing very easy.
Chapter 9 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=09
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
(ql:quickload "lisp-unit") #-xlisp-test (load "gigasecond") (defpackage #:gigasecond-test (:use #:cl #:lisp-unit)) (in-package #:gigasecond-test) (define-test from-lisp-epoch (assert-equal '(1931 9 10 1 46 40) (gigasecond:from 1900 1 1 0 0 0))) (define-test from-unix-epoch (assert-equal '(2001 9 9 1 46 40) (gigasecond:from 1970 1 1 0 0 0))) (define-test from-20110425T120000Z (assert-equal '(2043 1 1 13 46 40) (gigasecond:from 2011 4 25 12 0 0))) (define-test from-19770613T235959Z (assert-equal '(2009 2 20 1 46 39) (gigasecond:from 1977 6 13 23 59 59))) (define-test from-19590719T123030Z (assert-equal '(1991 3 27 14 17 10) (gigasecond:from 1959 7 19 12 30 30))) ; customize this to test your birthday and find your gigasecond date: ; (define-test your-birthday ; (assert-equal '(year2 month2 day2) (gigasecond:from year1 month1 day1))) #-xlisp-test (let ((*print-errors* t) (*print-failures* t)) (run-tests :all :gigasecond-test))
(in-package #:cl-user) (defpackage #:gigasecond (:use #:cl) (:export #:from)) (in-package #:gigasecond) (defun from (year month day hour minute second) (multiple-value-bind (second minute hour date month year) (decode-universal-time (+ (expt 10 9) (encode-universal-time second minute hour day month year 0)) 0) (list year month date hour minute second)))
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.