Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Created June 6, 2015 09:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasily-kirichenko/5563a04f4a0c134a88a7 to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/5563a04f4a0c134a88a7 to your computer and use it in GitHub Desktop.
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