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
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
phpenv on Mac 難しすぎワロタ
ttskch
0
560
Other Decks in Programming
See All in Programming
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
Arm移行タイムアタック
qnighy
0
300
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
520
Quine, Polyglot, 良いコード
qnighy
4
640
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
subpath importsで始めるモック生活
10tera
0
300
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
40
2.4k
Documentation Writing (for coders)
carmenintech
65
4.4k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Building an army of robots
kneath
302
43k
Facilitating Awesome Meetings
lara
50
6.1k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
4 Signs Your Business is Dying
shpigford
180
21k
Scaling GitHub
holman
458
140k
Optimizing for Happiness
mojombo
376
70k
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