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
300
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
3.7k
プライベートでも毎日コードを書く暮らし / Hatena Engineer Seminar #18
gurrium
0
1.7k
Other Decks in Programming
See All in Programming
Patterns of Patterns
denyspoltorak
0
1.4k
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
290
CSC307 Lecture 02
javiergs
PRO
1
770
登壇資料を作る時に意識していること #登壇資料_findy
konifar
3
810
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
440
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
170
Package Management Learnings from Homebrew
mikemcquaid
0
200
2026年 エンジニアリング自己学習法
yumechi
0
130
Architectural Extensions
denyspoltorak
0
270
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.9k
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
110
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.2k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
97
The Cost Of JavaScript in 2023
addyosmani
55
9.5k
Building an army of robots
kneath
306
46k
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
350
Facilitating Awesome Meetings
lara
57
6.7k
How GitHub (no longer) Works
holman
316
140k
Paper Plane (Part 1)
katiecoart
PRO
0
4k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
47
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