Skip to content

Instantly share code, notes, and snippets.

@zackmdavis
Created February 17, 2014 18:31
Show Gist options
  • Save zackmdavis/9056258 to your computer and use it in GitHub Desktop.
Save zackmdavis/9056258 to your computer and use it in GitHub Desktop.
HyTimer scratch work
(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