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
今日の"どう書く"問題のアルゴリズム例
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Takashi Kanemoto
August 28, 2019
Programming
1.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
今日の"どう書く"問題のアルゴリズム例
Nagoya.php #17 補足資料
https://nagoyaphp.connpass.com/event/139314/
Takashi Kanemoto
August 28, 2019
More Decks by Takashi Kanemoto
See All by Takashi Kanemoto
API Platformを活用したPHPによる本格的なWeb API開発 / api-platform-book-intro
ttskch
2
240
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
5
1.4k
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
570
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
1.3k
今年書いた技術記事で伸びたやつの自慢と自分の中では力作なのにさっぱり伸びなかったやつの供養 / My Tech Articles 2024
ttskch
2
210
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
48
44k
データベース/SQL超入門!完全初心者向けに世界一分かりやすく解説します
ttskch
2
8.2k
Symfony UX Autocompleteとかいう 顧客が本当に必要だったもの
ttskch
0
2.3k
就活生あるいは新人エンジニアさんへのお節介なアドバイス
ttskch
0
1.7k
Other Decks in Programming
See All in Programming
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.6k
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
750
はてなアカウント基盤 State of the Union
cockscomb
1
920
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
360
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
280
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.6k
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
320
Datadog LLM Observabilityで実現する 安全なLLM Usage 管理
3150
0
120
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
15
7.4k
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
130
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
210
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
180
Featured
See All Featured
How to make the Groovebox
asonas
2
2.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
The Invisible Side of Design
smashingmag
301
52k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Believing is Seeing
oripsolob
1
160
Google's AI Overviews - The New Search
badams
0
1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
Transcript
ࠓͷ”Ͳ͏ॻ͘”ͷ ΞϧΰϦζϜྫ 2019/08/28 #nagoyaphp @ttskch
ʹ͍ͭͯ
͖ͨͭͪʢ໊͋ͩʣ • (ג)ΧϧςοτίϛϡχέʔγϣϯζCTO • WebΤϯδχΞྺ7ɺPHPྺ7 • #nagoyaphpʊ • #symfony_meetup
͖ͨͭͪʢ໊͋ͩʣ • ͓ख͍ͨ͠ຊʢ2015/12ʣ • Schooߨࢣʢ2018/04ʣ ʮGitHubΛͬͨσϓϩΠࣗಈԽ࣮ફʯ ʮجຊ͔Β͔ͬ͠ΓֶͿ Symfony2ೖʯ
ͨ ͭ ͖ ͪ twitter.com/ttskch ͋͞ɺ͋ͳͨࠓ͙͢ϑΥϩʔ͠Α͏!!! શແྉ ·͞ʹ໊ݴػ ਓੜͰେͳ͜ͱɺͯ͢ ͖͔ͨͭͪΒڭΘͬͨ
͖ͨͭͪΛϑΥϩʔͨ͠Β ࠊ௧͕࣏Γ·ͨ͠ 100% φϯτʂ ϑΥϩϫʔ͔Βͷࢧ࣋ 100% ͍ͯ͠Δ ͍ͯ͠ͳ͍ ϑΥϩϫʔ͞Μ100ਓʹฉ͖·ͨ͠ ͖ͨͭͪΛϑΥϩʔ͍ͯ͠Δʁ
ձࣾʹ͍ͭͯ
(ג)Χϧςοτίϛϡχέʔγϣϯζ https://quartet-communications.com
(ג)Χϧςοτίϛϡχέʔγϣϯζ https://www.google.co.jp/search?q=Χʔςϯ
(ג)Χϧςοτίϛϡχέʔγϣϯζ https://lisket.jp
We are hiring!ʢϚδͰʣ • PHPer/JSerઈࢍେืूதʂʢϦϞʔτόΠτՄʣ • Symfony+AngularͰɺWebࠂۀքΛ ϗϫΠτʹ͢ΔΈΛ࡞ͬͯ·͢ • ܦӦϏδϣϯʮੈքҰޮతͳཧళʯ
We are hiring!ʢϚδͰʣ • ࣗࣾαʔϏεʮLisketʯͰࣗࣾͷۀޮԽ • શࣾһͷฏۉۀ͕࣌ؒ5h/݄͙Β͍Ͱ͢ ಛผड
We are hiring!ʢϚδͰʣ ΤϯδχΞͷಇ͖͢͞େࣄʹͯ͠·͢✨
We are hiring!ʢϚδͰʣ ·͓͚ͣͩͰʂؾܰʹ͔͚͍ͯͩ͘͞
/30 We are hiring!ʢϚδͰʣ ࠾༻αΠτ͋Γ·͢ʂͥͻ͍ͯΈ͍ͯͩ͘͞ 14 https://quartetcom.co.jp/recruit/engineer/
ࠓͷ”Ͳ͏ॻ͘”ͷ ΞϧΰϦζϜྫ 2019/08/28 #nagoyaphp @ttskch
http://nabetani.sakura.ne.jp/hena/orde16nontri/
ී௨ʹΔͱ
public function run(string $input) : string { $dec = intval($input);
while (true) { $bin = decbin(strval(++$dec)); if (strpos($bin, '000') === false && strpos($bin, '111') === false) { return strval($dec); } } } 1૿͠ͳ͕Βɺஞ࣍ʮඇࡾ࿈͔ʁʯΛνΣοΫ͢Δ
public function run(string $input) : string { $dec = intval($input);
while (true) { $bin = decbin(strval(++$dec)); if (strpos($bin, '000') === false && strpos($bin, '111') === false) { return strval($dec); } } } 1૿͠ͳ͕Βɺஞ࣍ʮඇࡾ࿈͔ʁʯΛνΣοΫ͢Δ ೖྗͱظͷࠩʹൺྫͯ͠ ܭࢉྔ͕૿͑Δ
public function run(string $input) : string { $dec = intval($input);
while (true) { $bin = decbin(strval(++$dec)); if (strpos($bin, '000') === false && strpos($bin, '111') === false) { return strval($dec); } } } 1૿͠ͳ͕Βɺஞ࣍ʮඇࡾ࿈͔ʁʯΛνΣοΫ͢Δ ೖྗͱظͷࠩʹൺྫͯ͠ ܭࢉྔ͕૿͑Δ 100000000000000 (2) ͱ͔Λೖྗ͞ΕΔͱϠόΠ
ͯ͠ΈΔ
ྫᶃ 22
ྫᶃ 23 100010110001
24 100010110001 ࠷ॳͷ 000 Λݟ͚ͭΔ ྫᶃ
25 100110110001 ͦΕΛ 001 ʹஔ͖͑Δ ྫᶃ
26 100110110001 ଓ͖Λͯ͢ 001001... Ͱஔ͖͑Δ ྫᶃ
27 100100100100 ଓ͖Λͯ͢ 001001... Ͱஔ͖͑Δ ྫᶃ
28 100100100100 ྫᶃ
ྫᶄ 29
ྫᶄ 30 101110101101
31 101110101101 ࠷ॳͷ 0111 Λݟ͚ͭΔ ྫᶄ
32 110010101101 ͦΕΛ 1001 ʹஔ͖͑Δ ྫᶄ
33 110010101101 ଓ͖Λͯ͢ 001001... Ͱஔ͖͑Δ ྫᶄ
34 110010010010 ଓ͖Λͯ͢ 001001... Ͱஔ͖͑Δ ྫᶄ
35 110010010010 ྫᶄ
·ͱΊΔͱ 36
37 000͕ઌʹ ͋Δ߹ ࠷ॳͷ000Λ001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ
38 000͕ઌʹ ͋Δ߹ ࠷ॳͷ000Λ001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ
39 000͕ઌʹ ͋Δ߹ ࠷ॳͷ000Λ001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ ઌ಄͕111ͩͬͨΒʁ
40 000͕ઌʹ ͋Δ߹ ࠷ॳͷ000Λ001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ
41 000͕ઌʹ ͋Δ߹ ࠷ॳͷ000Λ001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ ͋Β͔͡Ίઌ಄ʹ0Λ༩্͓͍ͯͨ͠Ͱ
42 000͕ઌʹ ͋Δ߹ ࠷ॳͷ000Λ001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ ͋Β͔͡Ίઌ಄ʹ0Λ༩্͓͍ͯͨ͠Ͱ
͞Βʹͻͱ…
43 1000͕ઌʹ ͋Δ߹ ࠷ॳͷ1000Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ ͋Β͔͡Ίઌ಄ʹ0Λ༩্͓͍ͯͨ͠Ͱ
44 1000͕ઌʹ ͋Δ߹ ࠷ॳͷ1000Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ ͋Β͔͡Ίઌ಄ʹ0Λ༩্͓͍ͯͨ͠Ͱ
45 1000͕ઌʹ ͋Δ߹ ࠷ॳͷ1000Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ࠷ॳͷ0111Λ1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ ͋Β͔͡Ίઌ಄ʹ0Λ༩্͓͍ͯͨ͠Ͱ
46 1000͕ઌʹ ͋Δ߹ ࠷ॳͷ1000·ͨ0111Λ 1001ʹஔͯ͠ ΓΛ001ͷ॥ͰຒΊΔ 0111͕ઌʹ ͋Δ߹ ͋Β͔͡Ίઌ಄ʹ0Λ༩্͓͍ͯͨ͠Ͱ
ྫᶅ 47
ྫᶅ 48 110111010110
ྫᶅ 49 01101110101100 ઌ಄ʹ 0 Λ༩͢Δ
50 01101110101100 ࠷ॳͷ 0111 Λݟ͚ͭΔ ྫᶅ
51 01110010101100 ͦΕΛ 1001 ʹஔ͖͑Δ ྫᶅ
52 01110010101100 ଓ͖Λͯ͢ 001001... Ͱஔ͖͑Δ ྫᶅ
53 01110010010010 ଓ͖Λͯ͢ 001001... Ͱஔ͖͑Δ ྫᶅ
54 111001001001 ʁ ྫᶅ
55 111001001001 ൱ʂ ྫᶅ
མͱ݀͠ 56 • 0111Λ1001ʹஔͨ͜͠ͱͰɺ 111͕৽ͨʹ࡞ΒΕͯ͠·͏߹͕͋Δ • ಉ͡ૢ࡞Λ܁Γฦ͢ඞཁ͕͋Δʂ
݁ 57
58 • ͋Β͔͡Ίઌ಄ʹ0Λ༩্͓͍ͯͨ͠Ͱ • ࠷ॳͷ1000·ͨ0111Λ1001ʹஔͯ͠ • ΓΛ001ͷ॥ͰຒΊΔ • ઌ಄ͷ0ΛऔΓআ͘ •
…ͱ͍͏ૢ࡞Λඇࡾ࿈ʹͳΔ·Ͱ܁Γฦ͢
59 • ͋Β͔͡Ίઌ಄ʹ0Λ༩্͓͍ͯͨ͠Ͱ • ࠷ॳͷ1000·ͨ0111Λ1001ʹஔͯ͠ • ΓΛ001ͷ॥ͰຒΊΔ • ઌ಄ͷ0ΛऔΓআ͘ •
…ͱ͍͏ૢ࡞Λඇࡾ࿈ʹͳΔ·Ͱ܁Γฦ͢
࣮ྫ
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } }
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } } Ұ࿈ͷॲཧΛ܁Γฦ͢
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } } 2ਐʹมͯ͠ઌ಄ʹ0Λ༩
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } } ࠷ॳͷ1000·ͨ0111Λ୳͢
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } } ݟ͔ͭΒͳ͚Εඇࡾ࿈ͷ
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } } ઌ಄ͷ0ΛऔΓআ͖ͭͭ (1000|0111)ΑΓલͷ෦Λୀආ
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } } (1000|0111)ΑΓޙͷ෦Λ001...Ͱஔ
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } } ʮલʴ1001ʴޙʯͱ࿈݁ͯ͠10ਐʹ
public function run(string $input) : string { $dec = intval($input)
+ 1; while (true) { $bin = '0' . decbin($dec); preg_match('/(.*?)(1000|0111)(.*)/', $bin, $m); if (empty($m)) { return strval($dec); } $head = ltrim($m[1], '0'); $tailLength = strlen($m[3]); $tail = substr( str_repeat('001', intval(floor($tailLength / 3)) + 1), 0, $tailLength); $dec = strval(bindec($head . '1001' . $tail)); } }
https://github.com/ ttskch/nagoyaphp17
@ttskch ʘThanks!ʗ