Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This question has a certain induction feel to it. You want a function: (bool list list) -> (bool list) such that an inverse function (bool list) -> (bool list list) generates the same original structure, and the length of the encoded bool list is minimal, without imposing restrictions on the input structure. Since this question is so abstract, I'm thinking these lists could be mind bogglingly large - 10^50 maybe, or 10^2000, or they can be very small, like 10^0. Also, there can be a large number of lists, again 10^50 or just 1. So the algorithm needs to adapt to these widely different inputs.</p> <p>I'm thinking that we can encode the length of each list as a (bool list), and add one extra bool to indicate whether the next sequence is another (now larger) length or the real bitstream.</p> <pre> let encode2d(list1d::Bs) = encode1d(length(list1d), true) @ list1d @ encode2d(Bs) encode2d(nil) = nil let encode1d(1, nextIsValue) = true :: nextIsValue :: [] encode1d(len, nextIsValue) = let bitList = toBoolList(len) @ [nextIsValue] in encode1d(length(bitList), false) @ bitList let decode2d(bits) = let (list1d, rest) = decode1d(bits, 1) in list1d :: decode2d(rest) let decode1d(bits, n) = let length = fromBoolList(take(n, bits)) in let nextIsValue :: bits' = skip(n, bits) in if nextIsValue then bits' else decode1d(bits', length) </pre> <pre> assumed library functions ------------------------- toBoolList : int -> bool list this function takes an integer and produces the boolean list representation of the bits. All leading zeroes are removed, except for input '0' fromBoolList : bool list -> int the inverse of toBoolList take : int * a' list -> a' list returns the first count elements of the list skip : int * a' list -> a' list returns the remainder of the list after removing the first count elements </pre> <p>The overhead is per individual bool list. For an empty list, the overhead is 2 extra list elements. For 10^2000 bools, the overhead would be 6645 + 14 + 5 + 4 + 3 + 2 = 6673 extra list elements.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload