SlideShare a Scribd company logo
LL Quiz解答 
LL Diver @ 日本科学未来館 
LL Quiz Team
LL Quizについて 
● 今年で3年目 
– 毎々お世話になっております 
● 参加者に問題を出題(llquiz-2014.appspot.com) 
– ご参加ありがとうございました 
● LTで簡単に解答紹介 
– 詳細はLL Diver公式サイトで解説
今年のテーマ 
LL Diver 
↓ 
潜る 
↓ 
Depth First Search(DFS)
DFS 
http://upload.wikimedia.org/wikipedia/commons/2/2c/Depthfirst.png より引用
問題1 
● 巡回セールスマン問題 
– 10個の都市があって、どういう順番で回ると最 
短? 
● 今回の問題では、最初の都市は指定 
● 想定解 
– DFS 
– permutation(順列組合せ) 
● NP困難だけど都市数少ないので大丈夫
解答1(DFS) 
これから探索する都市 
これまで探索した都市 
def visit(cost, cur_pos, visited=[cur_pos]) 
return if $max_cost < cost 
cands = $positions - visited 
if cands.empty? 
puts [cost, visited.map{ |i| $str[i] }.join('') ] 
$max_cost = cost 
return 
end 
cands.each do |cand| 
visit(cost+$data[cur_pos][cand], cand, visited+[cand]) 
end 
end 
全都市探索したら= 
一番深い場所にいたら 
これ以上探索しない 
一番深い場所にいないなら 
順に次の場所を探索
解答2(permutation) 
my @ary=(1..9); 
my $p=Math::Permute::Array->new(@ary); 
my $md; 
for my $i (0..$p->cardinal()-1) { 
my @p=@{$p->permutation($i)}; 
my $from=0; 
my $d=0; 
for my $to (@p) { 
$d+=$map[$from][$to]; 
$from=$to; 
} 
if (!defined($md)||$d<$md) { 
$md=$d; 
@c=@p; 
} 
} 
print join(' ', map {$d[$_]} (0, @c)), "n"; 
9!=362880通り 
全順列組合せを列挙
問題2 
● N-Kings 
● チェスのKingの置き方は何通り? 
– あらかじめ盤面にいくつかKingが置いてあって、 
追加でいくつか置く 
– すでに置いてあるKingの上下左右斜め1マスには、 
Kingをおけない 
● 想定解 
– DFS 
– (Dynamic Programming)(省略)
解答1 
def countPattern(pos,max,board) 
c = 0 
p = pos 
while p < max 
posx = p % board.size 
posy = p / board.size 
if canSet(posx,posy,board) 
c += 1 
b = [] 
board.each{|a|b.push(a.clone) } 
b[posy][posx] = "1" 
c += countPattern(p,max,b) 
end 
p += 1 
end 
c 
end 
これから探索する場所 
これまで探索した 
結果の盤面 
盤面を1マスずつ探索 
Kingが置ける場所なら 
Kingを置いた盤面を 
再帰的に探索
解答の傾向 
問題1 問題2 sum 
Perl 2 2 4 
Ruby 3 2 5 
Python 1 0 1
来年に向けて 
● もっと解答してもらえる問題を 
– 問題1: いろんな言語でpermutationを想定していた 
● 思い返してみるとpermutationはmajorでない 
● ネタ尽きつつあるんですorz 
– ある程度使われていて、言語ごとの特色が出る処理
おしまい 
ありがとうございました 
m(__)m
問題1の正解について 
● PALINDROME(回文) 
● 最短距離: 1991 
– 1991.to_s(16) => '7c7'
その他 
● 今回のサーバはGAE利用 
– 無料枠で行けました 
– 当分、openしてます

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

LL Quiz LT @ LL Diver