본문 바로가기

sum56

0207. Divide and Conquer Given a mixed array of number and string representations of integers, add up the non-string integers and subtract this from the total of the string integers. Return as a number. Solution: def div_con(arr): x = sum(i for i in arr if isinstance(i, int)) y = sum(int(i) for i in arr if isinstance(i, str)) return x - y 2023. 2. 8.
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 .. 2023. 1. 28.
0125. Counting sheep... Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present). For example, [True, True, True, False, True, True, True, True , True, False, True, False, True, False, False, True , True, True, True, True , False, False, True, True] The correct answer would be 17. Hint: Don't forget to .. 2023. 1. 25.
0115. Name on billboard You can print your name on a billboard ad. Find out how much it will cost you. Each character has a default price of £30, but that can be different if you are given 2 parameters instead of 1. You can not use multiplier "*" operator. If your name would be Jeong-Ho Aristotelis, ad would cost £600. 20 leters * 30 = 600 (Space counts as a character). Solution: def billboard(name, price=30): return s.. 2023. 1. 15.
1208. A Strange Trip to the Market You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to shift octaves by 8 pitches or something silly like that, it dawns on you that you have been watching the musician for some 10 odd minutes. You a.. 2022. 12. 8.
1205. Sum of Cubes Write a function that takes a positive integer n, sums all the cubed values from 1 to n, and returns that sum. Assume that the input n will always be a positive integer. Examples: (Input --> output) 2 --> 9 (sum of the cubes of 1 and 2 is 1 + 8) 3 --> 36 (sum of the cubes of 1, 2, and 3 is 1 + 8 + 27) Solution: int sumCubes(int n) { int result = 0; for (int i=1; i i * i * i); return l.sum; } 2022. 12. 5.