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
Takashi Kanemoto
August 28, 2019
Programming
1.4k
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
260
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
5
1.5k
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
580
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
1.3k
今年書いた技術記事で伸びたやつの自慢と自分の中では力作なのにさっぱり伸びなかったやつの供養 / My Tech Articles 2024
ttskch
2
220
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
48
45k
データベース/SQL超入門!完全初心者向けに世界一分かりやすく解説します
ttskch
2
8.5k
Symfony UX Autocompleteとかいう 顧客が本当に必要だったもの
ttskch
0
2.4k
就活生あるいは新人エンジニアさんへのお節介なアドバイス
ttskch
0
1.7k
Other Decks in Programming
See All in Programming
Build-to-own AI: Agentic Development for Humans
inesmontani
PRO
0
160
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.4k
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
190
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
380
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
280
FDEが実現するAI駆動経営の現在地
gonta
2
250
その節約、円になってますか?
isamumumu
1
640
React本体のコードリーディング
high_g_engineer
1
120
5分で問診!Composer セキュリティ健康診断
codmoninc
0
780
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
150
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
17k
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
260
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
190
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The agentic SEO stack - context over prompts
schlessera
0
860
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Context Engineering - Making Every Token Count
addyosmani
9
1k
Claude Code のすすめ
schroneko
67
230k
Marketing to machines
jonoalderson
1
5.6k
Test your architecture with Archunit
thirion
1
2.3k
Color Theory Basics | Prateek | Gurzu
gurzu
0
400
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
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!ʗ