Skip to content

Instantly share code, notes, and snippets.

@0918nobita
Last active March 31, 2022 08:14
Show Gist options
  • Select an option

  • Save 0918nobita/65ca672caa5fc15cb49004b162193580 to your computer and use it in GitHub Desktop.

Select an option

Save 0918nobita/65ca672caa5fc15cb49004b162193580 to your computer and use it in GitHub Desktop.
13
45
120
120
120
120
120
120
60
45
120
60
60
60
Monday (225) [10; 5; 0]
Tuesday (240) [6; 1]
Wednesday (240) [12; 7; 2]
Thursday (225) [11; 8; 3]
Friday (240) [9; 4]
open System
type Day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
type Lecture = {
id: int
difficulty: uint32
}
type State = Map<Day, uint32 * int list>
let plan (lectures: Lecture seq) =
let initialState: State = Map.ofList [
(Monday, (0u, []))
(Tuesday, (0u, []))
(Wednesday, (0u, []))
(Thursday, (0u, []))
(Friday, (0u, []))
]
let folder (prevState: State) ({ id = id; difficulty = difficulty }: Lecture): State =
let day =
prevState
|> Map.toList
|> List.sortBy (fun (_, (lectures, _)) -> lectures)
|> List.map (fun (day, _) -> day)
|> List.head
prevState
|> Map.change day (fun from ->
let (sum, lectures) = Option.get from
Some((sum + difficulty, id :: lectures)))
lectures
|> Seq.fold folder initialState
let () =
let numLectures = Console.ReadLine() |> Int32.Parse
let lectures =
Array.zeroCreate numLectures
|> Array.map (Console.ReadLine >> UInt32.Parse)
|> Seq.mapi (fun i v -> { id = i; difficulty = v })
plan lectures
|> Map.iter (fun day (sum, lectures) -> printfn "%-9s (%d) %A" (string day) sum lectures)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment