/odd-jobs

A solution for 1Computer1‘s “Odd Jobs“ programming challenge.

Primary LanguageHaskellBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Odd Jobs

A solution for 1Computer1‘s “tasks“ challenge, solved in Haskell.



What is “Odd Jobs“?


“Odd Jobs“ is the title for one of the 4 programming challenges made up by 1Computer1 with no reward except the euphoric rush of finally seeing your program run successfully after extensive amounts of trial and error.

The “Odd Jobs“ challenge gives you 3 non-negative integers; N, M and D.

Integer N specifies the lines of tasks which are obligatory. Whereas the M integer specifies the lines of tasks which are not obligatory, but rather optional. And finally, the D integer specifies dependencies in the format

    Task A, Task B -> Task C, Task D
On the left-hand side are the tasks required in order to complete the tasks on the right-hand side.
Meaning, in order to complete Task C and Task D, both Task A and Task B must be completed before-hand.



My solution


My personal approach to solving the problem was quite inefficient, and there are definitely much better approaches to this.

Nonetheless, the outputs from the inputs yield the expected results. However, they are not ordered the same.

The way my solution works is by obtaining the input via the terminal, obtaining it, parsing it into pairs (obligatory tasks, optional tasks and dependencies), and from there on saving the obligatory tasks into a list of completed tasks, then splitting the dependencies into two parts:

  • requirements

  • tasks to do

It matches each required task against the current list of completed tasks, and if all of the required tasks have been completed, it adds new tasks that haven‘t already been completed into the list of completed tasks.

Below is a snippet of all of the inputs and outputs of each task example:

Alt Text

Alt Text 2