99 Problems in OCaml
https://ocaml.org/learn/tutorials/99problems.html
99 problems – OCaml
Your Help is Needed Many of the solutions below have been written by Victor Nicollet. Please contribute more solutions or improve the existing ones. 99 Problems (solved) in OCaml This section is inspired by Ninety-Nine Lisp Problems which in turn was based
ocaml.org
10번 문제
- encode
- encode list
- list에 대해 run length encoding을 수행한다. 이때 (개수, data)를 pair로 하는 리스트를 반환한다.
내가 구현한 코드
개수를 세는 n을 인자로 갖고 정답을 누적하는 ans를 인자로 갖는 encode_ans라는 로컬 함수를 만들어서 해결하였다.
정답 코드
@를 사용하는 것 말고 ::와 List.rev를 사용한 방법이다.
test 결과
728x90
'Ocaml' 카테고리의 다른 글
[99 Problems in OCaml] 14번, 15번 문제 (0) | 2021.09.23 |
---|---|
[99 Problems in OCaml] 11번, 12번, 13번 문제 (0) | 2021.09.23 |
[99 Problems in OCaml] 6번, 9번 문제 (0) | 2021.09.19 |
[99 Problems in OCaml] 9번 문제 (0) | 2021.09.16 |
[99 Problems in OCaml] 8번 문제 (0) | 2021.09.15 |
댓글