Last active
February 2, 2018 16:05
-
-
Save anthonyshull/0d43659e2ea6c4f1aa6f3ddb9053d1f9 to your computer and use it in GitHub Desktop.
Electricity Transmission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Transmit = Station -> Station -> Supply option -> Station * Station | |
let transmit (fStation: Station) (tStation: Station) (supply: Supply option) = | |
match fStation, tStation, supply with | |
| PowerStation fStation, TransmissionSubstation tStation, Some (Supply supply) -> | |
match fStation.Supply, tStation.Supply with | |
| Some (Supply fStationSupply), Some (Supply tStationSupply) -> | |
if fStationSupply > supply then | |
PowerStation { fStation with Supply = Supply (fStationSupply - supply) }, | |
TransmissionSubstation { tStation with Supply = Supply (tStationSupply + supply) } | |
else | |
PowerStation { fStation with Supply = None }, | |
TransmissionSubstation { tStation with Supply = Supply (tStationSupply + fStationSupply)} | |
| None, _ | _, _ -> PowerStation fStation, TransmissionSubstation tStation | |
| TransmissionSubstation fStation, TransmissionSubstation tStation, Some (Supply supply) -> | |
match fStation.Supply, tStation.Supply with | |
| Some (Supply fStationSupply), Some (Supply tStationSupply) -> | |
if fStationSupply > supply then | |
TransmissionSubstation { fStation with Supply = Supply (fStationSupply - supply) }, | |
TransmissionSubstation { tStation with Supply = Supply (tStationSupply + supply) } | |
else | |
TransmissionSubstation { fStation with Supply = None }, | |
TransmissionSubstation { tStation with Supply = Supply (tStationSupply + fStationSupply)} | |
| None, _ | _, _ -> TransmissionSubstation fStation, TransmissionSubstation tStation | |
| _, _, None | _, _, _ -> fStation, tStation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment