Sha256: 628e8b538074e138db57ce5e7691cdc65276fa935f067e48fdfc810a74b8ae00

Contents?: true

Size: 586 Bytes

Versions: 270

Compression:

Stored size: 586 Bytes

Contents

module Clock

open System

type Clock = { hours: int; minutes: int }

let modulo x y = (int)(((x % y) + y) % y)

let mkClock hours minutes =
    let totalMinutes = hours * 60 + minutes
    let normalizedHours = modulo ((double)totalMinutes / 60.0) 24.0
    let normalizedMinutes = modulo ((double)minutes) 60.0

    { hours = normalizedHours; minutes = normalizedMinutes }

let add minutes clock = mkClock clock.hours (clock.minutes + minutes)

let subtract minutes clock = mkClock clock.hours (clock.minutes - minutes)

let display clock = sprintf "%02i:%02i" clock.hours clock.minutes

Version data entries

270 entries across 270 versions & 1 rubygems

Version Path
trackler-2.2.1.52 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.51 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.50 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.49 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.48 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.47 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.46 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.45 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.44 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.43 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.42 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.41 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.40 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.39 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.38 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.37 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.36 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.35 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.34 tracks/fsharp/exercises/clock/Example.fs
trackler-2.2.1.33 tracks/fsharp/exercises/clock/Example.fs