Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
数独ではじめるアルゴリズム 第一章 実装と高速化
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ryosuke Uchiyama
September 25, 2020
Programming
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
数独ではじめるアルゴリズム 第一章 実装と高速化
Ryosuke Uchiyama
September 25, 2020
More Decks by Ryosuke Uchiyama
See All by Ryosuke Uchiyama
AWSでサーバレスな書籍管理アプリを作る
step63r
0
68
PythonでSlack通知botを作る
step63r
0
23
ChatGPT実践
step63r
1
400
IoT実践! 行先予定表を電子ペーパーで作る
step63r
0
49
React x Socket.ioで人狼サーバを作る 第一章 フロントエンド実装
step63r
0
33
深層強化学習で東方AI 第一章 DQNの基本
step63r
0
390
Build 2021 プレイバック
step63r
0
44
WPFで実践アプリ開発! 第四章 機能の実装 Part 2
step63r
0
62
WPFで実践アプリ開発! 第三章 機能の実装 Part 1
step63r
0
140
Other Decks in Programming
See All in Programming
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
110
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
18
18k
JRuby: Past, Present, and Future
headius
0
210
Are APIs Still Relevant in the AI Era?
soyuka
0
330
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
200
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
320
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
390
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
560
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
4.4k
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
220
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
980
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.3k
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Utilizing Notion as your number one productivity tool
mfonobong
4
600
Being A Developer After 40
akosma
91
590k
How GitHub (no longer) Works
holman
316
150k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Un-Boring Meetings
codingconduct
0
430
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
530
The Curse of the Amulet
leimatthew05
3
15k
Ethics towards AI in product and experience design
skipperchong
2
400
Transcript
数独ではじめるアルゴリズム 第一章 実装と高速化 Ryosuke Uchiyama step63r
はじめに
数独ってなに? 3✕3✕3のマスに1~9の数字を入れていくペンシルパズル 5 3 7 6 1 9 5 9
8 6 8 6 3 4 8 3 1 7 2 6 6 2 8 4 1 9 5 8 7 9 問題例 5 3 4 6 7 8 9 1 2 6 7 2 1 9 5 3 4 8 1 9 8 3 4 2 5 6 7 8 5 9 7 6 1 4 2 3 4 2 6 8 5 3 7 9 1 7 1 3 9 2 4 8 5 6 9 6 1 5 3 7 2 8 4 2 8 7 4 1 9 6 3 5 3 4 5 2 8 6 1 7 9 解答
手筋1 特定のマスに入る数値を絞る ★ 5 6 7 2 3 4 8
9 • ボックスより (2, 3, 4) は✕ • ヨコより (5, 6, 7) は✕ • タテより (8, 9) は✕ ★に入るのは 1 だけ! A B C 1 2 3 1 2 3 4 5 6 7 8 9
手筋2 特定の数値が入るマスを絞る 1 1 ★ 2 1 • C1の 1
でA1の1行目が潰れる • B1の 1 でA1の2行目が潰れる • A2の 1 でA1の3列目が潰れる 1 が入るのは★だけ! A B C 1 2 3
経緯
その昔……
step63r/NumpreTool02: Resolve NUMPRE (Number Place) automatically.
None
ところが……
None
None
None
_人人人人人人人人人_ > 解答できません <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^ ̄
Software Design 8月号 技術評論社 Software Design 2020年8月号|技術評論社
ここに書かれていることをやってみました
探索アルゴリズム
グラフ構造と深さ優先探索(DFS) 0 1 2 3 4 11 5 8 6
7 9 10 12 13 14
数独の盤面をグラフ化 ※ここでは単純化のため3✕3の盤面で考える 2 3 1 2 1 2 2 3
1 2 2 1 2 2 3 1 3 2 1 2 2 3 1 3 2 1 1 2 2 3 1 3 2 2 1 2 2 3 1 3 2 3 1 2 2 3 1 1 2 1 2 2 3 1 1 2 1 1 2 2 3 1 1 2 2 1 2 2 3 1 1 2 3 1 2 2 3 1 1 2 3 1 1 2 2 3 1 1 2 3 2 1 2 2 3 1 1 2 3 3 1 2
実装してみた SudokuCpp python-sudoku
Demo
高速化
ベンチマーク(Python版) 4 9 2 4 8 2 1 4 6
6 9 4 8 3 1 3 5 6 7 7 5 6 2 6 1 3 5 2 中級クラス 0.6955 秒 2 1 8 4 9 6 3 1 2 7 9 6 4 6 9 3 7 専門級クラス 110.6565 秒 ※Intel Core i7-10700 @2.90 GHz 空きマスが増えるにつれて処理時間が長くなってしまう
改善アプローチ その1 入れられる数字の選択肢が少ないマスから埋めていく その2 一意に決まるマスはあらかじめ埋めておく
入れられる数字の選択肢が少ないマスから埋めていく 3 6 5 4 8 7 9 4 5
1 9 7 3 5 6 8 9 6 5 4 4 6 5 5 6 5 3 5 3 4 5 6 5 3 4 4 4 6 5 5 5 4 4 5 5 5 4 4 5 5 5 4 7 3 3 4 3 4 4 5 6 4 4 5 6 5 4 4 6 4 5 7 7 4 6 7 7 5 6 6 8 問題 入れられる数字の残数 ここから処理するよりも… この辺から処理した方が速い!
一意に決まるマスはあらかじめ埋めておく 3 6 5 4 8 7 9 4 5
1 9 7 3 5 6 8 9 問題 5 8 3 6 5 4 8 7 5 9 4 6 5 9 1 5 9 7 3 5 6 8 5 9 5 前処理後の問題
ベンチマーク比較(Python版) 測定不可(時間かかりすぎ) 1080.966 281.378 5.0795 0 200 400 600 800
1000 1200 対策なし 対策1 対策2 対策1&2 最高級クラスを30問解くのにかかった時間 (秒)
まとめ
たまにはゴリゴリ書くのも楽しいよ!!!!!!!!
今後やること • UI実装(WPFかXamarinあたり) • モバイル対応(iOSアプリをビルドする環境がない……つらたん……) • OCR(問題をカメラで撮ってAzure Cognitive Servicesとかで盤面認識&自動解答) •
マルチスレッド(たぶんやらないやつ)