## URL

https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/description/?envType=daily-question&envId=2024-09-02

## Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202409/find_the_student_that_will_replace_the_chalk/main.fsx

```
let chalkReplacer (chalk: int list) (k: int) : int =
let rec chalkReplacer' (chalk: (int * int64) list) (k: int64) =
match chalk with
| [] -> failwith "never reach here"
| (i, h) :: t -> if h > k then i else chalkReplacer' t (k - h)
let chalk = List.map int64 chalk
let sum = chalk |> List.sum
chalkReplacer' (List.indexed chalk) (int64 k % sum)
```