Guest User

Untitled

a guest
May 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. type fahrplan = (int*(int*int) list) list
  2. type wochentag = fahrplan
  3. type samstag = fahrplan
  4. type haltestelle = wochentag * samstag
  5.  
  6. val dudw_str :haltestelle =
  7. ([(7,[(05,124),(10,112),(11,101),(20,124),(22,150),(35,124),(40,112),(41,101),(42,150),(43,124),(50,124)]),
  8. (8,[(05,124),(08,112),(10,112),(11,101),(20,124),(35,124),(38,112),(40,112),(41,101),(50,124)]),
  9. (9,[(10,112),(11,101),(20,124),(36,150),(38,112),(40,112),(41,101),(42,112),(50,124)]),
  10. (10,[(10,112),(11,101),(20,124),(40,112),(41,101),(50,124),(52,150)]),
  11. (11,[(10,112),(11,101),(20,124),(40,112),(41,101),(50,124)]),
  12. (12,[(10,112),(11,101),(20,124),(40,112),(41,101),(50,124),(52,150)]),
  13. (13,[(10,112),(11,101),(20,124),(40,112),(41,101),(42,150),(50,124)]),
  14. (14,[(10,112),(11,101),(20,124),(40,112),(41,101),(50,124)]),
  15. (15,[(05,124),(10,112),(11,101),(20,124),(35,124),(40,112),(41,101),(50,124),(52,150)]),
  16. (16,[(05,124),(10,112),(11,101),(20,124),(35,124),(37,150),(40,112),(41,101),(50,124)]),
  17. (17,[(05,124),(10,112),(11,101),(20,124),(35,124),(40,112),(41,101),(50,124)]),
  18. (18,[(05,124),(11,101),(20,124),(41,101),(50,124),(52,150)]),
  19. (19,[(11,101),(20,124),(41,101),(50,124)]),
  20. (20,[(11,101),(22,150)]),
  21. (21,[(02,101)])],
  22. [(7,[(02,101),(41,101)]),(8,[(11,101),(41,101)]),(9,[(11,101),(41,101)]),(10,[(11,101),(41,101)]),
  23. (11,[(11,101),(41,101)]),(12,[(11,101),(41,101),(57,150)]),(13,[(11,101),(41,101)]),
  24. (14,[(11,101),(17,150),(41,101)]),(15,[(11,101),(41,101)]),(16,[(11,101),(17,150),(41,101)]),
  25. (17,[(11,101),(41,101)]),(18,[(11,101),(52,101)]),(19,[(52,101)]),(20,[]),(21,[(02,101)])])
  26.  
  27. val r_w_str :haltestelle =
  28. ([(7,[(18,109),(27,102),(41,102),(48,109),(50,111),(57,102)]),
  29. (8,[(05,111),(14,109),(20,111),(27,102),(35,111),(48,109),(50,111),(57,102)]),
  30. (9,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  31. (10,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  32. (11,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  33. (12,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  34. (13,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  35. (14,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  36. (15,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  37. (16,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  38. (17,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  39. (18,[(05,111),(18,109),(27,102),(35,111),(48,109),(57,102)]),
  40. (19,[(27,102),(57,102)]),(20,[(27,102)]),(21,[(31,102)])],
  41. [(7,[(31,102),(57,102)]),(8,[(27,102),(57,102)]),(9,[(27,102),(57,102)]),
  42. (10,[(27,102),(57,102)]),(11,[(27,102),(57,102)]),(12,[(27,102),(57,102)]),
  43. (13,[(27,102),(57,102)]),(14,[(27,102),(57,102)]),(15,[(27,102),(57,102)]),
  44. (16,[(27,102),(57,102)]),(17,[(27,102),(57,102)]),(18,[(27,102)]),
  45. (19,[(27,102)]),(20,[(27,102)]),(21,[(31,102)])])
  46.  
  47. fun bus() =
  48.  
  49. let
  50.  
  51. exception BadTime
  52. datatype weekday = Sun | Mon | Tue | Wed | Thu | Fri | Sat
  53.  
  54. fun getDate() = Date.fromTimeLocal(Time.now())
  55. fun getTime(d) =
  56. if Date.minute(d)+5<60 then (Date.hour(d),Date.minute(d)+5)
  57. else (Date.hour(d)+1,(Date.minute(d)+5) mod 10)
  58. fun getDay(d) = Date.weekDay(d)
  59. fun findHour(stunde,nil) = raise BadTime
  60. | findHour(stunde,(p::pr):fahrplan) = if stunde = #1p then #2p else findHour(stunde,pr)
  61. fun findBus(minute,nil) = NONE
  62. | findBus(minute,(b::br) :(int*int) list) = if #1b < minute then findBus(minute,br) else SOME(b)
  63.  
  64.  
  65.  
  66. val datum = getDate()
  67. val tag = getDay(datum)
  68. val (stunde,minute) = getTime(datum)
  69.  
  70. val bus_dudw_str =
  71. if tag = Sun then (NONE,0)
  72. else if tag = Sat then (if findBus(minute, findHour(stunde,#2dudw_str)) = NONE then
  73. (findBus(0, findHour(stunde+1,#2dudw_str)),stunde+1)
  74. else (findBus(minute, findHour(stunde,#2dudw_str)),stunde)) handle BadTime => (NONE,0)
  75. else (if findBus(minute, findHour(stunde,#1dudw_str)) = NONE then
  76. (findBus(0, findHour(stunde+1,#1dudw_str)),stunde+1)
  77. else (findBus(minute, findHour(stunde,#1dudw_str)),stunde)) handle BadTime => (NONE,0)
  78.  
  79. val bus_r_w_str =
  80. if tag = Sun then (NONE,0)
  81. else if tag = Sat then (if findBus(minute, findHour(stunde,#2r_w_str)) = NONE then
  82. (findBus(0, findHour(stunde+1,#2r_w_str)),stunde+1)
  83. else (findBus(minute, findHour(stunde,#2r_w_str)),stunde)) handle BadTime => (NONE,0)
  84. else (if findBus(minute, findHour(stunde,#1r_w_str)) = NONE then
  85. (findBus(0, findHour(stunde+1,#1r_w_str)),stunde+1)
  86. else (findBus(minute, findHour(stunde,#1r_w_str)),stunde)) handle BadTime => (NONE,0)
  87.  
  88.  
  89. fun printBus((NONE,_),(NONE,_)) = print("Was willst du denn jetzt an der Uni??? \n")
  90. | 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")
  91.  
  92. | 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")
  93.  
  94. | printBus((SOME(bus_dud :int*int),a),(SOME(bus_r_w :int*int),b)) =
  95. if a = b then
  96. if #1bus_dud < #1bus_r_w then
  97. print("Der naechste Bus: Linie "^Int.toString(#2bus_dud)^" um "^Int.toString(a)^":"^Int.toString(#1bus_dud)^" ab Haltestelle Dudweiler Strasse \n")
  98. 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")
  99.  
  100. 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")
  101.  
  102. 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")
  103.  
  104. in printBus(bus_dudw_str,bus_r_w_str)
  105. end
Add Comment
Please, Sign In to add comment