summary refs log tree commit diff stats
path: root/python/code/2/1.py
diff options
context:
space:
mode:
authorSudipto Mallick <>2024-01-02 03:38:10 +0000
committerSudipto Mallick <>2024-01-02 03:38:10 +0000
commit7451edff7692e86c5238ff7bc6659825e242a84e (patch)
tree830fe25caf403869fe77df83bc44822ea6f5f11d /python/code/2/1.py
parenta70e0a59817ce06a3dd23b3750ae16ee6660deaf (diff)
downloadzadania-7451edff7692e86c5238ff7bc6659825e242a84e.tar.gz
Quick backup, need to be rewritten
Diffstat (limited to 'python/code/2/1.py')
-rw-r--r--python/code/2/1.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/python/code/2/1.py b/python/code/2/1.py
new file mode 100644
index 0000000..7ccd78f
--- /dev/null
+++ b/python/code/2/1.py
@@ -0,0 +1,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)))