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
240
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
900
プライベートでも毎日コードを書く暮らし / Hatena Engineer Seminar #18
gurrium
0
1.4k
Other Decks in Programming
See All in Programming
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
160
Tauriでネイティブアプリを作りたい
tsucchinoko
0
350
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
420
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
2.7k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
440
C#/.NETのこれまでのふりかえり
tomokusaba
1
180
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
2.4k
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
120
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
450
Click-free releases & the making of a CLI app
oheyadam
2
100
僕がつくった48個のWebサービス達
yusukebe
20
17k
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1.5k
Featured
See All Featured
Scaling GitHub
holman
458
140k
Building Your Own Lightsaber
phodgson
102
6.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
What's new in Ruby 2.0
geeforr
343
31k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Designing Experiences People Love
moore
138
23k
Unsuck your backbone
ammeep
668
57k
Designing the Hi-DPI Web
ddemaree
280
34k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
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