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
250
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
作りながら紹介するマンガビューワの機能
gurrium
0
1k
プライベートでも毎日コードを書く暮らし / Hatena Engineer Seminar #18
gurrium
0
1.5k
Other Decks in Programming
See All in Programming
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
chibiccをCILに移植した結果 (NGK2025S版)
kekyo
PRO
0
150
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.4k
선언형 UI에서의 상태관리
l2hyunwoo
0
270
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
300
DMMオンラインサロンアプリのSwift化
hayatan
0
190
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
110
HTML/CSS超絶浅い説明
yuki0329
0
190
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
950
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
1
560
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
3
2.8k
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
335
57k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
KATA
mclloyd
29
14k
The Language of Interfaces
destraynor
155
24k
GraphQLとの向き合い方2022年版
quramy
44
13k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Designing Experiences People Love
moore
139
23k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
A Philosophy of Restraint
colly
203
16k
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