본문 바로가기

STR20

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) 2022. 9. 13.
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.. 2022. 9. 9.
Playing with digits Some numbers have funny properties. For example: 89 --> 8¹ + 9² = 89 * 1 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51 Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p we want to find a positive integer k, if it exists, such that the sum of the digits of n taken to the successive powers of p is equal.. 2022. 8. 15.
Count the Digit Take an integer n (n >= 0) and a digit d (0 2022. 8. 5.
Descending Order Your task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number. Examples: Input: 42145 Output: 54421 Input: 145263 Output: 654321 Input: 123456789 Output: 987654321 Solution: def descending_order(num): return int("".join(sorted([i for i in str(num)], r.. 2022. 8. 5.
Form The Minimum Task Given a list of digits, return the smallest number that could be formed from these digits, using the digits only once (ignore duplicates). Notes: Only positive integers will be passed to the function (> 0 ), no negatives or zeros. Input >> Output Examples minValue ({1, 3, 1}) ==> return (13) Explanation: (13) is the minimum number could be formed from {1, 3, 1} , Without duplications minVal.. 2022. 8. 2.