본문 바로가기

나는 이렇게 학습한다/Algorithm & SQL405

0119. Thinkful - Number Drills: Blue and red marbles You and a friend have decided to play a game to drill your statistical intuitions. The game works like this: You have a bunch of red and blue marbles. To start the game you grab a handful of marbles of each color and put them into the bag, keeping track of how many of each color go in. You take turns reaching into the bag, guessing a color, and then pulling one marble out. You get a point if you.. 2023. 1. 19.
0118. Ordered Count of Characters Count the number of occurrences of each character and return it as a (list of tuples) in order of appearance. For empty output return (an empty list). Consult the solution set-up for the exact data structure implementation depending on your language. Example: ordered_count("abracadabra") == [('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)] Solution: def ordered_count(inp): from collections impo.. 2023. 1. 18.
0117. get character from ASCII Value Write a function get_char() / getChar() which takes a number and returns the corresponding ASCII char for that value. Example: get_char(65) should return: 'A' Solution: get_char = lambda x: chr(x) 2023. 1. 18.
0116. OOP: Object Oriented Piracy Ahoy matey! You are a leader of a small pirate crew. And you have a plan. With the help of OOP you wish to make a pretty efficient system to identify ships with heavy booty on board! Unfortunately for you, people weigh a lot these days, so how do you know if a ship is full of gold and not people? You begin with writing a generic Ship class / struct: class Ship: def __init__(self, draft, crew): s.. 2023. 1. 16.
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.
0114. Are arrow functions odd? Time to test your basic knowledge in functions! Return the odds from a list: [1, 2, 3, 4, 5] --> [1, 3, 5] [2, 4, 6] --> [] Solution: odds = lambda x: [i for i in x if i & 1] 2023. 1. 15.