Created
June 6, 2015 09:56
-
-
Save vasily-kirichenko/5563a04f4a0c134a88a7 to your computer and use it in GitHub Desktop.
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 Bridge = { RunwayLength: int; GapSize: int; LandingSize: int } | |
type Bike = { Speed: int; Position: int } | |
type BikeSate = | |
| OnTheRunway | |
| JustBeforeGap | |
| InFlight | |
| AfterGap | |
type BikeSpeed = | |
| TooSlow | |
| TooFast | |
| TargetSpeed | |
let bridge = { RunwayLength = 1; GapSize = 1; LandingSize = 1 } | |
// Get current position | |
let bikeState bike = | |
if bike.Position >= bridge.RunwayLength + bridge.GapSize then AfterGap | |
elif bike.Position > (bridge.RunwayLength - bike.Speed) then JustBeforeGap | |
elif bike.Position < bridge.RunwayLength then OnTheRunway | |
else InFlight | |
// Get current speed | |
let bikeSpeed speed = | |
let targetSpeed = bridge.GapSize + 1 | |
if speed < targetSpeed then TooSlow | |
elif speed > targetSpeed then TooFast | |
else TargetSpeed | |
let getAction state = | |
match bikeState state, bikeSpeed state.Speed with | |
| OnTheRunway, TooSlow -> "SPEED" | |
| OnTheRunway, TooFast -> "SLOW" | |
| OnTheRunway, TargetSpeed | InFlight, _ -> "WAIT" | |
| JustBeforeGap, _ -> "JUMP" | |
| AfterGap, _ -> "SLOW" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment