Skip to content

Instantly share code, notes, and snippets.

@execat
Created May 16, 2019 16:05
Show Gist options
  • Save execat/b375fa0f65b26517719d993217b0bb77 to your computer and use it in GitHub Desktop.
Save execat/b375fa0f65b26517719d993217b0bb77 to your computer and use it in GitHub Desktop.
# I am a bank.
# I need PEOPLE to give their name and open an account.
# If the account balance < 10, then send them warning email.
# If the account balance < 0, then close the account
# If the account balance > 10M, then send them a "thank you" email
# I have a customer X. X's balance is $10.
# Today: X walks in. Deposits $40. New balance $50.
# Tomorrow: X walks in. Deposits $33. New balance $83.
# After that: X walks in. Withdraws $3. New balance $80.
# After that: X walks in. Deposits $20M. New balance $20,000,080.
x_money = 10
puts "Before day 1"
puts x_money
# function definition
def deposit(value, x_money, day)
puts "Day #{day}"
x_money = x_money + value
puts x_money
if (x_money < 10)
puts "WARNING"
end
if (x_money > 10_000_000)
puts "Thanks!"
end
x_money # Ignore this
end
# Day 1
x_money = deposit(40, x_money, 1) # function call
# Day 2
x_money = deposit(33, x_money, 2)
# Day 3
x_money = deposit(-3, x_money, 3)
# Day 4
x_money = deposit(20_000_000, x_money, 4)
# Day 5
x_money = deposit(-10_000_000, x_money, 5)
# Day 6
x_money = deposit(-10_000_080, x_money, 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment