Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type fahrplan = (int*(int*int) list) list
- type wochentag = fahrplan
- type samstag = fahrplan
- type haltestelle = wochentag * samstag
- val dudw_str :haltestelle =
- ([(7,[(05,124),(10,112),(11,101),(20,124),(22,150),(35,124),(40,112),(41,101),(42,150),(43,124),(50,124)]),
- (8,[(05,124),(08,112),(10,112),(11,101),(20,124),(35,124),(38,112),(40,112),(41,101),(50,124)]),
- (9,[(10,112),(11,101),(20,124),(36,150),(38,112),(40,112),(41,101),(42,112),(50,124)]),
- (10,[(10,112),(11,101),(20,124),(40,112),(41,101),(50,124),(52,150)]),
- (11,[(10,112),(11,101),(20,124),(40,112),(41,101),(50,124)]),
- (12,[(10,112),(11,101),(20,124),(40,112),(41,101),(50,124),(52,150)]),
- (13,[(10,112),(11,101),(20,124),(40,112),(41,101),(42,150),(50,124)]),
- (14,[(10,112),(11,101),(20,124),(40,112),(41,101),(50,124)]),
- (15,[(05,124),(10,112),(11,101),(20,124),(35,124),(40,112),(41,101),(50,124),(52,150)]),
- (16,[(05,124),(10,112),(11,101),(20,124),(35,124),(37,150),(40,112),(41,101),(50,124)]),
- (17,[(05,124),(10,112),(11,101),(20,124),(35,124),(40,112),(41,101),(50,124)]),
- (18,[(05,124),(11,101),(20,124),(41,101),(50,124),(52,150)]),
- (19,[(11,101),(20,124),(41,101),(50,124)]),
- (20,[(11,101),(22,150)]),
- (21,[(02,101)])],
- [(7,[(02,101),(41,101)]),(8,[(11,101),(41,101)]),(9,[(11,101),(41,101)]),(10,[(11,101),(41,101)]),
- (11,[(11,101),(41,101)]),(12,[(11,101),(41,101),(57,150)]),(13,[(11,101),(41,101)]),
- (14,[(11,101),(17,150),(41,101)]),(15,[(11,101),(41,101)]),(16,[(11,101),(17,150),(41,101)]),
- (17,[(11,101),(41,101)]),(18,[(11,101),(52,101)]),(19,[(52,101)]),(20,[]),(21,[(02,101)])])
- val r_w_str :haltestelle =
- ([(7,[(18,109),(27,102),(41,102),(48,109),(50,111),(57,102)]),
- (8,[(05,111),(14,109),(20,111),(27,102),(35,111),(48,109),(50,111),(57,102)]),
- (9,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (10,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (11,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (12,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (13,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (14,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (15,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (16,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (17,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (18,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
- (19,[(27,102),(57,102)]),(20,[(27,102)]),(21,[(31,102)])],
- [(7,[(31,102),(57,102)]),(8,[(27,102),(57,102)]),(9,[(27,102),(57,102)]),
- (10,[(27,102),(57,102)]),(11,[(27,102),(57,102)]),(12,[(27,102),(57,102)]),
- (13,[(27,102),(57,102)]),(14,[(27,102),(57,102)]),(15,[(27,102),(57,102)]),
- (16,[(27,102),(57,102)]),(17,[(27,102),(57,102)]),(18,[(27,102)]),
- (19,[(27,102)]),(20,[(27,102)]),(21,[(31,102)])])
- fun bus() =
- let
- exception BadTime
- datatype weekday = Sun | Mon | Tue | Wed | Thu | Fri | Sat
- fun getDate() = Date.fromTimeLocal(Time.now())
- fun getTime(d) =
- if Date.minute(d)+5<60 then (Date.hour(d),Date.minute(d)+5)
- else (Date.hour(d)+1,(Date.minute(d)+5) mod 10)
- fun getDay(d) = Date.weekDay(d)
- fun findHour(stunde,nil) = raise BadTime
- | findHour(stunde,(p::pr):fahrplan) = if stunde = #1p then #2p else findHour(stunde,pr)
- fun findBus(minute,nil) = NONE
- | findBus(minute,(b::br) :(int*int) list) = if #1b < minute then findBus(minute,br) else SOME(b)
- val datum = getDate()
- val tag = getDay(datum)
- val (stunde,minute) = getTime(datum)
- val bus_dudw_str =
- if tag = Sun then (NONE,0)
- else if tag = Sat then (if findBus(minute, findHour(stunde,#2dudw_str)) = NONE then
- (findBus(0, findHour(stunde+1,#2dudw_str)),stunde+1)
- else (findBus(minute, findHour(stunde,#2dudw_str)),stunde)) handle BadTime => (NONE,0)
- else (if findBus(minute, findHour(stunde,#1dudw_str)) = NONE then
- (findBus(0, findHour(stunde+1,#1dudw_str)),stunde+1)
- else (findBus(minute, findHour(stunde,#1dudw_str)),stunde)) handle BadTime => (NONE,0)
- val bus_r_w_str =
- if tag = Sun then (NONE,0)
- else if tag = Sat then (if findBus(minute, findHour(stunde,#2r_w_str)) = NONE then
- (findBus(0, findHour(stunde+1,#2r_w_str)),stunde+1)
- else (findBus(minute, findHour(stunde,#2r_w_str)),stunde)) handle BadTime => (NONE,0)
- else (if findBus(minute, findHour(stunde,#1r_w_str)) = NONE then
- (findBus(0, findHour(stunde+1,#1r_w_str)),stunde+1)
- else (findBus(minute, findHour(stunde,#1r_w_str)),stunde)) handle BadTime => (NONE,0)
- fun printBus((NONE,_),(NONE,_)) = print("Was willst du denn jetzt an der Uni??? \n")
- | printBus((SOME(bus_dud :int*int),a),(NONE,_)) = print("Der naechste Bus: Linie "^Int.toString(#2bus_dud)^" um "^Int.toString(a)^":"^Int.toString(#1bus_dud)^" ab Haltestelle Dudweiler Strasse \n")
- | printBus((NONE,_),(SOME(bus_r_w :int*int),b)) = print("Der naechste Bus: Linie "^Int.toString(#2bus_r_w)^" um "^Int.toString(b)^":"^Int.toString(#1bus_r_w)^" ab Haltestelle Richard-Wagner-Strasse \n")
- | printBus((SOME(bus_dud :int*int),a),(SOME(bus_r_w :int*int),b)) =
- if a = b then
- if #1bus_dud < #1bus_r_w then
- print("Der naechste Bus: Linie "^Int.toString(#2bus_dud)^" um "^Int.toString(a)^":"^Int.toString(#1bus_dud)^" ab Haltestelle Dudweiler Strasse \n")
- else print("Der naechste Bus: Linie "^Int.toString(#2bus_r_w)^" um "^Int.toString(b)^":"^Int.toString(#1bus_r_w)^" ab Haltestelle Richard-Wagner-Strasse \n")
- else if a < b then print("Der naechste Bus: Linie "^Int.toString(#2bus_dud)^" um "^Int.toString(a)^":"^Int.toString(#1bus_dud)^" ab Haltestelle Dudweiler Strasse \n")
- else print("Der naechste Bus: Linie "^Int.toString(#2bus_r_w)^" um "^Int.toString(b)^":"^Int.toString(#1bus_r_w)^" ab Haltestelle Richard-Wagner-Strasse \n")
- in printBus(bus_dudw_str,bus_r_w_str)
- end
Add Comment
Please, Sign In to add comment