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
April 17, 2019
Programming
480
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
今日の"どう書く"問題のアルゴリズム例
Nagoya.php #15 補足資料
https://nagoyaphp.connpass.com/event/120856/
Takashi Kanemoto
April 17, 2019
More Decks by Takashi Kanemoto
See All by Takashi Kanemoto
API Platformを活用したPHPによる本格的なWeb API開発 / api-platform-book-intro
ttskch
2
240
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
5
1.4k
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
570
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
1.3k
今年書いた技術記事で伸びたやつの自慢と自分の中では力作なのにさっぱり伸びなかったやつの供養 / My Tech Articles 2024
ttskch
2
210
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
48
44k
データベース/SQL超入門!完全初心者向けに世界一分かりやすく解説します
ttskch
2
8.2k
Symfony UX Autocompleteとかいう 顧客が本当に必要だったもの
ttskch
0
2.3k
就活生あるいは新人エンジニアさんへのお節介なアドバイス
ttskch
0
1.7k
Other Decks in Programming
See All in Programming
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
230
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
130
Lessons from Spec-Driven Development
simas
PRO
0
220
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
190
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.6k
スマートグラスで並列バイブコーディング
hyshu
0
260
Inside Stream API
skrb
1
800
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
270
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
14
5.9k
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
150
Featured
See All Featured
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
Abbi's Birthday
coloredviolet
3
8.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
GitHub's CSS Performance
jonrohan
1033
470k
From π to Pie charts
rasagy
0
220
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
The SEO Collaboration Effect
kristinabergwall1
1
490
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
4 Signs Your Business is Dying
shpigford
187
22k
WCS-LA-2024
lcolladotor
0
660
Transcript
ࠓͷ”Ͳ͏ॻ͘”ͷ ΞϧΰϦζϜྫ 2019/04/17 #nagoyaphp @ttskch
ʹ͍ͭͯ
͖ͨͭͪʢ໊͋ͩʣ • (ג)ΧϧςοτίϛϡχέʔγϣϯζCTO • WebΤϯδχΞྺ7ɺPHPྺ7 • #nagoyaphpʊ • #symfony_meetup
͖ͨͭͪʢ໊͋ͩʣ • ͓ख͍ͨ͠ຊʢ2015/12ʣ • Schooߨࢣʢ2018/04ʣ ʮGitHubΛͬͨσϓϩΠࣗಈԽ࣮ફʯ ʮجຊ͔Β͔ͬ͠ΓֶͿ Symfony2ೖʯ
ͨ ͭ ͖ ͪ twitter.com/ttskch ͋͞ɺ͋ͳͨࠓ͙͢ϑΥϩʔ͠Α͏!!! શແྉ ·͞ʹ໊ݴػ ਓੜͰେͳ͜ͱɺͯ͢ ͖͔ͨͭͪΒڭΘͬͨ
͖ͨͭͪΛϑΥϩʔͨ͠Β ࠊ௧͕࣏Γ·ͨ͠ 100% φϯτʂ ϑΥϩϫʔ͔Βͷࢧ࣋ 100% ͍ͯ͠Δ ͍ͯ͠ͳ͍ ϑΥϩϫʔ͞Μ100ਓʹฉ͖·ͨ͠ ͖ͨͭͪΛϑΥϩʔ͍ͯ͠Δʁ
ձࣾʹ͍ͭͯ
(ג)Χϧςοτίϛϡχέʔγϣϯζ https://quartet-communications.com
(ג)Χϧςοτίϛϡχέʔγϣϯζ https://www.google.co.jp/search?q=Χʔςϯ
(ג)Χϧςοτίϛϡχέʔγϣϯζ https://lisket.jp
We are hiring!ʢϚδͰʣ • PHPer/JSer ઈࢍେืूதʂʢϦϞʔτόΠτՄʣ • Symfony+Angular ͰɺWebࠂۀքΛ ϗϫΠτʹ͢ΔΈΛ࡞ͬͯ·͢
• ܦӦϏδϣϯʮੈքҰޮతͳཧళʯ
We are hiring!ʢϚδͰʣ • ࣗࣾαʔϏεʮLisketʯͰࣗࣾͷۀޮԽ • શࣾһͷฏۉۀ͕࣌ؒ5h/݄͙Β͍Ͱ͢ ಛผड
We are hiring!ʢϚδͰʣ ΤϯδχΞͷಇ͖͢͞େࣄʹͯ͠·͢✨
We are hiring!ʢϚδͰʣ ·͓͚ͣͩͰʂؾܰʹ͔͚͍ͯͩ͘͞
ࠓͷ”Ͳ͏ॻ͘”ͷ ΞϧΰϦζϜྫ 2019/04/17 #nagoyaphp @ttskch
http://nabetani.sakura.ne.jp/hena/ordf04octsp/
ͷٻΊํ
1 2 4 8 16 32 64 128
3 5 4 4
3 5 4 4 1 2 3 2
1 2 3 2 3 5 4 4 ؔͯͦ͠͏
3 5 4 4 1 2 3 2
3 5 4 4 1 2 3 2 3 -1
= 2
3 5 4 4 1 2 3 2 2 +
3 = 5 3 -1 = 2
3 5 4 4 1 2 3 2
3 5 4 4 1 2 3 2 2 -1
= 1
3 5 4 4 1 2 3 2 1 +
3 = 4 2 -1 = 1
3 5 4 4 ࣮ઢؒͷڑ͔ΒٻΊΒΕΔ
5
5 4
5 4 4 -1 = 3
5 4 3 + 3 = 6 4 -1 =
3
5 4 4 -1 = 3 3 + 3 =
6 3 + 2= 5
5 4 ڑ͕4ͷͱ͖͚ͩܭࢉํ๏͕มΘΔ
1 2 4 8 16 32 64 128
2 8 16 64 1 2 3 2 1 4
32 128
21 23 24 26 1 2 3 2 20 22
25 27
21 23 24 26 1 2 3 2 20 22
25 27
21 23 24 26 1 2 3 2 20 22
25 27 ൪߸Λ2ͷྦྷͰද͢ͱࢦ෦ͷࠩͰڑΛٻΊΒΕΔ
21 23 24 26 2 3 2 22 25 Ұप͢Δͱۙͮ͘ߏͳͷͰ8ͷ༨Λ͑Αͦ͞͏✋
1 20 27
ೖྗͷύʔε
1 2 4 8 16 32 64 128
2 8 16 64 165 Λ 1 + 4 +
32 + 128 ʹղ͍ͨ͠ 1 4 32 128
2 8 16 64 1 4 32 128
21 23 24 26 20 22 25 27
165 = 27x1 + 26x0 + 25x1 + 24x0 +
23x0 + 22x1 + 21x0 + 20x1 21 23 24 26 20 22 25 27
165 = b10100101 21 23 24 26 20 22 25
27
21 23 24 26 20 22 25 27 ೖྗΛ2ਐͰද͢ͱɺ͕1ͷܻ͕࣮ઢͷҐஔΛࣔ͢
࣮ྫ
public function run(string $input): string { $lines = array_values(array_filter(range(0, 7),
function (int $i) use ($input) { return str_split(sprintf('%b', $input))[$i] ?? false; })); $vertices = []; for ($i = 0; $i < count($lines); $i++) { $distance = ($lines[($i + 1) % count($lines)] - $lines[$i] + 8) % 8; $vertices[] = ($distance === 4 ? 2 : 3) + $distance - 1; } sort($vertices); return implode('', $vertices); }
public function run(string $input): string { $lines = array_values(array_filter(range(0, 7),
function (int $i) use ($input) { return str_split(sprintf('%b', $input))[$i] ?? false; })); $vertices = []; for ($i = 0; $i < count($lines); $i++) { $distance = ($lines[($i + 1) % count($lines)] - $lines[$i] + 8) % 8; $vertices[] = ($distance === 4 ? 2 : 3) + $distance - 1; } sort($vertices); return implode('', $vertices); } ೖྗΛ2ਐʹมͯ͠ɺཱ͍ͬͯΔϏοτͷҐஔʢ0ʙ7ʣΛྻʹ͢Δɻ ྫͷ߹ $lines === [0, 2, 5, 7] ͱͳΔɻ͜Ε͕࣮ઢͷҐஔɻ ೖྗͷύʔε
public function run(string $input): string { $lines = array_values(array_filter(range(0, 7),
function (int $i) use ($input) { return str_split(sprintf('%b', $input))[$i] ?? false; })); $vertices = []; for ($i = 0; $i < count($lines); $i++) { $distance = ($lines[($i + 1) % count($lines)] - $lines[$i] + 8) % 8; $vertices[] = ($distance === 4 ? 2 : 3) + $distance - 1; } sort($vertices); return implode('', $vertices); } [0, 2, 5, 7] ͱ͍͏ྻʹରͯ͠ɺཁૉؒͷ͔ࠩΒ࣮ઢؒͷڑΛٻΊΔͱɺ (2-0+8)%8=2, (5-2+8)%8=3, (7-5+8)%8=2, (0-7+8)%8=1 ͱͳΔɻ ڑ͕4ͷ߹ 2+ڑ-1 ͕ɺڑ͕ͦΕҎ֎ͷ߹ 3+ڑ-1 ͕ɻ ͷܭࢉ
https://github.com/ ttskch/nagoyaphp15
@ttskch ʘThanks!ʗ