Created
May 15, 2024 15:35
-
-
Save mboya/77bfa1286c67bdf5c581a3366fbd9624 to your computer and use it in GitHub Desktop.
Button Challenge.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # 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