Takashi Kanemoto
April 17, 2019
400

# 今日の"どう書く"問題のアルゴリズム例

Nagoya.php #15 補足資料
https://nagoyaphp.connpass.com/event/120856/

April 17, 2019

## Transcript

5. ### ͨ ͭ ͖ ͪ twitter.com/ttskch ͋͞ɺ͋ͳͨ΋ࠓ͙͢ϑΥϩʔ͠Α͏!!! ׬શແྉ ·͞ʹ໊ݴ੡଄ػ ਓੜͰେ੾ͳ͜ͱ͸ɺ͢΂ͯ ͖͔ͨͭͪΒڭΘͬͨ

͖ͨͭͪΛϑΥϩʔͨ͠Β  ࠊ௧͕࣏Γ·ͨ͠ 100% φϯτʂ ϑΥϩϫʔ͔Βͷࢧ࣋཰ 100% ͍ͯ͠Δ ͍ͯ͠ͳ͍ ϑΥϩϫʔ͞Μ100ਓʹฉ͖·ͨ͠ ͖ͨͭͪΛϑΥϩʔ͍ͯ͠Δʁ

10. ### We are hiring!ʢϚδͰʣ • PHPer/JSer ઈࢍେืूதʂʢϦϞʔτ΍όΠτ΋Մʣ • Symfony+Angular ͰɺWeb޿ࠂۀքΛ  ϗϫΠτʹ͢Δ࢓૊ΈΛ࡞ͬͯ·͢

• ܦӦϏδϣϯ͸ʮੈքҰޮ཰తͳ୅ཧళʯ

= 2
23. ### 3 5 4 4 1 2 3 2 2 +

3 = 5 3 -1 = 2

= 1
26. ### 3 5 4 4 1 2 3 2 1 +

3 = 4 2 -1 = 1

3

6 3 + 2= 5

32 128

25 27

25 27
38. ### 21 23 24 26 1 2 3 2 20 22

25 27 ൪߸Λ2ͷྦྷ৐Ͱද͢ͱࢦ਺෦ͷࠩͰڑ཭ΛٻΊΒΕΔ

1 20 27

42. ### 2 8 16 64 165 Λ 1 + 4 +

32 + 128 ʹ෼ղ͍ͨ͠ 1 4 32 128

45. ### 165 = 27x1 + 26x0 + 25x1 + 24x0 +

23x0 + 22x1 + 21x0 + 20x1 21 23 24 26 20 22 25 27

27

49. ### 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); }
50. ### 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] ͱͳΔɻ͜Ε͕࣮ઢͷҐஔɻ ೖྗͷύʔε
51. ### 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 ͕௖఺਺ɻ ௖఺਺ͷܭࢉ