0212. Reversed sequence Build a function that returns an array of integers from n to 1 where n>0. Example : n=5 --> [5,4,3,2,1] Solution: reverse_seq = lambda n: sorted(range(1, n+1), reverse=True) def reverseseq(n): return list(range(n, 0, -1)) 나는 이렇게 학습한다/Algorithm & SQL 2023.02.13
0128. Gauß needs help! (Sums of a lot of numbers). Due to another of his misbehaved, the primary school's teacher of the young Gauß, Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates, assigned him the problem of adding up all the whole numbers from 1 through a given number n. Your task is to help the young Carl Friedrich to solve this problem .. 나는 이렇게 학습한다/Algorithm & SQL 2023.01.28
0121. esreveR Write a function reverse which reverses a list (or in clojure's case, any list-like data structure) (the dedicated builtin(s) functionalities are deactivated) Solution: def reverse(lst): result = list() for _ in range(len(lst)): result.append(lst.pop()) return result 나는 이렇게 학습한다/Algorithm & SQL 2023.01.21
0113. Build a square I will give you an integer. Give me back a shape that is as long and wide as the integer. The integer will be a whole number between 1 and 50. Example n = 3, so I expect a 3x3 square back just like below as a string: +++ +++ +++ Solution: def generate_shape(n: int) -> str: return "\n".join("+" * n for i in range(n)) 나는 이렇게 학습한다/Algorithm & SQL 2023.01.13
0103. Powers of 2 Complete the function that takes a non-negative integer n as input, and returns a list of all the powers of 2 with the exponent ranging from 0 to n ( inclusive ). Examples n = 0 ==> [1] # [2^0] n = 1 ==> [1, 2] # [2^0, 2^1] n = 2 ==> [1, 2, 4] # [2^0, 2^1, 2^2] Solution: def powers_of_two(n: str) -> list[int]: return [pow(2, i) for i in range(n+1)] 나는 이렇게 학습한다/Algorithm & SQL 2023.01.03
1229. Parts of a list Write a function partlist that gives all the ways to divide a list (an array) of at least two elements into two non-empty parts. Each two non empty parts will be in a pair (or an array for languages without tuples or a structin C - C: see Examples test Cases - ) Each part will be in a string Elements of a pair must be in the same order as in the original array. Examples of returns in different l.. 나는 이렇게 학습한다/Algorithm & SQL 2022.12.30
1228. Kata Example Twist This is an easy twist to the example kata (provided by Codewars when learning how to create your own kata). Add the value "codewars" to the array websites/Websites 1,000 times. Solution: websites = ["codewars" for _ in range(1000)] websites = ["codewars"] * 1000 나는 이렇게 학습한다/Algorithm & SQL 2022.12.28
1211. Maximum Product Task Given an array of integers , Find the maximum product obtained from multiplying 2 adjacent numbers in the array. Notes Array/list size is at least 2. Array/list numbers could be a mixture of positives, negatives also zeroes . Input >> Output Examples adjacentElementsProduct([1, 2, 3]); ==> return 6 Explanation: The maximum product obtained from multiplying 2 * 3 = 6, and they're adjacent nu.. 나는 이렇게 학습한다/Algorithm & SQL 2022.12.11
1112. Sum of Multiples Your Job Find the sum of all multiples of n below m Keep in Mind n and m are natural numbers (positive integers) m is excluded from the multiples Examples sumMul(2, 9) ==> 2 + 4 + 6 + 8 = 20 sumMul(3, 13) ==> 3 + 6 + 9 + 12 = 30 sumMul(4, 123) ==> 4 + 8 + 12 + ... = 1860 sumMul(4, -7) ==> "INVALID" Solution: def invalid_value(func): def wrapper(n, m): return (n 나는 이렇게 학습한다/Algorithm & SQL 2022.11.13
1027. Filling an array (part 1) We want an array, but not just any old array, an array with contents! Write a function that produces an array with the numbers 0 to N-1 in it. For example, the following code will result in an array containing the numbers 0 to 4: arr(5) // => [0,1,2,3,4] Note: The parameter is optional. So you have to give it a default value. Solution: def arr(n: int = 0): return [i for i in range(n)] 나는 이렇게 학습한다/Algorithm & SQL 2022.10.28