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
270
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
5
1.5k
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
590
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
1.4k
今年書いた技術記事で伸びたやつの自慢と自分の中では力作なのにさっぱり伸びなかったやつの供養 / 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
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
190
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
220
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
220
React本体のコードリーディング
high_g_engineer
1
140
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
450
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3.5k
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
670
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
220
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
590
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
340
What's in a price? How to price your products and services
michaelherold
247
13k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.2k
Building the Perfect Custom Keyboard
takai
2
830
The Mindset for Success: Future Career Progression
greggifford
PRO
0
440
The Cost Of JavaScript in 2023
addyosmani
55
10k
Between Models and Reality
mayunak
4
390
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
280
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
760
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
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!ʗ