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
490
今日の"どう書く"問題のアルゴリズム例
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
26k
データベース/SQL超入門!完全初心者向けに世界一分かりやすく解説します
ttskch
1
4.1k
Symfony UX Autocompleteとかいう 顧客が本当に必要だったもの
ttskch
0
1.7k
就活生あるいは新人エンジニアさんへのお節介なアドバイス
ttskch
0
1.4k
symfony/pantherでWordleを解いてみた
ttskch
0
240
ついに、Webアプリでの帳票印刷のベストプラクティスを編み出しました💡
ttskch
16
19k
phpenvやめました🤦♂️
ttskch
0
1.1k
PHPでCSVのインポート/エクスポートに立ち向かう
ttskch
1
2.1k
phpenv on Mac 難しすぎワロタ
ttskch
0
530
Other Decks in Programming
See All in Programming
Rustではじめる負荷試験
skanehira
5
1.2k
Lessons by WebAssembly app in production on CDN Edge Computing Service
tetsuharuohzeki
0
170
Scala におけるコンパイラエラーとの付き合い方
chencmd
2
410
Amebaチョイス立ち上げの裏側 ~依存システムとの闘い~
daichi_igarashi
0
230
Web技術を駆使してユーザーの画面を「録画」する
yukukotani
13
6.5k
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
260
rails_girls_is_my_gate_to_join_the_ruby_commuinty
maimux2x
0
190
Method Swizzlingを行うライブラリにおけるマルチモジュール設計
yoshikma
0
110
メモリ最適化を究める!iOSアプリ開発における5つの重要なポイント
yhirakawa333
0
410
Debugging: All you need to know (for simultaneous interpreting)
jmatsu
2
600
What is Parser
yui_knk
9
4.1k
dRuby 入門者によるあなたの身近にあるdRuby 入門
makicamel
4
350
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
125
16k
Building a Scalable Design System with Sketch
lauravandoore
458
32k
Making Projects Easy
brettharned
113
5.8k
Typedesign – Prime Four
hannesfritz
39
2.3k
The Art of Programming - Codeland 2020
erikaheidi
48
13k
BBQ
matthewcrist
83
9.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
190
16k
YesSQL, Process and Tooling at Scale
rocio
167
14k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
157
15k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
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