1
0
Fork 0

new solution: emacs-lisp, gigasecond.

main
Gökmen Görgen 2 months ago
parent 4cee3fef55
commit fd6eeaa99b
  1. 41
      emacs-lisp/gigasecond/HELP.md
  2. 21
      emacs-lisp/gigasecond/README.md
  3. 46
      emacs-lisp/gigasecond/gigasecond-test.el
  4. 18
      emacs-lisp/gigasecond/gigasecond.el

@ -0,0 +1,41 @@
# Help
## Running the tests
Tests can be run several ways:
1. Interactively and individually, with `M-x ert RET test-name RET`
2. Interactively and all at once, with `M-x ert RET t RET`
3. From the terminal, in batch mode, with `emacs -batch -l ert -l my-test.el -f ert-run-tests-batch-and-exit`
4. Other options can be found in the docs, `C-h i m ert RET`
## Submitting your solution
You can submit your solution using the `exercism submit gigasecond.el` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [Emacs Lisp track's documentation](https://exercism.org/docs/tracks/emacs-lisp)
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
To get help if you're having trouble, you can use one of the following resources:
- [The Emacs Wiki](http://emacswiki.org/) is invaluable. Spend lots of time here.
- [The Emacs Editor](http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html) is the official manual for GNU Emacs.
- IRC - there are [freenode](https://freenode.net/) channels for `#emacs`, `#prelude`, and many Emacs
packages, and many helpful folks around. And with emacs, IRC is as close as
`M-x erc`.
- [Exercism Support](https://gitter.im/exercism/support) Gitter chat is also a good place to get help from the
exercism community.
- [StackOverflow](http://stackoverflow.com/questions/tagged/elisp) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

@ -0,0 +1,21 @@
# Gigasecond
Welcome to Gigasecond on Exercism's Emacs Lisp Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Given a moment, determine the moment that would be after a gigasecond
has passed.
A gigasecond is 10^9 (1,000,000,000) seconds.
## Source
### Created by
- @canweriotnow
### Based on
Chapter 9 in Chris Pine's online Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=09

@ -0,0 +1,46 @@
;;; 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

@ -0,0 +1,18 @@
;;; gigasecond.el --- Gigasecond exercise (exercism)
;;; 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 (second minute hour day month year)
"Given a moment, determine the moment that would be after a gigasecond has passed."
(let ((encoded-time (encode-time (+ (expt 10 9) second) minute hour day month year "UTC")))
(butlast (decode-time encoded-time "UTC") 3)))
(provide 'gigasecond)
;;; gigasecond.el ends here
Loading…
Cancel
Save