Sha256: 9d8aa43009ba2dbd79e6ab5e2d12b99ead6927e82b8c635c0a138518afe297da

Contents?: true

Size: 616 Bytes

Versions: 41

Compression:

Stored size: 616 Bytes

Contents

module Sublist

type SublistType = Equal | Sublist | Superlist | Unequal

let rec isSublist xs ys lx ly = 
    let rec helper xs' ys' =
        match (xs', ys') with
        | [], _ -> true
        | x'::xs'', y'::ys'' when x' = y' -> helper xs'' ys''
        | _ -> false

    if lx > ly then false
    elif helper xs ys then true
    else isSublist xs (List.tail ys) lx (ly - 1)

let sublist xs ys = 
    match (List.length xs, List.length ys) with
    | x, y when x < y && isSublist xs ys x y -> Sublist
    | x, y when x > y && isSublist ys xs y x -> Superlist
    | _ when xs = ys -> Equal
    | _ -> Unequal

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/fsharp/exercises/sublist/Example.fs