Last active
December 27, 2015 01:09
-
-
Save firesofmay/7242548 to your computer and use it in GitHub Desktop.
My attempt to calculating the runtime of all the videos in a list.
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
| exception NoAnswer; | |
| val files : string list = ["Signatures and Hiding Things (7-02).mp4", | |
| "A Module Example (11-06).mp4", | |
| "Signatures for Our Example (11-03).mp4", | |
| "Signature Matching (4-03).mp4", | |
| "An Equivalent Structure (6-38).mp4", | |
| "Another Equivalent Structure (9-01).mp4", | |
| "Different Modules Define Different Types (3-32).mp4", | |
| "Equivalent Functions (8-41).mp4", | |
| "Standard Equivalences (10-01).mp4", | |
| "Equivalence Versus Performance (6-00).mp4", | |
| "Section Introduction (1-45).mp4", | |
| "What is Type Inference (5-37).mp4", | |
| "ML Type Inference (6-09).mp4", | |
| "Type Inference Examples (10-27).mp4", | |
| "Polymorphic Examples (10-52).mp4", | |
| "Optional- The Value Restriction and Other Type-Inference Challenges (9-53).mp4", | |
| "Mutual Recursion (9-45).mp4", | |
| "Modules for Namespace Management (6-25).mp4"] | |
| fun substring c1 c2 s = | |
| let | |
| val match1 = (List.last (String.tokens (fn c => c=c1) s)) | |
| val match2 = hd (String.tokens (fn c => c=c2) match1) | |
| in | |
| match2 | |
| end | |
| val get_time_st = substring #"(" #")"; | |
| fun get_time ts = | |
| let | |
| val time = String.tokens (fn c => c= #"-") ts | |
| val min = hd time | |
| val sec = List.last time | |
| in | |
| (min,sec) | |
| end | |
| fun get_seconds (m,s) = | |
| case (Int.fromString m, Int.fromString s) of | |
| (SOME x, SOME y) => (x * 60) + y | |
| | (_,_) => raise NoAnswer | |
| fun sum xs = | |
| foldl (fn (x,acc) => x+acc) 0 xs | |
| fun session_time x = | |
| (x div 3600, x div 60 mod 60) | |
| val total_session = (session_time o sum) (map (get_seconds o get_time o get_time_st) files) handle NoAnwer => (0,0); | |
| (* Output;;=> val total_session = (2,18) : int * int*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment