본문 바로가기

count18

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.
1210. Bumps in the Road Your car is old, it breaks easily. The shock absorbers are gone and you think it can handle about 15 more bumps before it dies totally. Unfortunately for you, your drive is very bumpy! Given a string showing either flat road (_) or bumps (n). If you are able to reach home safely by encountering 15 bumps or less, return Woohoo!, otherwise return Car Dead Solution: def bumps(road): return road.cou.. 2022. 12. 11.
1017. Enumerable Magic - Does My List Include This? Create a method that accepts a list and an item, and returns true if the item belongs to the list, otherwise false. Solution: from typing import List def include(arr: List[int], item: int) -> bool: return bool(arr.count(item)) 2022. 10. 17.
1012. All Star Code Challenge #18 This Kata is intended as a small challenge for my students All Star Code Challenge #18 Create a function that accepts 2 string arguments and returns an integer of the count of occurrences the 2nd argument is found in the first one. If no occurrences can be found, a count of 0 should be returned. ("Hello", "o") ==> 1 ("Hello", "l") ==> 2 ("", "z") ==> 0 Notes: The first argument can be an empty s.. 2022. 10. 12.
Find the stray number You are given an odd-length array of integers, in which all of them are the same, except for one single number. Complete the method which accepts such an array, and returns that single different number. The input array will always be valid! (odd-length >= 3) Examples [1, 1, 2] ==> 2 [17, 17, 3, 17, 17, 17, 17] ==> 3 Solution: def stray(arr): import collections return [k for k, v in collections.C.. 2022. 8. 19.
Find the unique number There is an array with some numbers. All numbers are equal except for one. Try to find it! find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2 find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55 It’s guaranteed that array contains at least 3 numbers. The tests contain some very huge arrays, so think about performance. Solution: def find_uniq(arr): n = arr[0] == arr[-1] and arr[0] or arr[1] return [i for i in arr if n != i.. 2022. 8. 8.