Advertisement
tomasfdel

Comp Tiger Practica 0

Aug 21st, 2019
3,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (print("print me daddy 0w0\n") ; 69)
  2.  
  3.  
  4. ???????????????????????????????????????????????????????????????????????????????????????????
  5.  
  6. let
  7.     type intList = {head: int, tail: intList}
  8.     function cons(elem:int, list:intList):intList = intList{head = elem, tail = list}
  9.     function length(list:intList):int = if list = nil
  10.                                         then 0
  11.                                         else 1 + length(list.tail)
  12.     function concat(l1:intList, l2:intList):intList = if l1 = nil
  13.                                                       then l2
  14.                                                       else cons(l1.head, concat(l1.tail, l2))
  15.     function snoc(elem:int, list:intList):intList = concat(list, intList{head = elem, tail = nil})
  16.     function filtra(filter:int, list:intList):intList =
  17.         if list = nil
  18.         then nil
  19.         else if list.head = filter
  20.              then filtra(filter, list.tail)
  21.              else cons(list.head, filtra(filter, list.tail))
  22.     function isin(elem:int, list:intList):int =
  23.         if list = nil
  24.         then 0
  25.         else if list.head = elem
  26.              then 1
  27.              else isin(elem, list.tail)
  28.     function remove(elem:int, list:intList):intList =
  29.         if list = nil
  30.         then nil
  31.         else if list.head = elem
  32.              then list.tail
  33.              else cons(list.head, remove(elem, list.tail))
  34.      function removeall(elem:int, list:intList):intList =
  35.          if list = nil
  36.          then nil
  37.          else if list.head = elem
  38.               then removeall(elem, list.tail)
  39.               else cons(list.head, removeall(elem, list.tail))
  40.     function reverse(list: intList):intList =
  41.         if list = nil
  42.         then nil
  43.         else snoc(list.head, reverse(list.tail))
  44.  
  45.     function printint(i : int) =
  46.       let function f(i : int) =
  47.            if i > 0
  48.            then (f (i/10); print(chr(i-i/10*10+ord("0"))))
  49.       in if i < 0
  50.          then (print("-"); f(i))
  51.          else if i>0
  52.               then f(i)
  53.               else print("0")
  54.       end
  55.  
  56.     function printlist(list: intList):int =
  57.         if list = nil
  58.         then (print("\n") ; 420)
  59.         else (printint(list.head) ; print(" ") ; printlist(list.tail))
  60. in
  61.     printlist(filtra(73, reverse(cons(3,cons(73, cons(100, cons(73, nil)))))))
  62.     /*(printint( isin(73, cons(3,cons(73, cons(100, nil))))) ; 5)*/
  63. end
  64.  
  65.  
  66. ???????????????????????????????????????????????????????????????????????????????????????????
  67.  
  68.  
  69. let
  70.     function printint(i : int) =
  71.       let function f(i : int) =
  72.            if i > 0
  73.            then (f (i/10); print(chr(i-i/10*10+ord("0"))))
  74.       in if i < 0
  75.          then (print("-"); f(i))
  76.          else if i>0
  77.               then f(i)
  78.               else print("0")
  79.       end
  80.  
  81.     type tree = {key : int, children : treelist}
  82.     type treelist = {hd : tree, tl : treelist}
  83.  
  84.     function length(tList : treelist):int =
  85.         if tList = nil
  86.         then 0
  87.         else 1 + length(tList.tl)
  88.  
  89.     function isBin(t : tree):int =
  90.         (length(t.children) < 3) & isBinList(t.children)
  91.  
  92.     function isBinList(tList : treelist):int =
  93.         if tList = nil
  94.         then 1
  95.         else isBin(tList.hd) & isBinList(tList.tl)
  96.  
  97.     function isComp(t : tree):int =
  98.         (length(t.children) = 0 | length(t.children) = 2) & isCompList(t.children)
  99.  
  100.     function isCompList(tList : treelist):int =
  101.         if tList = nil
  102.         then 1
  103.         else isComp(tList.hd) & isCompList(tList.tl)
  104.  
  105.     var tunit := tree{key = 3, children = nil}
  106.  
  107. in
  108.  
  109.     (printint( isBin( tree{key = 3, children =
  110.         treelist{hd = tunit, tl =
  111.             treelist{hd = tunit, tl =
  112.                 treelist{hd = tunit, tl =
  113.                     treelist{hd = tunit, tl =
  114.                         treelist{hd = tunit, tl = nil}}}}}}  ) ) ; 420 )
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement