Calculate the moment when someone has lived for 10^9 seconds.
A gigasecond is 10^9 (1,000,000,000) seconds.
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.
;;; gigasecond-test.el --- ERT tests for gigasecond (exercism) ;;; Commentary: ;; ;; Tests ported from Common Lisp gigasecond: ;; https://github.com/exercism/xlisp/blob/master/gigasecond/gigasecond-test.lisp ;; ;; To run tests individually: M-x eval-buffer RET, M-x ert RET test-name. ;; If you're using helm or something similar, you should get a menu of test names. ;; ;; To run tests in batch mode, from the command line run: ;; emacs -batch -l ert -l gigasecond-test.el -f ert-run-tests-batch-and-exit ;;; Code: (load-file "gigasecond.el") (ert-deftest from-lisp-epoch () (should (equal '(40 46 1 10 9 1931) (from 0 0 0 1 1 1900)))) (ert-deftest from-unix-epoch () (should (equal '(40 46 1 9 9 2001) (from 0 0 0 1 1 1970)))) (ert-deftest from-20110425T120000Z () (should (equal '(40 46 13 1 1 2043) (from 0 0 12 25 4 2011)))) (ert-deftest from-19770613T235959Z () (should (equal '(39 46 1 20 2 2009) (from 59 59 23 13 6 1977)))) (ert-deftest from-19590719T123030Z () (should (equal '(10 17 14 27 3 1991) (from 30 30 12 19 7 1959)))) ; customize this test to test your birthday and find your gigasecond date: ; (ert-deftest your-birthday () ; (should ; (equal '(0 0 0 day2 month2 year2) (from 0 0 0 day1 month1 year1)))) (provide 'gigasecond-test) ;;; gigasecond-test.el ends here
;;; gigasecond.el --- Gigasecond exercise (exercism) ;; ;; Copyright (C) 2015 Mathieu Gagnon ;; ;; Author: Mathieu Gagnon <firstname.lastname@example.org> ;; Keywords: exercism, time ;; ;; This file is NOT part of GNU Emacs. ;; ;; This is free and unencumbered software released into the public domain. ;; ;; Anyone is free to copy, modify, publish, use, compile, sell, or ;; distribute this software, either in source code form or as a compiled ;; binary, for any purpose, commercial or non-commercial, and by any ;; means. ;; ;; In jurisdictions that recognize copyright laws, the author or authors ;; of this software dedicate any and all copyright interest in the ;; software to the public domain. We make this dedication for the benefit ;; of the public at large and to the detriment of our heirs and ;; successors. We intend this dedication to be an overt act of ;; relinquishment in perpetuity of all present and future rights to this ;; software under copyright law. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ;; IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR ;; OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ;; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ;; OTHER DEALINGS IN THE SOFTWARE. ;; ;; For more information, please refer to <http://unlicense.org> ;; ;;; Commentary: ;; Calculate the date one gigasecond (10^9 seconds) from the ;; given date. ;; ;; NB: Pay attention to Emacs' handling of time zones and dst ;; in the encode-time and decode-time functions. ;;; Code: (defun from (s i h d m y) (let ((time (encode-time s i h d m y t))) (subseq (decode-time (time-add time (seconds-to-time (expt 10 9))) t) 0 6))) (provide 'gigasecond) ;;; gigasecond.el ends here
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.