mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
feat(solutions): add find-closest-number/python/function
This commit is contained in:
parent
4e7cad4a70
commit
530f433028
@ -6,7 +6,7 @@ next(sys.stdin)
|
||||
for line in sys.stdin:
|
||||
quantity_per_cake, quantity_available = list(map(int, line.split(' ')))
|
||||
cake_possible = quantity_available // quantity_per_cake
|
||||
if maximum_number_of_cake_possible == None or cake_possible < maximum_number_of_cake_possible:
|
||||
if maximum_number_of_cake_possible is None or cake_possible < maximum_number_of_cake_possible:
|
||||
maximum_number_of_cake_possible = cake_possible
|
||||
|
||||
print(maximum_number_of_cake_possible)
|
||||
|
@ -0,0 +1,3 @@
|
||||
# find-closest-number/python/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 1 May 2022.
|
@ -0,0 +1,17 @@
|
||||
import sys
|
||||
|
||||
|
||||
def find_closest_number(integers: list[int], value: int) -> int:
|
||||
"""
|
||||
From list of integers, get number closest to a given value
|
||||
"""
|
||||
return min(integers, key=lambda x: abs(x - value))
|
||||
|
||||
|
||||
numbers: list[int] = []
|
||||
for value in sys.stdin:
|
||||
numbers.append(int(value.rstrip('\n')))
|
||||
|
||||
given_number = numbers[0]
|
||||
numbers = numbers[2:]
|
||||
print(find_closest_number(numbers, given_number))
|
@ -53,7 +53,7 @@ operations_index = int(nested[last_operation_index])
|
||||
current_value = None
|
||||
for index in range(len(operation_identifiers) - 1, -1, -1):
|
||||
current_identifier = operation_identifiers[index]
|
||||
if current_value == None:
|
||||
if current_value is None:
|
||||
current_value = assignments[current_identifier].get_by_index(
|
||||
operations_index)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user