본문 바로가기

Algorithm101

Total amount of points Description: Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the collection. For example: ["3:1", "2:2", "0:1", ...] Write a function that takes such collection and counts the points of our team in the championship. Rules for counting points for each match: if x > y: 3 points if x < y: 0 point if x = y: 1 point Notes: .. 2022. 4. 9.
Transportation on vacation Description: After a hard quarter in the office you decide to get some rest on a vacation. So you will book a flight for you and your girlfriend and try to leave all the mess behind you. You will need a rental car in order for you to get around in your vacation. The manager of the car rental makes you some good offers. Every day you rent the car costs $40. If you rent the car for 7 or more days,.. 2022. 4. 8.
Beginner - Lost Without a Map Description: Given an array of integers, return a new array with each value doubled. For example: [1, 2, 3] --> [2, 4, 6] Solution: 1. Get the elements out of the array. 2. Multiply the element by 2 and put it back into the array. 3. Return an array. def maps(a): return list(map(lambda x: x * 2, a)) The lambda function is an anonymous function and is suitable for simple calculations. 2022. 4. 7.
Hide Kata Description Description: You get an array of arrays. If you sort the arrays by their length, you will see, that their length-values are consecutive. But one array is missing! You have to write a method, that return the length of the missing array. Example: [[1, 2], [4, 5, 1, 1], [1], [5, 6, 7, 8, 9]] --> 3 If the array of arrays is null/nil or empty, the method should return 0. When an array in the array is.. 2022. 4. 5.
How Green Is My Valley? Description: Input : an array of integers. Output : this array, but sorted in such a way that there are two wings: the left wing with numbers decreasing, the right wing with numbers increasing. the two wings have the same length. If the length of the array is odd the wings are around the bottom, if the length is even the bottom is considered to be part of the right wing. each integer l of the le.. 2022. 4. 4.
Regexp Basics - is it a letter? Description: Complete the code which should return true if the given object is a single ASCII letter (lower or upper case), false otherwise. Solution: 1. Get the ASCII code of the argument. 2. Check whether the obtained ASCII code corresponds to the alphabet. 3. True if true, false otherwise. def is_letter(s): ascii_num = len(s) == 1 and ord(s) return (ascii_num >= 65 and ascii_num = 97 and asci.. 2022. 4. 3.