[2015-01-14] Challenge #197 [Intermediate] Food Delivery Problem

Squl. Squl is a Prolog off-shoot. This kind of problem is ideal for Prolog.

from:a to:b streetName:["South_Acorn_Drive] tA:[+5] tB:[+10] tC:[+5] tD:[+10].
from:b to:c streetName:["Acorn_Drive] tA:[+15] tB:[+5] tC:[+15] tD:[+5].
from:c to:d streetName:["North_Acorn_Drive] tA:[+7] tB:[+10] tC:[+15] tD:[+7].
from:h to:g streetName:["South_Almond_Way] tA:[+10] tB:[+10] tC:[+10] tD:[+10].
from:g to:f streetName:["Almond_Way] tA:[+15] tB:[+20] tC:[+15] tD:[+20].
from:f to:e streetName:["North_Almond_Way] tA:[+5] tB:[+6] tC:[+5] tD:[+6].
from:i to:j streetName:["South_Peanut_Lane] tA:[+8] tB:[+9] tC:[+10] tD:[+11].
from:j to:k streetName:["Peanut_Lane] tA:[+11] tB:[+10] tC:[+9] tD:[+8].
from:k to:l streetName:["North_Peanut_Lane] tA:[+7] tB:[+5] tC:[+7] tD:[+5].
from:p to:o streetName:["South_Walnut] tA:[+6] tB:[+5] tC:[+6] tD:[+5].
from:o to:n streetName:["Walnut] tA:[+10] tB:[+8] tC:[+10] tD:[+8].
from:n to:m streetName:["North_Walnut] tA:[+9] tB:[+6] tC:[+9] tD:[+6].
from:d to:e streetName:["West_Elm_Street] tA:[+10] tB:[+8] tC:[+12] tD:[+7].
from:e to:l streetName:["Elm_Street] tA:[+12] tB:[+11] tC:[+12] tD:[+8].
from:l to:m streetName:["East_Elm_Street] tA:[+5] tB:[+4] tC:[+5] tD:[+4].
from:c to:f streetName:["West_Central_Avenue] tA:[+9] tB:[+8] tC:[+9] tD:[+8].
from:f to:k streetName:["Central_Avenue] tA:[+5] tB:[+4] tC:[+5] tD:[+4].
from:k to:n streetName:["East_Central_Avenue] tA:[+9] tB:[+9] tC:[+9] tD:[+9].
from:b to:g streetName:["West_Pine_Road] tA:[+7] tB:[+6] tC:[+7] tD:[+6].
from:g to:j streetName:["Pine_Road] tA:[+9] tB:[+8] tC:[+9] tD:[+8].
from:j to:o streetName:["East_Pine_Road] tA:[+6] tB:[+5] tC:[+6] tD:[+5].
from:a to:h streetName:["West_Oak_Expressway] tA:[+9] tB:[+8] tC:[+7] tD:[+7].
from:h to:i streetName:["Oak_Expressway] tA:[+10] tB:[+10] tC:[+10] tD:[+10].
from:i to:p streetName:["East_Oak_Expressway] tA:[+8] tB:[+7] tC:[+8] tD:[+7].

then:(
    from:A
    to:EndIntersection
    startTime:StartTime
    route:( head:StreetName tail:Route ) )
if:(
    from:B
    to:EndIntersection
    startTime:NextTime
    route: Route )
if:(
    n:StartTime plus:StepCost result:NextTime )
if:(
    from:A to:B time:StartTime streetName:StreetName cost:StepCost ).

from:A
to:A
startTime:_
route:empty.

then:( from:A to:B time:StartTime streetName:StreetName cost:StepCost )
if:( lesser:[+0] greater:StartTime )
if:( lesser:StartTime greater:[+360] )
if:( from:A to:B streetName:StreetName tA:StepCost tB:_ tC:_ tD:_ ).

then:( from:A to:B time:StartTime streetName:StreetName cost:StepCost )
if:( lesser:[+360] greater:StartTime )
if:( lesser:StartTime greater:[+600] )
if:( from:A to:B streetName:StreetName tA:_ tB:StepCost tC:_ tD:_ ).

then:( from:A to:B time:StartTime streetName:StreetName cost:StepCost )
if:( lesser:[+600] greater:StartTime )
if:( lesser:StartTime greater:[+900] )
if:( from:A to:B streetName:StreetName tA:_ tB:_ tC:StepCost tD:_ ).

then:( from:A to:B time:StartTime streetName:StreetName cost:StepCost )
if:( lesser:[+900] greater:StartTime )
if:( lesser:StartTime greater:[+1140] )
if:( from:A to:B streetName:StreetName tA:StepCost tB:_ tC:_ tD:StepCost ).

then:( from:A to:B time:StartTime streetName:StreetName cost:StepCost )
if:( lesser:[+1140] greater:StartTime )
if:( from:A to:B streetName:StreetName tA:StepCost tB:_ tC:_ tD:StepCost ).

Result (see proviso below):

from:a
     to:m
     startTime:[+480]
     route:( head:["West_Oak_Expressway] tail:( head:["Oak_Expressway] tail:(     head:["East_Oak_Expressway] tail:( head:["South_Walnut] tail:( head:["Walnut] tail:( head:["North_Walnut] tail:empty ) ) ) ) ) )

Now:

It wouldn't run automatically. I needed to step through the debugger manually to get a solution.

If it would have run, it wouldn't have found the optimal solution.

I didn't convert times, and it only works for one day because I haven't implemented the modulo operator in Squl yet.

There's no syntactic sugar for lists yet.

Squl is a language that I'm developing, so these are problems I'll be working on.

/r/dailyprogrammer Thread