As a magician-to-be, Elyse needs to practice some basics. She has a stack of cards that she wants to manipulate.
To make things a bit easier she only uses the cards 1 to 10 so her stack of cards can be represented by a vector of numbers. The position of a certain card corresponds to the index in the vector.
To pick a card, return the card at index position from the given stack.
stack <- c(1, 2, 4, 1)
position <- 3
get_item(stack, position)
# => 4Perform some sleight of hand and exchange the card at index position with the replacement card provided.
Return the adjusted stack.
stack <- c(1, 2, 4, 1)
position <- 3
replacement_card <- 6
set_item(stack, position, replacement_card)
# => c(1, 2, 6, 1)Make a card appear by inserting a new card at the top of the stack. Return the adjusted stack.
stack <- c(5, 9, 7, 1)
new_card <- 8
insert_item_at_top(stack, new_card)
# => c(5, 9, 7, 1, 8)Make a card disappear by removing the card at the given position from the stack.
Return the adjusted stack.
stack <- c(3, 2, 6, 4, 8)
position <- 3
remove_item(stack, position)
# => c(3, 2, 4, 8)Check whether the size of the stack is equal to stack_size or not.
stack <- c(3, 2, 6, 4, 8)
stack_size <- 4
check_size_of_stack(stack, stack_size)
# => FALSEMake a card disappear by removing the card at the top of the stack. Return the adjusted stack.
stack <- c(3, 2, 6, 4, 8)
remove_item_from_top(stack)
# => c(3, 2, 6, 4)Make a card appear by inserting a new card at the bottom of the stack. Return the adjusted stack.
stack <- c(5, 9, 7, 1)
new_card <- 8
insert_item_at_bottom(stack, new_card)
# => c(8, 5, 9, 7, 1)Make a card disappear by removing the card at the bottom of the stack. Return the adjusted stack.
stack <- c(8, 5, 9, 7, 1)
remove_item_at_bottom(stack)
# => c(5, 9, 7, 1)As a magician-to-be, Elyse needs to practice some basics. She has a stack of cards that she wants to manipulate.
To make things a bit easier she only uses the cards 1 to 10 so her stack of cards can be represented by a vector of numbers. The position of a certain card corresponds to the index in the vector.
To pick a card, return the card at index position from the given stack.
stack <- c(1, 2, 4, 1)
position <- 3
get_item(stack, position)
# => 4Perform some sleight of hand and exchange the card at index position with the replacement card provided.
Return the adjusted stack.
stack <- c(1, 2, 4, 1)
position <- 3
replacement_card <- 6
set_item(stack, position, replacement_card)
# => c(1, 2, 6, 1)Make a card appear by inserting a new card at the top of the stack. Return the adjusted stack.
stack <- c(5, 9, 7, 1)
new_card <- 8
insert_item_at_top(stack, new_card)
# => c(5, 9, 7, 1, 8)Make a card disappear by removing the card at the given position from the stack.
Return the adjusted stack.
stack <- c(3, 2, 6, 4, 8)
position <- 3
remove_item(stack, position)
# => c(3, 2, 4, 8)Check whether the size of the stack is equal to stack_size or not.
stack <- c(3, 2, 6, 4, 8)
stack_size <- 4
check_size_of_stack(stack, stack_size)
# => FALSEMake a card disappear by removing the card at the top of the stack. Return the adjusted stack.
stack <- c(3, 2, 6, 4, 8)
remove_item_from_top(stack)
# => c(3, 2, 6, 4)Make a card appear by inserting a new card at the bottom of the stack. Return the adjusted stack.
stack <- c(5, 9, 7, 1)
new_card <- 8
insert_item_at_bottom(stack, new_card)
# => c(8, 5, 9, 7, 1)Make a card disappear by removing the card at the bottom of the stack. Return the adjusted stack.
stack <- c(8, 5, 9, 7, 1)
remove_item_at_bottom(stack)
# => c(5, 9, 7, 1)