20-CS-4003-001 | Organization of Programming Languages | Fall 2018 |
---|---|---|
Lab Assignment 9 |
Hamming's Sequence
Due: 5 November, 2018 (submit instructions: here)
Rationale: | |
Simple warmup exercise. | |
Lab Problem (three parts): | |
1. Create a haskell procedure called merge that takes as input two
(possibly infinite) lists of increasing integers and outputs a single
increasing sequence consisting of all the numbers in the two input lists.
For example, if the input lists are
[3,7,8,12,89] [1,2,8,9,19,22]then *Main> merge [3,7,8,12,89] [1,2,8,9,19,22] [1,2,3,7,8,8,9,12,19,22,89] 2. Create a haskell procedure called times that takes as input a positive integer m and a list of integers L and outputs a list of integers, each of which is m times its position counterpart in L. For example *Main> times 3 [4,8,9,16] [12,24,27,48] 3. Create a haskell procedure called hamming that takes as input an increasing list P of prime numbers and outputs all integers whose prime factors are a subset of P, in increasing order. For example *Main> take 20 (ham [3,5,11]) [3,5,9,11,15,25,27,33,45,55,75,81,99,121,125,135,165,225,243,275]Observe take must be used or else haskell attempts to print the entire (infinite) list. |