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
520
今日の"どう書く"問題のアルゴリズム例
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
2
69
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
47
31k
データベース/SQL超入門!完全初心者向けに世界一分かりやすく解説します
ttskch
1
4.7k
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.4k
PHPでCSVのインポート/エクスポートに立ち向かう
ttskch
1
2.2k
Other Decks in Programming
See All in Programming
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
670
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Haze - Real time background blurring
chrisbanes
1
500
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
42 best practices for Symfony, a decade later
tucksaun
1
180
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
命名をリントする
chiroruxx
1
380
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
CSC305 Lecture 26
javiergs
PRO
0
140
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Fireside Chat
paigeccino
34
3.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Designing for Performance
lara
604
68k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
The Cult of Friendly URLs
andyhume
78
6.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
4 Signs Your Business is Dying
shpigford
181
21k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
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