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
970
プライベートでも毎日コードを書く暮らし / Hatena Engineer Seminar #18
gurrium
0
1.4k
Other Decks in Programming
See All in Programming
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
500
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Exploring: Partial and Independent Composables
blackbracken
0
100
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
500
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
790
return文におけるstd::moveについて
onihusube
1
1.2k
php-conference-japan-2024
tasuku43
0
330
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
140
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
MCP with Cloudflare Workers
yusukebe
2
220
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Producing Creativity
orderedlist
PRO
341
39k
Scaling GitHub
holman
458
140k
Building Applications with DynamoDB
mza
91
6.1k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
4 Signs Your Business is Dying
shpigford
181
21k
A Tale of Four Properties
chriscoyier
157
23k
Optimising Largest Contentful Paint
csswizardry
33
3k
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