blob: 7ccd78f3d6602040527823d93c5b9165c1415892 (
plain) (
blame)
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
|
def gaussian_sum_even(numbers):
assert len(numbers) % 2 == 0
start_index, end_index = 0, len(numbers) - 1
sum = 0
while start_index < end_index:
print(numbers[start_index], '+', numbers[end_index])
sum += numbers[start_index] + numbers[end_index]
start_index += 1
end_index -= 1
print('Result:', sum)
gaussian_sum_even(list(range(1, 7)))
def gaussian_sum(numbers):
start_index, end_index = 0, len(numbers) - 1
sum = 0
while start_index < end_index:
print(numbers[start_index], '+', numbers[end_index])
sum += numbers[start_index] + numbers[end_index]
start_index += 1
end_index -= 1
middle_value = numbers[len(numbers) // 2]
print(middle_value)
sum += middle_value
print('Result:', sum)
gaussian_sum(list(range(1, 10)))
|