Skip to content

Instantly share code, notes, and snippets.

@mboya
Created May 15, 2024 15:35
Show Gist options
  • Save mboya/77bfa1286c67bdf5c581a3366fbd9624 to your computer and use it in GitHub Desktop.
Save mboya/77bfa1286c67bdf5c581a3366fbd9624 to your computer and use it in GitHub Desktop.
Button Challenge.
# # When Kevin turns on the machine, the screen displays the symbol '@'. When the button is pressed, the display of the screen changes in the following way:
# - 1st time button is pressed: '@' turns to '&&'
# - 2nd time button is pressed: '&&' turns to '&@&@'
# - 3rd time button is pressed: '&@&@' turns to '&@&&&@&&'
# - the 4th time the button is pressed: '&@&&&@&&' turns to '&@&&&@&@&@&&&@&@' and so forth.
# Requirements:
# - Create a function called `count_symbols` that will count the number of '@'s and '&'s that are displayed on the screen after the button has been pressed ñ number of times.
def count_symbols(clicker)
at = 1
amp,a,b=0
while (0 != clicker)
a = amp
b = amp + (at * 2)
at = a
amp = b
clicker -= 1
end
return a, b
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment