aboutsummaryrefslogtreecommitdiff
path: root/Semestr 3/anm/numerki/lista2
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-02-25 14:42:55 +0100
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-02-25 14:42:55 +0100
commit9477dbe667f250ecd23f8fc0d56b942191526421 (patch)
treea4b50c9a726f415f835f5311c11c5d66e95f688c /Semestr 3/anm/numerki/lista2
parent1968c1e590077bd51844eacfac722d7963848cb8 (diff)
Stare semestry, niepoukladane
Diffstat (limited to 'Semestr 3/anm/numerki/lista2')
-rw-r--r--Semestr 3/anm/numerki/lista2/rozw.ml33
1 files changed, 33 insertions, 0 deletions
diff --git a/Semestr 3/anm/numerki/lista2/rozw.ml b/Semestr 3/anm/numerki/lista2/rozw.ml
new file mode 100644
index 0000000..f946051
--- /dev/null
+++ b/Semestr 3/anm/numerki/lista2/rozw.ml
@@ -0,0 +1,33 @@
+(* Zadanie 1 *)
+
+let sublists l =
+ let rec backtrack sl = function
+ | [] -> [sl]
+ | hd :: tl -> (backtrack (sl @ [hd]) tl) @ backtrack sl tl
+ in backtrack [] l
+
+
+(* Zadanie 2 *)
+
+(* Znalezione tutaj: https://stackoverflow.com/questions/2710233/how-to-get-a-sub-list-from-a-list-in-ocaml *)
+
+let rec super_sublist b e = function
+ | [] -> failwith "empty list"
+ | hd :: tl ->
+ let tail = if e <= 1 then [] else super_sublist (b - 1) (e - 1) tl in
+ if b > 0 then tail else hd :: tail
+
+(* Moje rozwiązanie: *)
+
+let rec sublist b e l =
+ let rec suffix idx l =
+ if idx = 0 then l else suffix (idx - 1) (List.tl l) in
+ let rec prefix idx l =
+ if idx = 0 then [] else (List.hd l) :: (prefix (idx - 1) (List.tl l)) in
+ prefix (e - 1) (suffix b l)
+
+let cycle_with_sub sublist_fun xs n =
+ sublist_fun n (n + (List.length xs)) (xs @ xs)
+
+let super_cycle = cycle_with_sub super_sublist
+let cycle = cycle_with_sub sublist