@@ -172,30 +172,68 @@ We will simulate a cookie distribution network:
# Homework 3 (Data)
# Homework 3 (Assignment)
Tasks:
- read the cookie network from a JSON file (we'll provide example data, use `JSON.jl`)
- make a nice data structure to hold this problem, make sure the input is valid
- make functions that:
- find the length of the *longest chain* (by transport "steps") from the factory to the muncher
- find out how many cookies the factory needs to produce daily so that *all munchers are fed*
- construct a network where all *transports are split in half*, each half with half cookie consumption
- find out *how many cookies are wasted* by being routed to munchers who can't eat them
- construct a network where the *distribution points are balanced* so that no cookies get wasted
-*BONUS: print the network nicely*
- for simplicity, data structures and functions may be recursive
- performance optimization _is not_ a goal
- nice short code _is_ a goal
# Homework 3 (Example data)
```json
{type:"distribution point",
serves:[
{type:"muncher",consumption:3},
{type:"transport",
capacity:5,
serves:{
type:"distribution point",
serves:[
{type:"muncher",consumption:7},
{type:"muncher",consumption:2},
{type:"muncher",consumption:1}
]
ratios:[1,1,1]
{"type":"distribution point",
"serves":[
{"type":"muncher",
"consumption":3},
{"type":"transport",
"capacity":5,
"serves":{
"type":"distribution point",
"serves":[
{"type":"muncher",
"consumption":7},
{"type":"muncher",
"consumption":2},
{"type":"muncher",
"consumption":1}],
"ratios":[1,1,1]
}
}
],
ratios:[1,5]
"ratios":[1,5]
}
```
Pretty-printed (one possibility):
# Homework 3 (expected results on the example data)
- make one common abstract type for "everything in the network"
- longest chain length: 3 (any of the "nested" munchers is at the longest chain)
- required daily production for feeding all munchers: 36 (7+7+7 cookies for the nested munchers because of 1:1:1 ratio, that needs 5 cookies for transport (26 total), and overfeeds the first muncher by 3 cookies because of 6+30 in ratio 1:5). Alternative ways to compute are OK (if allowing non-integer cookies, we'd get something like 30.24 daily consumption).
- transports split in half: instead of `... -> transport 5 -> ...` the network should contain something like `... -> transport 10 -> transport 10 -> ...`.
- how many cookies are wasted: the easiest way to guess is to assume perfect distribution and make a difference from the required daily production. In this case, if distribution ratios were perfect, the network would consume 15 cookies daily (10 for the nested munchers + 2 for transport + 3 for the other muncher), which wastes 21 or 15.24 cookies depending on the interpretation.