[김한기] Week 3 solutions #82
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
지각이네요 ^^;
그리고 마지막 문제는 풀지 못했습니다 ㅠㅠ
이번주에도 엘릭서로 풀었는데
약간의 특이사항은 이번주 문제에 두개의 트리가 동일한지 비교하는 문제가 두개 나왔는데,
엘릭서는 함수형 언어이고, 모든 객체(?)가 한번만들어지면 불변이므로, 무언가를 비교할때 모든건 불변한다는걸 이용해서 그 값을 비교한다는 특징이 있고... 이때문에 문제가 너무나도 쉽게 풀릴 수 있었네요.
예를들어 same tree 문제는
p == q
이렇게만 해도 같은지 비교가 가능한...(최소한 루비 기준에선)다른 언어에선 두 객체가 있고,
Object.new == Object.new
이와같이 하면 객체의 레퍼런스가 같은지 비교하는데,다른 언어에선 주소값을 비교하는 이유와 엘릭서가 그렇게 동작하지 않는 이유를 추측해본다면
다른 언어들은 다른 쓰레드에서 값이 언제라도 바뀔 수 있기때문에 레퍼런스가 같은지 비교하고, 엘릭서는 두 객체가 한번 만들어지면 절대 변할 일 없기때문에 좀더 자신있게 값 전체를 비교하는 식으로 되어있지 않나 싶네요... 레퍼런스 비교대신에...
맞나 모르겠습니다...