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
February 13, 2019
Programming
1
530
今日の"どう書く"問題のアルゴリズム例
Nagoya.php #14 LT 資料
https://nagoyaphp.connpass.com/event/115049/
Takashi Kanemoto
February 13, 2019
Tweet
Share
More Decks by Takashi Kanemoto
See All by Takashi Kanemoto
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
220
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
400
今年書いた技術記事で伸びたやつの自慢と自分の中では力作なのにさっぱり伸びなかったやつの供養 / My Tech Articles 2024
ttskch
2
84
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
47
32k
データベース/SQL超入門!完全初心者向けに世界一分かりやすく解説します
ttskch
1
4.9k
Symfony UX Autocompleteとかいう 顧客が本当に必要だったもの
ttskch
0
1.9k
就活生あるいは新人エンジニアさんへのお節介なアドバイス
ttskch
0
1.5k
symfony/pantherでWordleを解いてみた
ttskch
0
290
ついに、Webアプリでの帳票印刷のベストプラクティスを編み出しました💡
ttskch
16
19k
Other Decks in Programming
See All in Programming
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
190
asdf-ecspresso作って 友達が増えた話 / Fujiwara Tech Conference 2025
koluku
0
1.5k
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
180
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
240
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
Azure AI Foundryのご紹介
qt_luigi
1
220
선언형 UI에서의 상태관리
l2hyunwoo
0
270
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
0
110
Scaling your build logic
antalmonori
1
120
為你自己學 Python
eddie
0
530
rails newと同時に型を書く
aki19035vc
6
730
Featured
See All Featured
Become a Pro
speakerdeck
PRO
26
5.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
How to Ace a Technical Interview
jacobian
276
23k
Why Our Code Smells
bkeepers
PRO
335
57k
Being A Developer After 40
akosma
89
590k
Building Adaptive Systems
keathley
39
2.4k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Practical Orchestrator
shlominoach
186
10k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Building an army of robots
kneath
302
45k
Speed Design
sergeychernyshev
25
740
Transcript
1 ࠓͷ”Ͳ͏ॻ͘”ͷ ΞϧΰϦζϜྫ 2019/02/13 #nagoyaphp /39
ʹ͍ͭͯ 2/39
͖ͨͭͪʢ໊͋ͩʣ 3 • (ג)ΧϧςοτίϛϡχέʔγϣϯζCTO • WebΤϯδχΞྺ7ɺPHPྺ7 • #nagoyaphpʊ • #symfony_meetup
/39
͖ͨͭͪʢ໊͋ͩʣ 4 • ͓ख͍ͨ͠ຊʢ2015/12ʣ • Schooߨࢣʢ2018/04ʣ ʮGitHubΛͬͨσϓϩΠࣗಈԽ࣮ફʯ ʮجຊ͔Β͔ͬ͠ΓֶͿ Symfony2ೖʯ /39
ͨ ͭ ͖ ͪ twitter.com/ttskch ͋͞ɺ͋ͳͨࠓ͙͢ϑΥϩʔ͠Α͏!!! શແྉ ·͞ʹ໊ݴػ ਓੜͰେͳ͜ͱɺͯ͢ ͖͔ͨͭͪΒڭΘͬͨ
͖ͨͭͪΛϑΥϩʔͨ͠Β ࠊ௧͕࣏Γ·ͨ͠ 100% φϯτʂ ϑΥϩϫʔ͔Βͷࢧ࣋ 100% ͍ͯ͠Δ ͍ͯ͠ͳ͍ ϑΥϩϫʔ͞Μ100ਓʹฉ͖·ͨ͠ ͖ͨͭͪΛϑΥϩʔ͍ͯ͠Δʁ 5/39
ձࣾʹ͍ͭͯ 6/39
(ג)Χϧςοτίϛϡχέʔγϣϯζ 7 https://quartet-communications.com /39
(ג)Χϧςοτίϛϡχέʔγϣϯζ 8 https://www.google.co.jp/search?q=Χʔςϯ /39
(ג)Χϧςοτίϛϡχέʔγϣϯζ 9 https://lisket.jp /39
We are hiring!ʢϚδͰʣ 10 • PHPer/JSer ઈࢍେืूதʂʢϦϞʔτόΠτՄʣ • Symfony+Angular ͰɺWebࠂۀքΛ
ϗϫΠτʹ͢ΔΈΛ࡞ͬͯ·͢ • ܦӦϏδϣϯʮੈքҰޮతͳཧళʯ /39
We are hiring!ʢϚδͰʣ 11 • ࣗࣾαʔϏεʮLisketʯͰࣗࣾͷۀޮԽ • શࣾһͷฏۉۀ͕࣌ؒ5h/݄͙Β͍Ͱ͢ ಛผड /39
We are hiring!ʢϚδͰʣ 12 ΤϯδχΞͷಇ͖͢͞େࣄʹͯ͠·͢✨ /39
We are hiring!ʢϚδͰʣ 13 ·͓͚ͣͩͰʂؾܰʹ͔͚͍ͯͩ͘͞ /39
14 ࠓͷ”Ͳ͏ॻ͘”ͷ ΞϧΰϦζϜྫ 2019/02/13 #nagoyaphp /39
ͷ༰ 15 http://nabetani.sakura.ne.jp/hena/orde17palin/ /39
$count = 0; for ($i = $min; $i < $max;
$i++) { $number = base_convert(strval($i), 10, $base); if ($number === strrev($number)) { $count++; } } return $count; 16 ࠷ॳʹॻ͍ͨίʔυ ۪ʹ૯ͨΓͰఆ͍ͯͭ͘͠ /39
public function dataProvider() { return [ ['12,34,5', 5], ['10,11,10', 0],
['1,100,3', 18], : : ['66160071,153732445,5', 5605], ['18799557,189007582,14', 33741], ['78547566,225312226,20', 18346], ['143084571,506549072,18', 62323], ['2099642384,2789567569,6', 14787], ]; } 17 ςετέʔε /39
݁Ռ 18 ܭࢉྔ͕େ͖͗ͯ͢λΠϜΞτ… /39
ͪΐͬͱ ಄ΛͬͯΈΔ 19/39
ਓؒͲ͏ͬͯղ͍͍ͯΔ͔ 20 ྫʣ10ਐͷ123ʙ150ͰճจΛ୳͢߹ /39
ਓؒͲ͏ͬͯղ͍͍ͯΔ͔ 20 123 ྫʣ10ਐͷ123ʙ150ͰճจΛ୳͢߹ /39
ਓؒͲ͏ͬͯղ͍͍ͯΔ͔ 20 123 131 ྫʣ10ਐͷ123ʙ150ͰճจΛ୳͢߹ /39
ਓؒͲ͏ͬͯղ͍͍ͯΔ͔ 20 123 131 141 ྫʣ10ਐͷ123ʙ150ͰճจΛ୳͢߹ /39
ਓؒͲ͏ͬͯղ͍͍ͯΔ͔ 20 123 131 141 151 ྫʣ10ਐͷ123ʙ150ͰճจΛ୳͢߹ /39
ਓؒͲ͏ͬͯղ͍͍ͯΔ͔ 20 123 131 141 151 ྫʣ10ਐͷ123ʙ150ͰճจΛ୳͢߹ /39
ਓؒͲ͏ͬͯղ͍͍ͯΔ͔ 20 • 1ͣͭ૿͠ͳ͕Βʮ͜Εճจ͔ʁʯ ͳΜͯͬͯͳ͍ • ճจ͕ࠨӈରশͳ͜ͱΛར༻͍ͯ͠Δ • ࠨΛ1ͣͭ૿͠ͳ͕ΒڸจࣈྻΛ ࡞ͬͯΔ
123 131 141 151 ྫʣ10ਐͷ123ʙ150ͰճจΛ୳͢߹ /39
͍͔ͭ͘ύλʔϯ͕͋Δͳʁ 21 • ܻ͕ۮ͔ح͔ʢ123ͱ1234ʣ • ࠨΛͦͷ··స͢Δ͔ɺ1૿͔ͯ͠Β స͢Δ͔ʢ120→121ͱ123→131ʣ • ࠨΛ1૿ͨ͠ͱ͖ʹܻ͕૿͑Δ͔૿͑ ͳ͍͔ʢ99→101ͱ88→99ʣ
/39
/39 ͍͔ͭ͘ύλʔϯ͕͋Δͳʁ 22 • ܻ͕ۮ͔ح͔ʢ123ͱ1234ʣ • ࠨΛͦͷ··స͢Δ͔ɺ1૿͔ͯ͠Β స͢Δ͔ʢ120→121ͱ123→131ʣ • ࠨΛ1૿ͨ͠ͱ͖ʹܻ͕૿͑Δ͔૿͑
ͳ͍͔ʢ99→101ͱ88→99ʣ
1. ܻ͕ۮ͔ح͔ 23 ࠨ ӈ ճจͷܻ 12 23 3
12 34 4 123 345 5 123 456 6 حܻͷ߹ɺਅΜதͷܻΛࠨӈ྆ํʹؚΊΔ /39
/39 ͍͔ͭ͘ύλʔϯ͕͋Δͳʁ 24 • ܻ͕ۮ͔ح͔ʢ123ͱ1234ʣ • ࠨΛͦͷ··స͢Δ͔ɺ1૿͔ͯ͠Β స͢Δ͔ʢ120→121ͱ123→131ʣ • ࠨΛ1૿ͨ͠ͱ͖ʹܻ͕૿͑Δ͔૿͑
ͳ͍͔ʢ99→101ͱ88→99ʣ
2. ࠨΛ1૿͔͢Ͳ͏͔ 25 ࠨ ӈ ࠨͷస ࣍ͷճจ 10 00
01 101 12 20 21 121 12 21 21 131 12 23 21 131 ӈ >= ࠨͷస ͷͱ͖ࠨΛ1૿͢ < < >= >= /39
͍͔ͭ͘ύλʔϯ͕͋Δͳʁ 26 • ܻ͕ۮ͔ح͔ʢ123ͱ1234ʣ • ࠨΛͦͷ··స͢Δ͔ɺ1૿͔ͯ͠Β స͢Δ͔ʢ120→121ͱ123→131ʣ • ࠨΛ1૿ͨ͠ͱ͖ʹܻ͕૿͑Δ͔૿͑ ͳ͍͔ʢ99→101ͱ88→99ʣ
/39
3. ࠨΛ1૿ܻ͕ͯ͠૿͑Δ͔ 27 1૿ͨ͠ͱ͖ʹࠨͷܻ͕૿͑Δ߹ ճจͷܻݩͷࣈΑΓ૿͑Δ ࠨ 1૿͢ͱ ࣍ͷճจ ճจͷܻ
8 9 99 2 9 10 101 3 19 20 202 3 /39
ίʔυʹͯ͠ΈΔ 28/39
$ tree src src ├── Dokaku14.php └── Palindrome ├── Finder.php
├── Generator.php └── Operator.php 29 Δ͜ͱ͕ෳࡶͳͷͰΫϥε͚ ࣍ͷճจΛݟ͚ͭΔ αʔϏε ʮࠨʯΛݩʹ ճจΛ࡞ΔαʔϏε จࣈྻʹର͢ΔܭࢉΛ αϙʔτ͢ΔαʔϏε /39
30 ݺͼग़͠ݩ͜Μͳײ͡ $count = 0; $current = base_convert(strval($min - 1),
10, $base); while (base_convert($current, $base, 10) < $max) { $current = $this->finder->findNextPalindrome($current, $base); $count++; } $count--; return $count; ࣍ͷճจ·ͰਐΊΔͷͰܭࢉྔେ෯Χοτ /39
public function findNextPalindrome(string $number, int $base): string { list($leftHalf, $rightHalf)
= $this->operator->cutIntoHalf($number); $palindromeLength = strlen($number); if ($this->operator->compare($rightHalf, strrev($leftHalf), $base) >= 0) { $halfLength = strlen($leftHalf); $leftHalf = $this->operator->increment($leftHalf, $base); if (strlen($leftHalf) > $halfLength) { $palindromeLength++; } } return $this->generator->generate($leftHalf, $palindromeLength); } 31 Finderͷ࣮͜Μͳײ͡ /39
ෳࡶʹݟ͑Δ͚Ͳ 32 ͜ΕΒͷॲཧΛ͍ͯ͠Δ͚ͩͰ͢ /39
GeneratorͱOperator 33 • ༰୯७ͳͷͰ͜͜ͰׂѪ͠·͢ ʢGitHubʹ্͕ͬͯΔͷͰݟͯΈ͍ͯͩ͘͞ʣ /39
ಈ͔ͯ͠ΈΔ 34/39
35 υϠΝʂ /39
·ͱΊ 36/39
ΊͬͪΌ಄ͬͯർΕ·ͨ͠ 37 • ͳΜ͔ͩΜͩ·Ͱ͔͔࣌ؒΓ·ͨ͠ • ࢴͷ্Ͱ࣮ݧ͠ͳ͕Βߟ͑Δͷେࣄˣ /39
ιʔεGitHubʹ্͛ͯ·͢✋ 38 https://github.com/ ttskch/nagoyaphp14 /39
39 @ttskch ʘThanks!ʗ /39