ZOJ Problem Set - 1182
Lazy functional languages like Haskell and Miranda support features that are not found in other programming languages, including infinite lists. Consider the following simple (and useful) recursive declaration:
The function cons constructs lists, so the above declaration creates the following structure:
cons 0 (count 1)
Lazy languages can do this because they only evaluate expressions that are actually used. If a program creates an infinite list and only looks at items 2 and 3 in it, the values in positions 0 and 1 are never evaluated and the list structure is only evaluated so far as the fourth node.
It is also possible to use more than one function to build an infinite list. Here is a declaration that creates the list ["even","odd","even",...]:
There are also functions that manipulate infinite lists. The functions take and drop can be used to remove elements from the start of the list, returning the (removed) front elements or the remainder of the list, respectively. Another useful function is zip, which combines two lists like the slider on a zipper combines the teeth. For example,
zip (count 0) (count 10) = [0,10,1,11,2,12,...]
Your task is to implement a subset of this functionality.
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Each declaration takes the form name = expr. There are two forms for expr : zip name1 name2 and x0 x1 ... xi name3. In the first case, name is the result of zipping name1 and name2 together. The other case defines the first i + 1 non-negative integers in the list name (where i is at least 0) and name3 is the name of the list that continues it (mandatory--all lists will be infinite).
The test cases take the form name s e, where s and e are non-negative integers, s <= e and e - s < 250.
No line of input will be longer than 80 characters. Names consist of a single capital letter.
Source: East Central North America 1998