I Exercise on Programming I http://bit.ly/oitprog1 12 of 14 ( RD S ) I 12 of 14 1 / 35
https://bit.ly/oitprog1 ( RD S ) I 12 of 14 2 / 35
game.rb ( RD S ) I 12 of 14 3 / 35
game.rb 11 ( ) 1 require "io/console" 2 require "timeout" 3 k = "" 4 x = 5 5 sp = 1 6 life = 3 7 score = 0 8 buf = [] 9 while true 10 buf.unshift(" " * rand(40) + "#" * (score / 15)) 11 buf = buf[0, 9] 12 puts(buf[0]) 13 print("\x1b7\x1b[33m\x1b[10a\x1b[#{x}co\x1b8\x1b[0m") 14 begin 15 Timeout.timeout(0.1) do 16 while true do 17 k = STDIN.getch 18 if k == " " && sp > 0 19 print("\x1b[9a\x1b[j\x1b8") 20 buf = [""] 21 sp = sp - 1 22 else 23 x = (x + (k == "h"? -1 : 1)) % 40 24 end 25 end 26 end 27 rescue 28 end 29 life = life - 1 if buf[-1][x] == "#" 30 break if life <= 0 31 score = score + 1 32 end 33 puts(score) ( RD S ) I 12 of 14 4 / 35
game.rb LIFE O o. ( RD S ) I 12 of 14 5 / 35
1 O #{".oo"[life]} print("\x1b( )[#{x}co\x1b8\x1b[0m") print("\x1b( )[#{x}c#{".oo"[life]}\x1b8\x1b[0m") ( RD S ) I 12 of 14 6 / 35
S t r i n g I n t e g e r variable str = gets.chomp val = gets.to_i.to_s.to_i if else end while end break ( RD S ) I 12 of 14 8 / 35
0 sumall_919???.rb e1919123@edu1: $ ruby sumall_919123.rb # 31 # 31 27 # 27-16 # -16 0 # 0 42 # 31+27+(-16)=42 e1919123@edu1: $ ( RD S ) I 12 of 14 9 / 35
sum = 0 while true x = gets.to_i break if x == 0 sum = sum + x end puts(sum) ( RD S ) I 12 of 14 10 / 35
1 sum = 0 2 while true 3 break if (x = gets.to_i) == 0 4 sum = sum + x 5 end 6 puts(sum) a = 123 123 x=gets.to_i ( RD S ) I 12 of 14 11 / 35
n
: n.times do end 10.times do puts("hello, world") end ( RD S ) I 12 of 14 13 / 35
n?.times do end a = gets.to_i a.times do i puts(i) end ( RD S ) I 12 of 14 14 / 35
times i break 5 10 (5..10).each do i end (5..10).each do i puts(i * 3) end ( RD S ) I 12 of 14 15 / 35
times times 0 99 3 0 + 3 + 6 + + 99 sum3_100.rb (5 ) e1x19123@edu2: $ ruby sum3_100.rb 1683 e1x19123@edu2: $ ( RD S ) I 12 of 14 16 / 35
(a.k.a. )
: x x = 10 puts("-" * x) puts(" " * (x - 1) + " ") puts("-" * x) e1x19123@edu2: $ ruby barchart.rb ---------- ---------- e1x19123@edu2: $ ( RD S ) I 12 of 14 18 / 35
: x x = 10 puts("-" * x) puts(" " * (x - 1) + " ") puts("-" * x) e1x19123@edu2: $ ruby barchart.rb ---------- ---------- e1x19123@edu2: $ ( RD S ) I 12 of 14 18 / 35
= def end def draw_bar x = 10 puts("-" * x) puts(" " * (x - 1) + " ") puts("-" * x) end ( RD S ) I 12 of 14 19 / 35
def draw_bar # x = 10 # puts("-" * x) # puts(" " * (x - 1) + " ") # puts("-" * x) # end # draw_bar draw_bar # 1 # 2 ( RD S ) I 12 of 14 20 / 35
barchart.rb ( RD S ) I 12 of 14 21 / 35
1: def draw_bar # end 10.times do # 10 draw_bar # end # ( RD S ) I 12 of 14 22 / 35
:! def draw_bar x = 10 puts("-" * x) puts(" " * (x - 1)) puts("-" * x) end def draw_bar(x) puts("-" * x) puts(" " * (x - 1) + puts("-" * x) end ( RD S ) I 12 of 14 23 / 35
: 2 draw_bar(10) draw_bar(3) draw_bar(8) x 10, 3, 8 ( RD S ) I 12 of 14 24 / 35
ok! def draw_bar(x, f) puts("-" * x) puts(f * (x - 1) + " " + x.to_s) puts("-" * x) end # f # f draw_bar(20, "/") draw_bar(8, " ") draw_bar(13, "X") ( RD S ) I 12 of 14 25 / 35
( ) ( ) / Q.? def hoge a = 0 b = 456 end a = 123 puts(a) hoge puts(a) puts(b) ( RD S ) I 12 of 14 26 / 35
220 110 bus_fare busfare.rb 0 e1x19123@edu2: $ ruby busfare.rb 2 # [ ] 2 3 # [ ] 3 770 # [ ] 770 0 # [ ] 0 4 # [ ] 4 440 # [ ] 440 0 # [ ] 0 0 # [ ] 0 e1x19123@edu2: $ ( RD S ) I 12 of 14 27 / 35
3 Fizz 5 Buzz 3 5 Fizz Buzz 3 5 fizz_buzz 0 49 Fizz Buzz fizzbuzz_x19???.rb ( x19??? wx ) ( RD S ) I 12 of 14 28 / 35
( ) ex919123@edu1: $ ruby fizzbuzz_x19123.rb # Fizz Buzz # 0 3 5 Fizz Buzz 1 2 Fizz # 3 3 Fizz 4 Buzz # 5 5 Buzz Fizz # 6 3 Fizz ( ) Fizz # 48 3 Fizz 49 e1919123@edu1: $ ( RD S ) I 12 of 14 29 / 35
fizzbuzz_x19???.rb Google classroom https://classroom.google.com https://edu1.rd. oit.ac.jp/prog1/selfcheck.rb selfcheck.rb ( RD S ) I 12 of 14 30 / 35
( RD S ) I 12 of 14 32 / 35
( )
1 def fizz_buzz(x) # end # 0 49 # fizz_buzz ( ) ( RD S ) I 12 of 14 34 / 35
2 def fizz_buzz(x) # end 50.times do i # end ( RD S ) I 12 of 14 35 / 35