Language 69

[프로그래머스] 두 수의 합 : Int범위를 넘어가는 경우 String으로 합 구하기

https://school.programmers.co.kr/learn/courses/30/lessons/181846 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문자열로 주어진 숫자 두 개의 합을 구해 문자열로 반환하는 문제이다. 문제를 얼핏 봤을 때는 간단해 보였지만, 이 문제의 핵심은 문자열로 주어진 수가 Int의 범위를 넘어간다는 것이다. 양수라는 점을 감안해 UInt64를 사용한다고 하더라도 최대 값을 넘어간다. 그래서 이 문제를 풀기 위해서는 정수로 변환해서 합을 구할 수 없고, 일의 자리부터 자리수를 더해야 한다. (손으로 더하기 문제 풀 때..

Language/Swift 2023.07.17

[Exercism] Anagram #sort!!!!!

https://exercism.org/tracks/dart/exercises/anagram Anagram in Dart on Exercism Can you solve Anagram in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org word와 list가 주어지고, list 안에서 word의 글자들을 바꾼 경우(즉 각 알파벳의 개수도 같아야 한다)에 해당하는 단어들만 찾는 문제이다. 대소문자를 구분하지 않고 완전히 일치하는 경우에는 답이 아니다. 처음에 문제를 풀었던 방식은 다음과 같다. 결국 알파벳 하나하나를 살펴봐야 하니까 for문을 돌릴 수 밖에 없다고 생각했다. class An..

Language/Dart 2022.09.21

[Exercism] Rna Transcription

https://exercism.org/tracks/dart/exercises/rna-transcription Rna Transcription in Dart on Exercism Can you solve Rna Transcription in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 주어진 String에서 특정 단어를 변경하면 되는 문제이다. 함수형 프로그래밍에 아직 익숙하지 않아서, 가급적 함수형으로 해보려고 노력중이다. split으로 iterable을 만들고 map을 돌려서 조건에 해당하는 경우에는 글자를 바꿔주었고, reduce로 다시 새로운 String으로 만들어서 retu..

Language/Dart 2022.09.18

[Exercism] Raindrops #String #Stringbuffer #immutual

https://exercism.org/tracks/dart/exercises/raindrops Raindrops in Dart on Exercism Can you solve Raindrops in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 주어진 수가 몇으로 나누어지는지에 따라서 다른 소리를 리턴해야하는 문제이다. String에 +를 이용해서 조건에 맞는 경우 소리를 추가하였다. class Raindrops { String convert(int number) { String sound = ''; if (number % 3 == 0) sound += 'Pling'; if (num..

Language/Dart 2022.09.11

[Exercism] Gigasecond #Duration #Named parameter

https://exercism.org/tracks/dart/exercises/gigasecond/iterations?idx=2 Exercism Learn, practice and get world-class mentoring in over 50 languages. 100% free. exercism.org 문제 자체는 정말 단순하게 gigasecond를 더하면 되는데, Duration을 처음 써볼 수 있었다. Duration은 말 그대로 기간을 나타내는 클래스인데, DateTime 클래스와 같이 많이 쓰는 것 같다. Dart에서 마음에 드는 것 중 하나는 named parameter인데, 이렇게 arguments가 어떤 값인지 바로 알 수 있어서 좋다. (자바는 named parameter가 없고, 코틀..

Language/Dart 2022.09.08

[Exercism] Hamming

https://exercism.org/tracks/dart/exercises/hamming Hamming in Dart on Exercism Can you solve Hamming in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 두 개의 주어진 문자열을 자리마다 비교해서 값이 다른 개수를 리턴하는 문제이다. 문제 조건에서 둘 중 하나가 empty이거나 길이가 다르면 에러를 던지도록 되어 있어서 먼저 에러 처리를 해주고, for문으로 각 자리를 비교해 다른 경우를 count하였다. if문에서 조건은 메서드로 분리를 해주는게 가독성이 더 좋다고 생각해서, 간단한 로직이지만 별도로 분..

Language/Dart 2022.09.08

[Excercism] Space Age #enum

https://exercism.org/tracks/dart/exercises/space-age Space Age in Dart on Exercism Can you solve Space Age in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org  행성과 초seconds가 주어지면 조건에 따라서 나이를 계산하는 문제이다. 각 행성들의 공전 주기가 Earth Year로 주어졌기 때문에 1) 행성별로 One Earth Year을 구하고, 2) 주어진 초를 지구 나이로 환산한 뒤에 2) / 1)로 답을 구했다. 비슷비슷한 개념이 많아서 메서드명이나 변수명을 어떻게 만들어야 하는지 고민이 되..

Language/Dart 2022.09.08

[Exercism] Bob

https://exercism.org/tracks/dart/exercises/bob Bob in Dart on Exercism Can you solve Bob in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 주어진 질문에 따라 알맞은 반응을 return 하는 문제이다. 정규표현식을 활용해서 각 조건을 만들어 주었다. 문제 자체가 많이 어렵지는 않았는데, 조건이 여러 개 들어가다보니 조건을 체크하는 순서도 고려해야 했다. 조건을 크게 isQuestion과 isYelling으로 구분할 수 있는데, 둘 다 적용되야 하는 경우를 가장 먼저 제시해주고, 그 다음에 각 조건에 맞는 경우를 ..

Language/Dart 2022.09.08

[Exercism] Word Count

https://exercism.org/tracks/dart/exercises/word-count Word Count in Dart on Exercism Can you solve Word Count in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 문제는 주어진 문장 안에서 word를 count하는 것이었는데, 이 word를 어떻게 규정하는지와 관련된 여러가지 조건들을 어떻게 코드로 풀어야 하는지 고민이 많았던 문제다. 다음의 세 가지 경우는 word 1개로 볼 수 있다. 각 조건은 정규표현식으로 만들고, map을 통해 해당하는 Iterable을 만들어주었다. class WordCo..

Language/Dart 2022.08.31

[Exercism] Difference Of Squares

https://exercism.org/tracks/dart/exercises/difference-of-squares Difference Of Squares in Dart on Exercism Can you solve Difference Of Squares in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 먼저 처음 풀이는 단순히 for문을 사용해서 푼 풀이다. 결과적으로 return해야하는 것은 합의제곱(squareOfSum)과 제곱의합(sumOfSquares)이다. import 'dart:math'; class DifferenceOfSquares { int squareOfSum(..

Language/Dart 2022.08.30