Last active
August 29, 2015 14:16
-
-
Save tjaskula/fb2860f6a0c50f4964f1 to your computer and use it in GitHub Desktop.
Euler
This file contains 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
let rec split<'T> (input: 'T array) size = | |
let rec loopOn (tail : 'T array) grouped = | |
let lastIndex = Array.length tail - 1 | |
let endindx = min (size - 1) lastIndex | |
let arrWrapper = (fun e -> [|e|]) | |
let newGroup = tail.[0..endindx] | |
|> List.ofArray | |
|> arrWrapper | |
|> Array.append grouped | |
match tail with | |
| [||] -> newGroup | |
|> Array.filter (fun e -> List.length e > 0) | |
| _ -> loopOn tail.[endindx + 1..] newGroup | |
let initialState = [|List.empty<'T>|] | |
loopOn input initialState | |
type Custom = {Value : int} | |
let r = split<int> [|1..1000|] 10 | |
let r2 = split<float> [|1.0..1000.0|] 10 | |
let r3 = split<Custom> [|for i in 1..1000 -> | |
{Value = i}|] 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment