SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
エダカリン!
      @ivoryworks
2011.12.17 gunma.web #7
@ivoryworks

C / Java / PHP / JS / Python
今回のテーマ




枝刈り
枝刈り




 主にツリー状のデータを扱う際、
 メモリや計算時間を節約する手法
不要な枝を刈ってデータを小さくする
   (作らない・削除する)
どうして枝刈りするの?


データを作る人(処理)
データを読む人(処理)

早く作れて早く読める
実は刈らなくてもいい


   無限の時間と
無限のリソースがあるなら

処理もシンプルになる
待ってらんない
話を変えます
実用 R アナグラミング


              2008
             昔つくった
             ローマ字の
            アナグラムを
            つくるサイト
        http://www.ivoryworks.com/anagram/
実用 Perl プログラミング
実用 R アナグラミング



           PHPで書いた
          Perl使ってない
        http://www.ivoryworks.com/anagram/
アナグラム



       言葉遊びの一つ。
単語または文の中の文字をいくつか入れ替えるこ
とによって全く別の意味にさせる遊びである。

    Wikipedia - http://ja.wikipedia.org/wiki/アナグラム
1 + 12 = 2 + 11




one plus twelve = two plus eleven
アナグラミングをローマ字でやる

 元となる文字列を並び替える

  ツリーを作って処理する

    ようするに

      枝
並びパターン




3文字だと6通り
 3x2x1=6
N!
 階乗
3! = 6
EDAKARI-N!
階乗
          2文字:2 x 1 = 2通り
         3文字:3 x 2 x 1 = 6通り
       4文字:4 x 3 x 2 x 1 = 24通り
     5文字:5 x 4 x 3 x 2 x 1 = 120通り
    6文字:6 x 5 x 4 x 3 x 2 x 1 = 720通り
  7文字:7 x 6 x 5 x 4 x 3 x 2 x 1 = 5040通り
8文字:8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 40320通り
              階乗ヤバい!
         ねずみ算式に増えていく
 10文字で3628800通りとか激ヤバだけど事実
3! = 3 x 2 x 1 = 6
10! = 3628800
ローマ字アナグラムを作る処理

1.入力:ローマ字
2.アナグラムツリー生成
3.アナグラムツリーからアナグラムリスト生成
4.アナグラムリストから読み仮名ツリー生成
5.読み仮名ツリーから読み仮名リスト生成
6.出力:アナグラム読み仮名リスト
読み仮名ツリー?




読み仮名は1つでは?
複数の読み方


  兄
 ANI
 安易
ANINAANI
一緒に刈ろうぜ!
  CAPCOM
サンプル



“NEZUMIZAN”
  ねずみざん
NEZUMIZAN



 9文字
NEZUMIZAN



362,880通り
Try-0
何も考えない
16.573249816895 sec.
どれが不要な枝なのか



     不要な枝の判断は
データの特性や内容によって異なる
    作る人や読む人次第
刈り方



枝を作る前に刈る

枝を作ってから刈る
枝を作る前に刈る



    枝を伸ばす前に
不要な枝になることを予測して
   それ以上計算しない
枝を作ってから刈る



  枝を伸ばした後
 不要と判断したら
 枝を逆上って刈る
Cace by Cace
Try-1
同じ計算しない
 (伸ばす前に刈れ)
AKA




同じ色の枝ダブってね?
小さくなった
16.573249816895 sec.
15.555239915848 sec.
Try-2
  途中で見切る1
(伸ばす前に刈れ&伸ばした後刈れ)
伸ばしても無駄な枝



 残りの文字に母音(A,I,U,E,O)
  もしくはNが存在しなければ
枝を伸ばしてもローマ字が成立しない
AKA




青いところローマ字成立してなくね?
もっと小さくなった
16.573249816895 sec.
15.555239915848 sec.
8.3212361335754 sec.
Try-3
  途中で見切る2
(伸ばす前に刈れ&伸ばした後刈れ)
枝を伸ばす際に
  読み仮名変換処理にかけて
既に読めないならその枝いらない
16.573249816895 sec.
15.555239915848 sec.
8.3212361335754 sec.
2.0270299911499 sec.
Try-Final
素早く刈れ
(時間かけるな)
読み仮名変換処理を元に
ローマ字スペルチェッカーを作成
      軽量化
16.573249816895 sec.
15.555239915848 sec.
8.3212361335754 sec.
2.0270299911499 sec.
1.1768751144409 sec!
(362,880通り)
16.573249816895 sec.



1.1768751144409 sec!
    (2,160通り)
よく刈れました
github




              - romaji-anagram -
https://github.com/ivoryworks/romaji-anagram
まとめ


●
 いらない枝は刈ろう
●
 効率良く刈ろう
●
 データが小さくなる
●
 小さなデータは早く作れる
●
 小さなデータは早く扱える
ねずみ算




演算済み
おしまい

Más contenido relacionado

Destacado

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
ThinkNow
 
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
Kurio // The Social Media Age(ncy)
 

Destacado (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...
 

20111217 gunmaweb#7 エダカリン!