SlideShare uma empresa Scribd logo
1 de 49
MCMXCIX (1999)

   2012.05.10 GenesisLightningTalks
    SAWADA Tadashi a.k.a. @cesare
こんにちは
沢田正
@cesare
さっそくですが
お題
自然数→ローマ数字
    変換
roman(3)
  → "III"
roman(1999)
→ "MCMXCIX"
ローマ数字
•1 → I      • 6 → VI
• 2 → II    • 7 → VII
• 3 → III   • 8 → VIII
• 4 → IV    • 9 → IX
•5 → V
• 10 → X     • 60 → LX
• 20 → XX    • 70 → LXX
• 30 → XXX   • 80 → LXXX
• 40 → XL    • 90 → XC
• 50 → L
•1 → I     • 100 → C
•5 → V     • 500 → D
• 10 → X   • 1000 → M
• 50 → L
よくある間違い


•IC → 99

• IM → 999
変換アルゴリズムを
 考えてください
   (3分)
条件


•1 ∼ 3999

• IIII はナシ
•1 → I     • 100 → C
•5 → V     • 500 → D
• 10 → X   • 1000 → M
• 50 → L
gist.github.com/2586858
解決編
ポイント

•分割して統治せよ

•どの桁の変換もパターンは同じ
•低い方から計算すると楽
ポイント1

•分割して統治せよ

•どの桁の変換もパターンは同じ
•低い方から計算すると楽
123

1 2  3
C XX III
2089

2  0 8     9
MM   LXXX IX
•
ある桁の変換は
他の桁に依存しない

•
0 は空文字列に
変換すればOK
戦略1


•   数値を桁ごとに分解する
ポイント2

•分割して統治せよ

•どの桁の変換もパターンは同じ
•低い方から計算すると楽
•0 →        •5 → V
•1 → I      • 6 → VI
• 2 → II    • 7 → VII
• 3 → III   • 8 → VIII
• 4 → IV    • 9 → IX
•0 →        •5 → L
•1 → X      • 6 → LX
• 2 → XX    • 7 → LXX
• 3 → XXX   • 8 → LXXX
• 4 → XL    • 9 → XC
•0 →        •5 → D
•1 → C      • 6 → DC
• 2 → CC    • 7 → DCC
• 3 → CCC   • 8 → DCCC
• 4 → CD    • 9 → CM
戦略2


•変換関数は共通にできそう

•桁ごとの文字を変えればOK
ポイント3

•分割して統治せよ

•どの桁の変換もパターンは同じ
•低い方から計算すると楽
高い方の桁から
 計算すると、
123 → [ 1, 2, 3 ]
     最初の要素は何の桁?
逆にする
123 → [ 3, 2, 1 ]


•3 → 1の桁
• 2 → 10の桁

•1 → 100の桁
1234 → [ 4, 3, 2, 1 ]

• 4 → 1の桁

• 3 → 10の桁

• 2 → 100の桁

• 1 → 1000の桁
戦略3


•数値の各桁を逆順に並べる
•変換関数を低い方から順に使う
変換手順

•数値を桁ごとに分解して逆順にする
•桁ごとに変換する
•変換結果を逆順に直す
•文字を連結する
計算例
1999
→ [ 9, 9, 9, 1 ]
→ [ IX, XC, CM, M ]
→ [ M, CM, XC, IX ]
→ MCMXCIX
コード例


• gist.github.com/2586858
• github.com/cesare/roman-numeric
おまけ
Common Lisp の
    場合
(format nil "~@r" 1234)
; => "MCCXXXIV"
Lisp 恐るべし
((((;゚Д゚))))
One More Thing お題...
懇親会にて:)
以上、
ご清聴ありがとう
 ございました
end

Mais conteúdo relacionado

Destaque

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
 

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

MCMXCIX (1999)

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. 4,000 以上の数は表現できない。\n
  13. 100 の前に置けるのは 10 だけ。\n1000 の前に置けるのは 100 だけ。\n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. 100 + 20 + 3 に分ける\n\n
  22. \n
  23. \n
  24. \n
  25. \n
  26. 1の桁\nI V X\n
  27. 10の桁\nX L C\n
  28. 100の桁\nC D M\n文字が違うだけで、並べ方のパターンは共通。\n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. 1番目の要素は1の桁\n2番目の要素は10の桁\n3番目の要素は100の桁\n\n
  35. 何番目の要素は何の桁なのか、が固定になっている。\n計算しやすい。\n
  36. \n
  37. \n
  38. \n
  39. \n
  40. 後で Twitter に流す\n
  41. \n
  42. \n
  43. (format) は C で言うところの printf()\n\n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n