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
type Move = Circle -> Circle |
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 spin (n : int) : Move = | |
fun circle -> | |
let len = Array.length circle in | |
Array.append circle.[(len-n)..(len-1)] circle.[0..(len-n-1)] |
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
> Dancers.spin 4 Dancers.startingPattern | |
val it : Dancers.Circle = | |
[|'m'; 'n'; 'o'; 'p'; 'a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'|] |
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
> Dancers.exchange (2, 5) Dancers.startingPattern | |
val it : Dancers.Circle = | |
[|'a'; 'b'; 'f'; 'd'; 'e'; 'c'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm'; 'n'; 'o'; 'p'|] |
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 exchange (a : int, b : int) : Move = | |
let toKV arr = Map.ofArray (Array.indexed arr) in | |
let ofKV map = Array.map snd (Array.sortBy fst (Map.toArray map)) in | |
fun circle -> | |
ofKV (Map.add b circle.[a] (Map.add a circle.[b] (toKV circle))) |
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
> Dancers.partner ('e', 'p') Dancers.startingPattern | |
val it : Dancers.Circle = | |
[|'a'; 'b'; 'c'; 'd'; 'p'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm'; 'n'; 'o'; 'e'|] |
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 partner (a : char, b : char) : Move = | |
let swap (a, b) = (b, a) in | |
let toKV arr = Map.ofArray (Array.map swap (Array.indexed arr)) | |
let ofKV map = Array.map snd (Array.sortBy fst (Array.map swap (Map.toArray map))) in | |
let withKV f arr = ofKV(f (toKV arr)) in | |
withKV (fun kv -> | |
let valA = (Map.find a kv) in | |
let valB = (Map.find b kv) in | |
Map.add b valA (Map.add a valB kv)) |
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
> Dancers.solve Dancers.input | |
val it : System.String = "olgejankfhbmpidc" |
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 exchange (a : int, b : int) : Move = | |
fun circle -> | |
let valA = circle.[a] in | |
circle.[a] <- circle.[b]; | |
circle.[b] <- valA; | |
circle | |
let partner (a : char, b : char) : Move = | |
fun circle -> | |
let idxA = Array.findIndex ((=) a) circle in |
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
package main | |
import ( | |
"encoding/json" | |
"flag" | |
"fmt" | |
"log" | |
"net" | |
"net/http" | |
"strings" |