Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
one_liner_fizzbuzz
Search
maimu
December 07, 2023
Programming
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
one_liner_fizzbuzz
maimu
December 07, 2023
More Decks by maimu
See All by maimu
Gentoo 1年生 ビルドは終わらない
maimux2x
0
100
Rails 1.0 のコードで学ぶ find_by* と method_missing の仕組み / Learn how find_by_* and method_missing work in Rails 1.0 code
maimux2x
1
1.5k
rails_girls_is_my_gate_to_join_the_ruby_commuinty
maimux2x
0
720
ruby-flip-flop
maimux2x
0
160
before_rails_girls_after_rails_girls
maimux2x
0
890
my_study_of_ruby_method
maimux2x
1
210
about_rails_girls_document_translation
maimux2x
0
6.4k
best_for_fbc
maimux2x
0
88
homemade_service_release_front_and_back
maimux2x
0
520
Other Decks in Programming
See All in Programming
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
170
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
330
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
150
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.6k
iOSDC2026登壇資料.pdf
riofujimon
0
160
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
580
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
1.2k
XHTMLが残したもの
yosuke_furukawa
PRO
2
800
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
480
A2UI for Android: Safely Rendering AI-Generated UI with Jetpack Compose - DroidKaigi 2026
itsmedreamwalker
0
140
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
710
AHC070解法紹介
eijirou
0
120
Featured
See All Featured
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
720
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
660
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.9k
Skip the Path - Find Your Career Trail
mkilby
1
230
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
430
Building Adaptive Systems
keathley
44
3.2k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
A better future with KSS
kneath
240
18k
Transcript
ワンライナーで FizzBuzz 2023/12/07 maimu
自己紹介 名前:maimu Xアカウント:maimux2x 所属:永和システムマネジメント エンジニア歴:4ヶ月 好きなRubyメソッド: Enumerable#map 好きなLinuxコマンド: tee
ワンライナーでFizzBuzz
なぜこのテーマなのか Linuxの勉強で学んだコマンドを使ってみたかった
ワンライナーとは? 1行で書かれたコマンドの組み合わせ
今回のお題
試作 seq 100 | awk '$1%15==0{print "FizzBuzz"}$1%5==0{print "Buzz"}$1%3==0{print "Fizz"}$1%15{print $1}'
コマンドについて seq : 連続した数字の列を出力・表示するコマンド awk : grepにプログラム機能をつけたようなもの(プログラミング言語) $1 : 読み込んだ行の1列目の文字列または数値
結果は・・・?
条件分岐を追加! seq 100 | awk '{ if ($1 % 15
== 0) print "FizzBuzz"; else if ($1 % 3 == 0) print "Fizz"; else if ($1 % 5 == 0) print "Buzz"; else print $1; }'
今度はできた!
他のコマンドも試したい
ebanさんのツイートにまさにシェル芸という模範解答が https://twitter.com/eban/status/830272982303936512 seq 1 100|sed '5~5s/.*/Buzz/;3~3s/[^B]*/Fizz/' 模範解答を見つけてしまった・・・
参考にしつつ自分もやってみる seq 100 | sed -e '3~3s/.*/Fizz/' -e '5~5s/.*/Buzz/' -e
'15~15s/.*/FizzBuzz/'
コマンドについて sed : 指定したファイルをコマンドに従って処理する -e : sedで複数のコマンドを指定する際に使用する s : 指定されたパターンに基づいて置換する
~ : 処理対象の位置を指定するアドレス指定子
できた!
もう1個やってみる seq 100 | sed -e '15~15c\FizzBuzz' -e '3~3c\Fizz' -e
'5~5c\Buzz'
コマンドについて c : 指定した行をテキストに置き換える
できた!
Rubyワンライナーでもやってみた seq 100 | ruby -ne 'if $_.to_i%15==0; puts "FizzBuzz"
elsif $_.to_i%5==0; puts "Buzz" elsif $_.to_i%3==0; puts "Fizz" else puts $_ end'
コマンドについて -e : 引数に記述されたRubyのコードを実行するためのオプション -n : 標準入力の内容を1行ずつ読み込む $_ : -nオプションで読み込んだ文字列が格納される変数
できた!
やってみた結果 • ワンライナーでFizzBuzzを4つ実行できた! ◦ 効率性は完全無視・・・ ◦ Rubyワンライナーは普通にコードを書いた方が分かりやすい・・・ • Linuxコマンドと少し仲良くなれた •
Rubyコマンドのオプションを初めて使った
今後の展望 • シェル・ワンライナー160本ノックをやり切りたい! • アイディアと手段を駆使したワンライナーを書いてみたい
参考文献 • man • 1日1問半年以内に習得 シェル・ワンライナー160本ノック