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
290
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
5
1.6k
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
600
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
1.4k
今年書いた技術記事で伸びたやつの自慢と自分の中では力作なのにさっぱり伸びなかったやつの供養 / My Tech Articles 2024
ttskch
2
230
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
48
45k
データベース/SQL超入門!完全初心者向けに世界一分かりやすく解説します
ttskch
2
8.6k
Symfony UX Autocompleteとかいう 顧客が本当に必要だったもの
ttskch
0
2.4k
就活生あるいは新人エンジニアさんへのお節介なアドバイス
ttskch
0
1.7k
Other Decks in Programming
See All in Programming
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
460
プロポーザルを書いてもらう
pvcresin
0
590
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
550
Introducing Stack Pull Request in GitHub
kkamegawa
0
120
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
290
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
46
30k
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
130
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
250
ALB ログから Trace を気合で繋げる技術
fohte
7
810
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
480
バグを直したら useEffect が消えた
colorful12
3
780
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
170
Featured
See All Featured
The Curse of the Amulet
leimatthew05
2
14k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
460
Amusing Abliteration
ianozsvald
1
280
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Thoughts on Productivity
jonyablonski
76
5.3k
Technical Leadership for Architectural Decision Making
baasie
3
550
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
290
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Marketing to machines
jonoalderson
1
5.7k
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!ʗ