Member-only story

Over-Engineered Python Code to Simple Julia Code

Solving a simple coding problem in Python and Julia

Erik Engheim
5 min readJul 3, 2022

I JUST came across a simple coding problem solved in Python. The complexity of the solution made me really ponder what could cause somebody to write such a complex solution. The person writing the code obviously understand coding, so why did they end up creating such a complex solution?

It made me wonder whether Python lends itself to this type of coding. It is a very subjective standpoint at this point. It is just that I keep seeing Python code which seems to overcomplicate things which I would have solved in a much more straightforward manner in Julia. Honestly, it seems implausible, but then again I have no simple answer.

The problem you got to solve is as follows:

Give five positive integers, find the minimum, maximum values that can be calculated by summing exactly four of the five integers.

Here is a solution where multiple permutations of four numbers are created and summed. Then we find the permutation of four elements which has the lowest sum and the permutation with the highest sum.

import itertools

def min_max(xs):
combos = list(itertools.combinations(xs, len(xs)-1))
sums = [sum(elements) for elements in combos]
return

--

--

Erik Engheim
Erik Engheim

Written by Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Responses (9)