Sort (2) 썸네일형 리스트형 [EP0062] 같은 숫자로 이루어진 세제곱이 다섯개 #!/usr/bin/env python # Project Euler 62 # http://projecteuler.net/index.php?section=problems&id=62 # Problem 62 # # The cube, 41063625 (3453), can be permuted to produce two other cubes: # 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest # cube which has exactly three permutations of its digits which are also # cube. # # Find the smallest cube for which exactly five permut.. Swift codewars 연습문제 gravity swift 문법을 배우면서 연습을 하기 위해서, codewars 문제를 몇 개 풀어보기 시작함. gravity 라는 문제를 풀어봤다. 그냥 숫자로 주어진 리스트를 L 또는 R 인자에 따라 ascending, descending 으로 sort한 결과를 리턴하는 함수를 짜면 된다. 내 풀이는 다음과 같다. func flip(_ direction:String, _ a: [Int]) -> [Int] { if direction == "L" { return a.sorted(by: >) } return a.sorted(by: 와 < 라는 두 람다 중에 하나를 선택하게 했다. 람다를 3항연산자로 선택가능하고 (그것도 간단한 신택스로) 코드가 예뻐서 블로그에서 한번 언급하고 싶었다. codewars 를 풀면, 풀어내는 .. 이전 1 다음