Ocaml

[99 Problems in OCaml] 5번 문제

seungh2 2021. 9. 13. 10:59

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

 

5번 문제

  • rev
    • rev list
    • list를 거꾸로 만든 새로운 리스트를 반

 

내가 구현한 코드

위에거는 tail recursion이 아니고 밑에거는 tail recursion이다.

@ 연산자를 활용해서 풀 수 있었다.

 

정답 코드

처음엔 내가 구현한 코드와 달라서 조금 당황했는데 @ 연사자를 사용하지 않고 이렇게도 구현할 수 있는 것을 알게 되었다.

 

test 결과

728x90