Skip to content

Instantly share code, notes, and snippets.

@CaseyLeask
Created October 29, 2016 12:19
Show Gist options
  • Save CaseyLeask/3c4402a0fcc1c79420d256e1712ef941 to your computer and use it in GitHub Desktop.
Save CaseyLeask/3c4402a0fcc1c79420d256e1712ef941 to your computer and use it in GitHub Desktop.
% Enter your code here. Read input from STDIN. Print output to STDOUT
% Your class should be named solution
-module(solution).
-export([main/0]).
main() ->
DateReturned = readDate(),
DueDate = readDate(),
DateDiff = calculateDifference(DateReturned, DueDate),
Fine = calculateFine(DateDiff),
io:fwrite("~w~n", [Fine]).
calculateDifference({Day1, Month1, Year1}, {Day2, Month2, Year2}) ->
{Day1 - Day2, Month1 - Month2, Year1 - Year2}.
calculateFine({_DayDiff, _MonthDiff, YearDiff}) when YearDiff < 0 ->
0;
calculateFine({_DayDiff, _MonthDiff, YearDiff}) when YearDiff > 0 ->
10000;
calculateFine({_DayDiff, MonthDiff, _YearDiff}) when MonthDiff < 0 ->
0;
calculateFine({_DayDiff, MonthDiff, _YearDiff}) when MonthDiff > 0 ->
MonthDiff * 500;
calculateFine({DayDiff, _MonthDiff, _YearDiff}) when DayDiff < 0 ->
0;
calculateFine({DayDiff, _MonthDiff, _YearDiff}) when DayDiff > 0 ->
DayDiff * 15;
calculateFine({_DayDiff, _MonthDiff, _YearDiff}) ->
0.
readDate() ->
{ok, [Day, Month, Year]} = io:fread("", "~d ~d ~d"),
{Day, Month, Year}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment