본문 바로가기

decorator25

1001. Hello, Name or World! Define a method hello that returns "Hello, Name!" to a given name, or says Hello, World! if name is not given (or passed as an empty String). Assuming that name is a String and it checks for user typos to return a name with a first capital letter (Xxxx). Examples: * With `name` = "john" => return "Hello, John!" * With `name` = "aliCE" => return "Hello, Alice!" * With `name` not given or `name` =.. 2022. 10. 2.
0930. Count of positives, sum of negatives Given an array of integers. Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative. If the input is an empty array or is null, return an empty array. Example For input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15], you should return [10, -65]. Solution: def sorted_arr(func): def w.. 2022. 9. 30.
0929. Summing a number's digits Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits. For example: (Input --> Output) 10 --> 1 99 --> 18 -32 --> 5 Let's assume that all numbers in the input will be integer values. Solution: def get_str_number(func): def wrapper(number): return func(str(number).replace("-", "")) return wrapper @get_str_nu.. 2022. 9. 29.
0923. Sum of differences in array Your task is to sum the differences between consecutive pairs in the array in descending order. Example [2, 1, 10] --> 9 In descending order: [10, 2, 1] Sum: (10 - 2) + (2 - 1) = 8 + 1 = 9 If the array is empty or the array has only one element the result should be 0 (Nothing in Haskell, None in Rust). Solution: def sort(func): def wrapper(arr): return func(sorted(arr, reverse=True)) return wrap.. 2022. 9. 23.
0918. Grasshopper - Array Mean Find Mean Find the mean (average) of a list of numbers in an array. Information To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list. For an example list of 1, 3, 5, 7 Add all of the numbers 1+3+5+7 = 16 Divide by the number of values in the list. In this example there are 4 numbers in the list. 16/4 = 4 The mean (or averag.. 2022. 9. 19.
0916. Do you speak "English"? Given a string of arbitrary length with any ascii characters. Write a function to determine whether the string contains the whole word "English". The order of characters is important -- a string "abcEnglishdef" is correct but "abcnEglishsef" is not correct. Upper or lower case letter does not matter -- "eNglisH" is also correct. Return value as boolean values, true for the string to contains "En.. 2022. 9. 16.