Created
February 17, 2014 18:31
-
-
Save zackmdavis/9056258 to your computer and use it in GitHub Desktop.
HyTimer scratch work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import re) | |
(import functools) | |
(defn parse [formatted] | |
(setv time_regex (.compile re "(\d+):?(\d{2}):(\d{2})")) | |
(setv s&m&h (map (fn [x] (if (empty? x) 0 (int x))) | |
(.group (.match time_regex formatted) | |
3 2 1))) | |
; (print (list (enumerate s&m&h))) | |
(functools.reduce sum | |
(map (fn [power&figure] | |
(* (** 60 (first power&figure)) | |
(second power&figure))) | |
(enumerate s&m&h)))) | |
; (print (parse "1:20:05")) | |
; (print (parse "0:20:01.0")) | |
(defn in_seconds [s&m&h] | |
(functools.reduce sum | |
(map (fn [power&figure] | |
(* (** 60 (first power&figure)) | |
(second power&figure))) | |
(enumerate s&m&h)) | |
0)) | |
(print (in_seconds [[0 1] [1 20] [2 1]])) | |
;; but, but , but I got it working in the REPL .. | |
;;; => (list (map (fn [pf] (* (** 60 (first pf)) (second pf))) (enumerate [1 20 1]))) | |
;[1, 1200, 3600] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment