Created
April 3, 2018 18:29
-
-
Save fractalatcarf/4f8f4f92c11620762313d4caeb9ab052 to your computer and use it in GitHub Desktop.
Live code Day 1
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
require 'date' | |
def days_until_xmas(now = Date.today) | |
xmas = Date.new(now.year, 12, 25) | |
days = (xmas - now).to_i | |
if days < 0 | |
xmas = Date.new(now.year + 1, 12, 25) | |
days = (xmas - now).to_i | |
end | |
return days | |
end | |
puts "#{days_until_xmas(Date.new(2018, 12, 5))} days remaining until next xmas" # 260 | |
puts "#{days_until_xmas(Date.new(2018, 12, 27))} days remaining until next xmas" # 260 | |
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
# mettre dans variable 'number' un chiffre entre 0 et 100 | |
# answer = nil | |
# attempts = 0 | |
# jusqu'à ce answer == number | |
# attempts = attempts + 1 | |
# demander au user un chiffre entre 0 et 100 | |
# mettre la réponse ds une variable 'answer' | |
# (attention, il faudra la convertir en integer) | |
# si answer < number afficher "c'est + !" | |
# si answer > number afficher "c'est - !" | |
# fin du "jusqu'à ce que" | |
# afficher "Congrats ! in #{attempts} attempts" | |
number = rand(101) | |
answer = nil | |
attempts = 0 | |
puts number | |
until answer == number | |
attempts += 1 | |
puts "please enter a number between 0 and 100" | |
answer = gets.chomp.to_i | |
puts "Try greater" if answer < number | |
puts "Try lower" if answer > number | |
end | |
puts "Congrats !! in #{attempts} attempts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment