Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
290
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.6k
プライベートでも毎日コードを書く暮らし / Hatena Engineer Seminar #18
gurrium
0
1.6k
Other Decks in Programming
See All in Programming
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
140
Patterns of Patterns
denyspoltorak
0
190
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
180
Jetpack XR SDKから紐解くAndroid XR開発と技術選定のヒント / about-androidxr-and-jetpack-xr-sdk
drumath2237
1
180
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
1
480
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
140
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
110
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
AIコーディングエージェント(skywork)
kondai24
0
200
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.3k
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
460
AIエージェントの設計で注意するべきポイント6選
har1101
5
2k
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
The Curse of the Amulet
leimatthew05
0
4.6k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
68
Statistics for Hackers
jakevdp
799
230k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.6k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
240
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
96
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
130
How to make the Groovebox
asonas
2
1.8k
Site-Speed That Sticks
csswizardry
13
1k
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