일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 파이썬
- js
- decorator
- FOR
- map
- enumerate
- MAX
- count
- range
- 위코드
- Algorithm
- slice
- list
- len
- If
- iNT
- STR
- or
- Python
- Sorted
- lambda
- WECODE
- join
- split
- DART
- sum
- SQL
- LOWER
- and
- index
- Today
- Total
목록sum (56)
코드로 우주평화
Create a function that takes 2 integers in form of a string as an input, and outputs the sum (also as a string): Example: (Input1, Input2 -->Output) "4", "5" --> "9" "34", "5" --> "39" "", "" --> "0" "2", "" --> "2" "-5", "3" --> "-2" Notes: If either input is an empty string, consider it as zero. Inputs and the expected output will never exceed the signed 32-bit integer limit (2^31 - 1) Solutio..
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..
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..
You get an array of numbers, return the sum of all of the positives ones. Example [1,-4,7,12] => 1 + 7 + 12 = 20 Note: if there is nothing to sum, the sum is default to 0. Solution: def positive_sum(arr): return sum(map(remove_negative, arr)) def remove_negative(i: int): return i if i >= 0 else 0
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..
If a = 1, b = 2, c = 3 ... z = 26 Then l + o + v + e = 54 and f + r + i + e + n + d + s + h + i + p = 108 So friendship is twice stronger than love :-) The input will always be in lowercase and never be empty. Solution: def words_to_marks(s: str, ord_num: int = 96): return sum(ord(i)-ord_num for i in s)
Task Sum all the numbers of a given array ( cq. list ), except the highest and the lowest element ( by value, not by index! ). The highest or lowest element respectively is a single element at each edge, even if there are more than one with the same value. Mind the input validation. Example { 6, 2, 1, 8, 10 } => 16 { 1, 1, 11, 2, 3 } => 6 Input validation If an empty value ( null, None, Nothing ..
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..
Given a sequence of numbers, find the largest pair sum in the sequence. For example [10, 14, 2, 23, 19] --> 42 (= 23 + 19) [99, 2, 2, 23, 19] --> 122 (= 99 + 23) Input sequence contains minimum two elements and every element is an integer. Solution: def largest_pair_sum(numbers): return sum(sorted(numbers)[-2:])
Write a function that takes an array of numbers and returns the sum of the numbers. The numbers can be negative or non-integer. If the array does not contain any numbers then you should return 0. Examples Input: [1, 5.2, 4, 0, -1] Output: 9.2 Input: [] Output: 0 Input: [-2.398] Output: -2.398 Assumptions You can assume that you are only given numbers. You cannot assume the size of the array. You..