Skip to content

Instantly share code, notes, and snippets.

@bonyiii
Created March 13, 2014 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonyiii/9531930 to your computer and use it in GitHub Desktop.
Save bonyiii/9531930 to your computer and use it in GitHub Desktop.
berlin clock
# TODO
# tömbként tároljuk az lámpa sorokat
# lámp sorok tömbe tartalmazzák a state -ket
# másodperc alapján eldöntjük az első sort
# óra / 5 kidja a második sorban színes lámpák számát annyi indexet felkapcsolunk
# óra mod 5 vissza adja a harmadik sor szines lámpák számát
# perc / 5 negyedik sor minden 3 piros
# pert mod 5
#
class BerlinClock
def self.current
now = Time.now
puts now
puts (now.sec / 2 == 0 ) ? 'Y' : 0
puts
five_hours = now.hour / 5
4.times.each do |lamp|
print (five_hours > lamp) ? "Y" : 0
end
puts
hours = now.hour % 5
4.times.each do |lamp|
print ( hours > lamp) ? "Y" : 0
end
puts
five_minutes = now.min / 5
11.times.each do |lamp|
print ( five_minutes > lamp) ? lamp_color(lamp) : 0
end
puts
minutes = now.min % 5
4.times.each do |lamp|
print ( minutes > lamp) ? "Y" : 0
end
end
def self.lamp_color(idx)
((idx +1) % 3 == 0) ? "R" : "Y"
end
end
loop do
BerlinClock.current
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment