0915. Beginner - Reduce but Grow Given a non-empty array of integers, return the result of multiplying the values together in order. Example: [1, 2, 3, 4] => 1 * 2 * 3 * 4 = 24 Solution: def grow(arr, i=1): return grow(arr, i*arr.pop()) if arr else i 나는 이렇게 학습한다/Algorithm & SQL 2022.09.15
0914. Rock Paper Scissors! Rock Paper Scissors Let's play! You have to return which player won! In case of a draw return Draw!. Examples(Input1, Input2 --> Output): "scissors", "paper" --> "Player 1 won!" "scissors", "rock" --> "Player 2 won!" "paper", "paper" --> "Draw!" Solution: from typing import Dict def check_draw(func): def wrapper(p1, p2): table = {"s":"p","r":"s","p":"r"} return p1 == p2 and "Draw!" or func(p1, p.. 나는 이렇게 학습한다/Algorithm & SQL 2022.09.14
0913. Take the Derivative This function takes two numbers as parameters, the first number being the coefficient, and the second number being the exponent. Your function should multiply the two numbers, and then subtract 1 from the exponent. Then, it has to print out an expression (like 28x^7). "^1" should not be truncated when exponent = 2. For example: derive(7, 8) In this case, the function should multiply 7 and 8, and.. 나는 이렇게 학습한다/Algorithm & SQL 2022.09.13
알고리즘 포스팅 관련 공지 'Algorithm & SQL' 카테고리는 매일 자동 포스팅되는 카테고리입니다. 구독자분들의 피드에 매일 알고리즘 글이 노출되는 것은 좋지 않다고 판단하여 9월 12일 부터 비공개로 포스팅합니다. *깃헙 레포는 기존과 동일하게 공개로 운영합니다. GitHub - Daco2020/Algorithm-SQL: 알고리즘과 SQL문제를 풀고 기록을 남기는 레포입니다. 알고리즘과 SQL문제를 풀고 기록을 남기는 레포입니다. Contribute to Daco2020/Algorithm-SQL development by creating an account on GitHub. github.com 나는 이렇게 학습한다/Algorithm & SQL 2022.09.13
0912. Fake Binary Given a string of digits, you should replace any digit below 5 with '0' and any digit 5 and above with '1'. Return the resulting string. Note: input will never be an empty string Solution: def fake_bin(x): return ''.join(str(int(i) >= 5 and 1 or 0) for i in x) 나는 이렇게 학습한다/Algorithm & SQL 2022.09.13
0911. Add Length What if we need the length of the words separated by a space to be added at the end of that same word and have it returned as an array? Example(Input --> Output) "apple ban" --> ["apple 5", "ban 3"] "you will win" -->["you 3", "will 4", "win 3"] Your task is to write a function that takes a String and returns an Array/list with the length of each word added to each element . Note: String will ha.. 나는 이렇게 학습한다/Algorithm & SQL 2022.09.11
0910. Quarter of the year Given a month as an integer from 1 to 12, return to which quarter of the year it belongs as an integer number. For example: month 2 (February), is part of the first quarter; month 6 (June), is part of the second quarter; and month 11 (November), is part of the fourth quarter. Solution: def quarter_of(month): return (lambda x: x%3==0 and x//3 or x//3+1)(month) Other Solution: from math import cei.. 나는 이렇게 학습한다/Algorithm & SQL 2022.09.10
0909. Will there be enough space? The Story: Bob is working as a bus driver. However, he has become extremely popular amongst the city's residents. With so many passengers wanting to get aboard his bus, he sometimes has to face the problem of not enough space left on the bus! He wants you to write a simple program telling him if he will be able to fit all the passengers. Task Overview: You have to write a function that accepts t.. 나는 이렇게 학습한다/Algorithm & SQL 2022.09.09
0908. Sorted? yes? no? how? Complete the method which accepts an array of integers, and returns one of the following: "yes, ascending" - if the numbers in the array are sorted in an ascending order "yes, descending" - if the numbers in the array are sorted in a descending order "no" - otherwise You can assume the array will always be valid, and there will always be one correct answer. Solution: def is_sorted_and_how(arr): .. 나는 이렇게 학습한다/Algorithm & SQL 2022.09.08
0907. Count by X Create a function with two arguments that will return an array of the first n multiples of x. Assume both the given number and the number of times to count will be positive numbers greater than 0. Return the results as an array or list ( depending on language ). Examples count_by(1,10) #should return [1,2,3,4,5,6,7,8,9,10] count_by(2,5) #should return [2,4,6,8,10] Solution: def get_range_index(f.. 나는 이렇게 학습한다/Algorithm & SQL 2022.09.07