Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
FizzBuzz code golf by ruby
Search
gurrium
February 22, 2018
Programming
1
200
FizzBuzz code golf by ruby
FizzBuzz code golf for hiroshima.rb #062
gurrium
February 22, 2018
Tweet
Share
More Decks by gurrium
See All by gurrium
プライベートでも毎日コードを書く暮らし / Hatena Engineer Seminar #18
gurrium
0
1.3k
Other Decks in Programming
See All in Programming
Elm 0.19.0 Changes
bkuhlmann
0
490
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
Tailwind CSSを本気でカスタマイズする方法
fsubal
13
5.3k
エンターテイメント業界で利用されるAWS
demuyan
0
210
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
810
Milestoner
bkuhlmann
1
410
Git Lint
bkuhlmann
4
750
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
270
Snowflakeで眠ったデータを起こそう!
estie
0
120
Scalable Customer Journey Orchestration (CJO)
lewuathe
0
330
MicrosoftのPlatform Engineeringガイドを読んで実際になにかやってみた
ymd65536
1
340
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
60
5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
187
16k
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
116
18k
Ruby is Unlike a Banana
tanoku
96
10k
Clear Off the Table
cherdarchuk
84
310k
Being A Developer After 40
akosma
57
580k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
2
3.4k
Making Projects Easy
brettharned
108
5.5k
How to train your dragon (web standard)
notwaldorf
73
5.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
6
1.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
Transcript
FizzBuzz code golf
first code
(1..100).each do |i| puts "#{i} " if i % 3
== 0 if i % 5 == 0 puts 'fizzbuzz' next else puts 'fizz' next end end if i % 5 == 0 puts 'buzz' next end end count 207
if…else…end -> ? :
(1..100).each do |i| print "#{i} " if i % 3
== 0 puts i % 5 == 0 ? 'fizzbuzz' : 'fizz' next end puts i % 5 == 0 ? 'buzz' : nil end count 148
nest conditional operator
(1..100).each do |i| print "#{i} " puts i % 3
== 0 ? i % 5 == 0 ? 'fizzbuzz' : 'fizz' : i % 5 == 0 ? 'buzz' : nil end count 122
do…end -> {…}
(1..100).each { |i| print "#{i} " puts i % 3
== 0 ? i % 5 == 0 ? 'fizzbuzz' : 'fizz' : i % 5 == 0 ? 'buzz' : nil } count 119
join lines
(1..100).each { |i| print "#{i} ";puts i % 3 ==
0 ? i % 5 == 0 ? 'fizzbuzz' : 'fizz' : i % 5 == 0 ? 'buzz' : nil } count 115
nil -> ''
(1..100).each { |i| print "#{i} “; puts i % 3
== 0 ? i % 5 == 0 ? 'fizzbuzz' : 'fizz' : i % 5 == 0 ? 'buzz' : '' } count 114
into string
(1..100).each { |i| puts "#{i} #{'fizz' if i % 3
== 0}#{'buzz' if i % 5 == 0}" } count 81
(1..100).each -> Integer#upto
1.upto(100) { |i| puts "#{i} #{'fizz' if i % 3
== 0}#{'buzz' if i % 5 == 0}" } count 79
i == 0 -> i < 1
1.upto(100) { |i| puts "#{i} #{'fizz' if i % 3
< 1}#{'buzz' if i % 5 < 1}" } count 77
delete whitespace
1.upto(100){|i|puts"#{i} #{'fizz'if i%3<1}#{'buzz'if i%5<1}"} count 62