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
510
今日の"どう書く"問題のアルゴリズム例
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
今年書いた技術記事で伸びたやつの自慢と自分の中では力作なのにさっぱり伸びなかったやつの供養 / My Tech Articles 2024
ttskch
0
28
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
47
29k
データベース/SQL超入門!完全初心者向けに世界一分かりやすく解説します
ttskch
1
4.5k
Symfony UX Autocompleteとかいう 顧客が本当に必要だったもの
ttskch
0
1.8k
就活生あるいは新人エンジニアさんへのお節介なアドバイス
ttskch
0
1.5k
symfony/pantherでWordleを解いてみた
ttskch
0
270
ついに、Webアプリでの帳票印刷のベストプラクティスを編み出しました💡
ttskch
16
19k
phpenvやめました🤦♂️
ttskch
0
1.3k
PHPでCSVのインポート/エクスポートに立ち向かう
ttskch
1
2.2k
Other Decks in Programming
See All in Programming
Realtime API 入門
riofujimon
0
150
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
900
CSC509 Lecture 09
javiergs
PRO
0
140
Ethereum_.pdf
nekomatu
0
460
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
A Tale of Four Properties
chriscoyier
156
23k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Six Lessons from altMBA
skipperchong
27
3.5k
Speed Design
sergeychernyshev
25
620
Writing Fast Ruby
sferik
627
61k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Producing Creativity
orderedlist
PRO
341
39k
Documentation Writing (for coders)
carmenintech
65
4.4k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
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