Skip to content

Commit 5bc4530

Browse files
authored
Added odd_sum and smooth_max solutions
Added odd_sum and smooth_max solutions that I created
1 parent 985cb00 commit 5bc4530

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Odd Sum
2+
# Given a 2D list, find the sum of all elements at odd indexes for all
3+
# the lists at odd indexes. Print this sum times the sum of all
4+
# first element of all the 1D lists in the 2D list.
5+
#
6+
# Ex:[[1,2,3,6],[2,41,2,1]]should have print 42 after the program runs.
7+
#
8+
# Write the code below.
9+
10+
two_d_list = [[1,2,3,5,2],[2,3,1,4],[2,3,1,2,21],[21,3,1,41]]
11+
#two_d_list should print 51 after the program runs.
12+
13+
odd_sum = 0
14+
for outer_idx in range(1,len(two_d_list),2):
15+
for inner_idx in range(1, len(two_d_list[outer_idx]),2):
16+
odd_sum += two_d_list[outer_idx][inner_idx]
17+
18+
first_sum = 0
19+
for inner_list in range(len(two_d_list)):
20+
first_sum += two_d_list[inner_list][0]
21+
22+
print(odd_sum* first_sum )
23+
24+
25+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Given a 2D list, let's call a element "smooth" if index of the
2+
# element in its 1D list plus the element is even. For example,
3+
# given the 2D list [[0,4][2,6]], the 1st element of each of the
4+
# 1D list is considered "smooth" because 0 + 0 is 0 and 0 + 2 is 2
5+
# (both are even numbers). Find the maximum "smooth" element and
6+
# print it. Using the example [[0,4][2,6]] again, the maximum
7+
# "smooth" element is 2 because 2 is bigger than 0.
8+
9+
two_d_list = [[425,214,412,123],[312,214,123,343]]
10+
curr_max = None
11+
12+
for outer_idx in range(len(two_d_list)):
13+
for inner_idx in range(len(two_d_list[outer_idx])):
14+
curr_elem = two_d_list[outer_idx][inner_idx]
15+
to_check = curr_elem + inner_idx
16+
if to_check % 2 == 0:
17+
if curr_max == None or curr_elem > curr_max:
18+
curr_max = curr_elem
19+
20+
print(curr_max)
21+
22+
23+
24+

0 commit comments

Comments
 (0)