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

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

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

8e844e43f029ec38e206a464cf4587b3?s=128

Takashi Kanemoto

April 17, 2019
Tweet

Transcript

  1. ࠓ೔ͷ”Ͳ͏ॻ͘”໰୊ͷ ΞϧΰϦζϜྫ 2019/04/17 #nagoyaphp @ttskch

  2. ๻ʹ͍ͭͯ

  3. ͖ͨͭͪʢ໊͋ͩʣ • (ג)ΧϧςοτίϛϡχέʔγϣϯζCTO • WebΤϯδχΞྺ7೥ɺPHPྺ7೥ • #nagoyaphpʊ • #symfony_meetup

  4. ͖ͨͭͪʢ໊͋ͩʣ • ͓ख఻͍ͨ͠ຊʢ2015/12ʣ • Schooߨࢣʢ2018/04ʣ ʮGitHubΛ࢖ͬͨσϓϩΠࣗಈԽ࣮ફʯ ʮجຊ͔Β͔ͬ͠ΓֶͿ Symfony2ೖ໳ʯ

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

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

  7. (ג)Χϧςοτίϛϡχέʔγϣϯζ https://quartet-communications.com

  8. (ג)Χϧςοτίϛϡχέʔγϣϯζ https://www.google.co.jp/search?q=Χʔςϯ

  9. (ג)Χϧςοτίϛϡχέʔγϣϯζ https://lisket.jp

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

    • ܦӦϏδϣϯ͸ʮੈքҰޮ཰తͳ୅ཧళʯ
  11. We are hiring!ʢϚδͰʣ • ࣗࣾαʔϏεʮLisketʯͰࣗࣾͷۀ຿΋ޮ཰Խ • શࣾһͷฏۉ࢒ۀ͕࣌ؒ5h/݄͙Β͍Ͱ͢ ಛผ৆ड৆

  12. We are hiring!ʢϚδͰʣ ΤϯδχΞͷಇ͖΍͢͞௒େࣄʹͯ͠·͢✨

  13. We are hiring!ʢϚδͰʣ ·ͣ͸͓࿩͚ͩͰ΋ʂؾܰʹ੠͔͚͍ͯͩ͘͞

  14. ࠓ೔ͷ”Ͳ͏ॻ͘”໰୊ͷ ΞϧΰϦζϜྫ 2019/04/17 #nagoyaphp @ttskch

  15. http://nabetani.sakura.ne.jp/hena/ordf04octsp/

  16. ௖఺਺ͷٻΊํ

  17. 1 2 4 8 16 32 64 128

  18. 3 5 4 4

  19. 3 5 4 4 1 2 3 2

  20. 1 2 3 2 3 5 4 4 ؔ܎ͯͦ͠͏

  21. 3 5 4 4 1 2 3 2

  22. 3 5 4 4 1 2 3 2 3 -1

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

    3 = 5 3 -1 = 2
  24. 3 5 4 4 1 2 3 2

  25. 3 5 4 4 1 2 3 2 2 -1

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

    3 = 4 2 -1 = 1
  27. 3 5 4 4 ࣮ઢؒͷڑ཭͔Β௖఺਺͸ٻΊΒΕΔ

  28. 5

  29. 5 4

  30. 5 4 4 -1 = 3

  31. 5 4 3 + 3 = 6 4 -1 =

    3
  32. 5 4 4 -1 = 3 3 + 3 =

    6 3 + 2= 5
  33. 5 4 ڑ཭͕4ͷͱ͖͚ͩܭࢉํ๏͕มΘΔ

  34. 1 2 4 8 16 32 64 128

  35. 2 8 16 64 1 2 3 2 1 4

    32 128
  36. 21 23 24 26 1 2 3 2 20 22

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

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

    25 27 ൪߸Λ2ͷྦྷ৐Ͱද͢ͱࢦ਺෦ͷࠩͰڑ཭ΛٻΊΒΕΔ
  39. 21 23 24 26 2 3 2 22 25 Ұप͢Δͱۙͮ͘ߏ଄ͳͷͰ8ͷ৒༨Λ࢖͑͹Αͦ͞͏✋

    1 20 27
  40. ೖྗͷύʔε

  41. 1 2 4 8 16 32 64 128

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

    32 + 128 ʹ෼ղ͍ͨ͠ 1 4 32 128
  43. 2 8 16 64 1 4 32 128

  44. 21 23 24 26 20 22 25 27

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

    23x0 + 22x1 + 21x0 + 20x1 21 23 24 26 20 22 25 27
  46. 165 = b10100101 21 23 24 26 20 22 25

    27
  47. 21 23 24 26 20 22 25 27 ೖྗΛ2ਐ਺Ͱද͢ͱɺ஋͕1ͷܻ͕࣮ઢͷҐஔΛࣔ͢

  48. ࣮૷ྫ

  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 ͕௖఺਺ɻ ௖఺਺ͷܭࢉ
  52. https://github.com/ ttskch/nagoyaphp15

  53. @ttskch ʘThanks!ʗ