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
2.4k
プライベートでも毎日コードを書く暮らし / Hatena Engineer Seminar #18
gurrium
0
1.5k
Other Decks in Programming
See All in Programming
GoとPHPのインターフェイスの違い
shimabox
2
190
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
170
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
160
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
11
3.8k
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
750
Amazon Bedrock Multi Agentsを試してきた
tm2
1
290
もう僕は OpenAPI を書きたくない
sgash708
5
1.8k
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
270
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
750
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
840
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
110
楽しく向き合う例外対応
okutsu
0
130
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
A better future with KSS
kneath
238
17k
Designing for humans not robots
tammielis
250
25k
Why Our Code Smells
bkeepers
PRO
336
57k
Fireside Chat
paigeccino
34
3.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Being A Developer After 40
akosma
89
590k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.8k
A Philosophy of Restraint
colly
203
16k
4 Signs Your Business is Dying
shpigford
182
22k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
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