14810 - Gyro Zeppeli   

Description

HD wallpaper: Anime, Jojo's Bizarre Adventure, Gyro Zeppeli

Gyro Zeppeli is a Jojo character who utilizes "Golden ratio" to fight enemies. "Golden ratio" is the ratio you get when you divide a number in a Fibonacci sequence, Fn+1/Fn for n = infinity. The ratio is 1.618.

Given N commands and K length, you are asked to implement a list of numbers and generators that get manipulated by N commands and output the first K numbers.

The list's element is either:

  1. An integer
  2. A generator

Given this code:

def fib_gen(limit):
    # You need to implement this
    pass

def filter_gen(gen, condition):
    for x in gen:
        if condition(x):
            yield x

 

Implement:

  1. fib_gen() function, which is a generator function for a Fibonacci sequence. (use yield)
    e.g. 0, 1, 1, 2, 3, 5, 8, 12, ...
  2. fib index limit: It appends a limited Fibonacci sequence generator to the list at the given index.
  3. push index value: It appends an integer value to the list at the given index.
  4. pop index: It removes an integer or a whole generator from the list at the given index.
  5. filter comparison value: It filters all the integers inside the list (including the generators) based on the comparison and the value given.

 

For example, in sample input two:

10 10, means we are given 10 commands, and 10 numbers to output

fib 0 100, means push the first 100 Fibonacci generator to index 0. Your list now should look like this: [fib(0 to 100)]

push 1 10, means push the integer 10 to index 1. Your list now should look like this: [fib(0 to 100), 10]

push 0 15, means push the integer 15 to index 0. Your list now should look like this: [15, fib(0 to 100), 10]

push 0 150, means push the integer 150 to index 0. Your list now should look like this: [150, 15, fib(0 to 100), 10]

pop 1, means remove the index 1. Your list now should look like this: [150, fib(0 to 100), 10]

filter higher 20, means filter everything in your list only to remain every number that is higher than 20. Your list now should look like this: [150, filter(fib_gen(0 to 100, higher than 20))]

fib 0 15, means push the first 15 Fibonacci generator to index 0. Your list now should look like this: [fib(0 to 15), 150, filter(fib(0 to 100, higher than 20))]

filter lower 100, means filter everything in your list only to remain every number that is lower than 100. Your list now should look like this: [filter(fib(0 to 15), lower than 100), filter(filter(fib(0 to 100, higher than 20)), lower than 100)]

pop 0, means remove the index 0. Your list now should look like this: [filter(filter(fib(0 to 100, higher than 20)), lower than 100)]

push 0 100, means push the integer 100 to index 0. Your list now should look like this: [100, filter(filter(fib(0 to 100, higher than 20)), lower than 100)]

Therefore, your first 10 numbers should be 100, 34, 55, 89

Input

The first line is 2 integers, N and K, where:

  • N = the number of commands
  • K = the number of numbers you have to output. (generator is not a number)

The next N line will be either of these commands, in this format:

  • fib index limit
  • push index value
  • pop index
  • filter comparison value

Constraints

  • comparison is either lower | higher
  • index is never out of bounds.
  • limit <= 5000
  • value is an integer

​>Note: lower is < and higher is > (not equal to)

Output

Output K number from the list starting from the front.

If K > len(list), output len(list) numbers.

Sample Input  Download

Sample Output  Download

Tags




Discuss