Add UE1 A.4, begin implementation for UE1 A.3
This commit is contained in:
parent
b1caccfe26
commit
1416d2f1f6
@ -59,7 +59,7 @@ tzr_zeuge z t
|
||||
| not (ist_tzr z t) = ("", t ++ t, "")
|
||||
| otherwise =
|
||||
let pos = (find_tzr_position z t 0) - 1
|
||||
pre = take (pos) z
|
||||
pre = take pos z
|
||||
suf = drop (pos + (length t)) z
|
||||
in (pre, t, suf)
|
||||
|
||||
@ -70,18 +70,36 @@ find_tzr_position (z:zs) t n
|
||||
| otherwise = find_tzr_position zs t (n + 1)
|
||||
|
||||
-- Aufgabe A.3
|
||||
|
||||
--tzr_zeugen :: Zeichenreihe -> Teilzeichenreihe -> Zerlegungszeugen
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht tzr_zeugen folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
tzr_zeugen :: Zeichenreihe -> Teilzeichenreihe -> Zerlegungszeugen
|
||||
tzr_zeugen [] [] = []
|
||||
tzr_zeugen z t
|
||||
| not (ist_tzr z t) = []
|
||||
| otherwise = []
|
||||
|
||||
|
||||
-- Aufgabe A.4
|
||||
|
||||
--wieOft :: Zeichenreihe -> Teilzeichenreihe -> Nat0
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht wieOft folgendermassen vor:
|
||||
...
|
||||
{-
|
||||
Solution:
|
||||
- we handle the case when the second string is empty - the result is always the length of the first string + 1
|
||||
- if the second string is not a substring of the first one, return 0 as a result
|
||||
- otherwise, count how many times the second string occurs in the first string by counting how many times the first string can be "cut" on the position of the second string
|
||||
-}
|
||||
|
||||
wieOft :: Zeichenreihe -> Teilzeichenreihe -> Nat0
|
||||
wieOft z [] = (length z) + 1
|
||||
wieOft z t
|
||||
| not (ist_tzr z t) = 0
|
||||
| otherwise = count_sub_string z t 0
|
||||
|
||||
--- find how many times a substring occurs in a string
|
||||
count_sub_string :: Zeichenreihe -> Teilzeichenreihe -> Nat0 -> Nat0
|
||||
count_sub_string z t n
|
||||
| not (ist_tzr z t) = n
|
||||
| otherwise =
|
||||
let
|
||||
pos = (find_tzr_position z t 0) - 1
|
||||
in count_sub_string (take pos z) t (n + 1)
|
||||
|
Reference in New Issue
Block a user