Home

CheckIO Homeの問題和訳
問題ページのうち, 問題の前提となる小話は訳してません.
また各問題ページ下部にある「Precondition」は「前提条件」のため訳しません(数値の範囲などだけなので).


Non-Unique Elements

Trim an array down to its non-unique elements

You are given a non-empty list of integers (X). For this task, you should return a list consisting of only the non-unique elements in this list.
To do so you will need to remove all unique elements (elements which are contained in a given list only once).
When solving this task, do not change the order of the list.
Example: [1, 2, 3, 1, 3] 1 and 3 non-unique elements and result will be [1, 3, 1, 3].

Input: A list of integers.
Output: The list of integers.

How it is used:
This mission will help you to understand how to manipulate arrays, something that is the basis for solving more complex tasks.
The concept can be easily generalized for real world tasks. For example: if you need to clarify statistics by removing low frequency elements (noise).

あなたに空でない整数のリストが与えられる. このタスクでは, あなたはこのリスト内の重複要素だけから成るリストを返す.
解くためには, あなたは全てのユニークな(与えられたリストにただ1つだけ含まれる)要素を削除する必要がある.
このタスクを解いているとき, リストの順序は変えてはならない.
例: [1, 2, 3, 1, 3]では1と3が重複要素なので, 結果は[1, 3, 1, 3]となる.

入力: ある整数のリスト
出力: 整数のリスト

備考
このミッションはあなたに配列操作の方法を理解させる手助けとなり, 更に複雑なタスクを解くときの基本となるだろう.
この問題のコンセプトは現実世界のタスクを容易に一般化させることができる. たとえば, もしあなたが綺麗な統計を必要とするなら, 頻度の小さな要素(ノイズ)を取り除くことによって得られる.

Median

Find the mathematical median in a list of numbers

A median is a numerical value separating the upper half of a list of numbers from the lower half.
In a list where there are an odd number of entities, the median is the number found in the middle of the list.
If the list contains an even number of entities, then there is no single middle value, instead the median becomes the average of the two numbers found in the middle.
For this mission, you are given a non-empty list of natural numbers (X). With it, you must separate the upper half of the numbers from the lower half and find the median.

Input: A list of integers.
Output: The median, a float.

How it is used:
The median has usage for Statistics and Probability theory, it has especially significant value for skewed distribution.
For example: we want to know average wealth of people from a set of data -- 100 people earn $100 in month and 10 people earn $1,000,000.
If we average it out, we get $91,000. This is weird value and does nothing to show us the real picture. In this case the median would give to us more useful value and a better picture.

メディアン(中央値)は舌半分からの数と, 上半分の数を分ける数値である.
奇数個からなるリストの場合, メディアンはリストの中央にある値である.
もしリストが偶数個からなる場合は, 中央の値は1つではない, 代わりに中央の2つの値の平均をメディアンとする.
このミッションでは, あなたに空でない自然数のリストが与えられる.

入力:整数のリスト
出力:メディアン(floatで)

備考
メディアンは統計と確率の定理で利用され, 歪んだ分布を特に表す値である.
たとえば, 私たちはあるデータの集合, 100人が1ヶ月に$100稼ぎ, 10人が1ヶ月に$1,000,000稼ぐ, から人々の富の平均を知りたい.
もし私たちがその平均を出せば, それは$91,000になる. これは異様な値で, 私たちに現実を見せようとしない. この場合, メディアンは私たちに有用な値と, よりよい見通しを与える.

House password

Check the strength of your favorite password

Help Nikola develop a password security check module for Sofia.
The password will be considered strong enough if its length is greater than or equal to 10 symbols, it has at least one digit, as well as containing one uppercase letter and one lowercase letter in it.

Input data: A string that is a password (Unicode for python 2.7).
Output data: The output will be true if the password is safe, a boolean or any data type that can be converted and processed as a boolean. In the results you will see the converted results.

How it is used:
If you are worried about the security of your app or service, you can check your users' passwords for complexity.
You can use these skills to require that your users passwords meet more conditions (punctuations or unicode).

ニコラがソフィアのためにパスワードのセキュリティをチェックするモジュールを開発するのを助けてあげよう.
パスワードは10文字以上で, 最低でも1文字以上は数値, 小文字と大文字両方を含んでいれば, 強固だとみなす.

入力:パスワードの文字列(python2.7のunicode文字列)
出力:パスワードが安全ならTrue, そうでないならFalse

備考
もしあなたが自分で作成したアプリケーションやサービスについて心配なら, あなたはユーザーのパスワードを複雑なものかどうかチェックできる.
あなたはより多くの条件(記号やUnicode)を満たすパスワードを必要とするために, これらのスキルを使うことができる.

The Most Wanted Letter

Find out which is the most wanted letter

You are given a text, which contains different english letters and punctuation symbols.
You should find the most frequent letter in the text. The letter returned must be in lower case.
While checking for the most wanted letter, casing does not matter, so for the purpose of your search, "A" == "a". Make sure you do not count punctuation symbols, digits and whitespaces, only letters.
If you have two or more letters with the same frequency, then return the letter which comes first in the latin alphabet.
For example -- "one" contains "o", "n", "e" only once for each, thus we choose "e".

Input: A text for analysis. A string (unicode for py2.7).
Output: The most frequent letter in lower case. A string.

How it is used:
For most decryption tasks you need to know the frequency of occurrence for various letters in a section of text.
For example: we can easily crack a simple addition or substitution cipher if we know the frequency in which letters appear.
This is interesting stuff for language experts!

あなたに文字と記号からなる異なる英語を含むテキストが与えられる.
あなたはテキスト内の最頻文字(最も出現する文字)を見つけ出し, その文字の小文字を返すようにする.
文字をチェックしている間, 検索の目的のために, 大文字小文字は区別しない("A" == "a"). もちろん記号や数字, 空白もカウントしない, 文字だけだ.
もしあなたが同じ頻度の文字を2つ以上得たなら, アルファベット順に最初に来るほうの文字を返す.
たとえば, "one"は"o"と"n"と"e"を含んでおり, それぞれが1回ずつ出現する, よって私たちは"e"を選ぶ.

入力:分析のためのテキスト. ある文字列(python2.7のunicode)
出力:最も出現頻度の高い小文字. 文字列で.

備考
大抵の暗号解読のために, あなたはテキストのセクションに存在する様々な文字の頻度を知る必要がある.
たとえば, 私たちは出現した文字の頻度を知れば, 単純な暗号を簡単にクラックすることができる.
これは言語学者にとって興味深いことだ.

※訳注
シーザー暗号のような平文と暗号文が1:1の写像で変換される場合, 暗号文の文字の頻度を数えて, 高い頻度のものを母音(特に"e")と推定して暗号を解く古典的な手法のことを応用例であげていると思われる.

Xs and Os Referee

Referee Tic-Tac-toe game

Tic-Tac-Toe, sometimes also known as Xs and Os, is a game for two players (X and O) who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three respective marks in a horizontal, vertical, or diagonal rows (NW-SE and NE-SW) wins the game.
But we will not be playing this game. You will be the referee for this games results. You are given a result of a game and you must determine if the game ends in a win or a draw as well as who will be the winner.
Make sure to return "X" if the X-player wins and "O" if the O-player wins. If the game is a draw, return "D."

Input: A game's result. A list of strings (Unicode).
Output: "X", "O" or "D". A string.

How it is used:
The concepts in this task will help you when iterating data types. They can also used in game algorithms, allowing you to know how to check results.

Tic-Tac-Toe(三目並べ, ○×ゲーム)はXとOの2人のプレイヤーが3×3のマスに交互にマークをつけるゲームとして知られている. プレイヤーが勝利するには, 水平, 垂直, もしくは斜めに3つのマークを置く.
私たちはこのゲームを遊ぶわけではない. あなたはこのゲームの審判となる. あなたにはゲームの結果が与えられ, 誰が勝利したかまたはドローかを決定する必要がある.
Xプレイヤーが勝利なら"X"を返し, Oプレイヤーが勝利なら"O"を返す. ドローなら"D"を返す.

入力:あるゲームの結果. 文字列のリスト(Unicode)
出力:"X"か"O"か"D". 文字列.

備考
このタスクのコンセプトはあなたがデータを繰り返すときの手助けとなるだろう. それらはゲームアルゴリズムでも使われ, あなたにどのように結果をチェックするかということを知るために与えられる.

Speech Module

Assigning words and phrases to digits and numbers.

Stephen's speech module is broken. This module is responsible for his number pronunciation. He has to click to input all of the numerical digits in a figure, so when there are big numbers it can take him a long time.
Help the robot to speak properly and increase his number processing speed by writing a new speech module for him. All the words in the string must be separated by exactly one space character.
Be careful with spaces -- it's hard to see if you place two spaces instead one.

Input: A number, an integer.
Output: A string representation of this number.

How it is used:
This concept may be useful for the speech synthesis software or automatic reports systems.
This system can also be used when writing a chatbot by assigning words or phrases numerical values and having a system retrieve responses based on those values.

ステファンのスピーチモジュールは壊れている. このモジュールは彼の数の発音を担う. 彼は図の中の全ての数値をクリックで入力するが, それが大きな数の時, とても時間がかかる.
ロボットが適切にしゃべるようにし, 大きな数でも処理のスピードが速い, 新しいモジュールを彼のために作る手助けをしてほしい. すべての単語はスペースで区切られた文字列として返せばよい.
スペースに関して注意してほしいことがある, 2つスペースを入れてはならない.

入力:ある数, 整数
出力:文字を表現する文字列

備考
このコンセプトは音声合成ソフトウェアや, 自動通報システムなどで使われるものである.
チャットボットに書きこむとき, このシステムは単語や数値のフレーズに割り当てられ, それらの値に基づいた応答を返すことにも使われる.

The Flat Dictionary

Nikola’s organization methods are flat-out ridiculous.

Nikola likes to categorize everything in sight. One time Stephan gave him a label maker for his birthday, and the robots were peeling labels off of every surface in the ship for weeks. He has since categorized all the reagents in his laboratory, books in the library and notes on the desk. But then he learned about python dictionaries, and categorized all the possible configurations for Sophia’s drones. Now the files are organized in a deep nested structure, but Sophia doesn’t like this. Let's help Sophia to flatten these dictionaries.
Python dictionaries are a convenient data type to store and process configurations. They allow you to store data by keys to create nested structures. You are given a dictionary where the keys are strings and the values are strings or dictionaries. The goal is flatten the dictionary, but save the structures in the keys. The result should be the a dictionary without the nested dictionaries. The keys should contain paths that contain the parent keys from the original dictionary. The keys in the path are separated by a "/". If a value is an empty dictionary, then it should be replaced by an empty string (""). Let's look at an example:
{
    "name": {
        "first": "One",
        "last": "Drone"
    },
    "job": "scout",
    "recent": {},
    "additional": {
        "place": {
            "zone": "1",
            "cell": "2"}
    }
}
The result will be:
{"name/first": "One",           #one parent
 "name/last": "Drone",
 "job": "scout",                #root key
 "recent": "",                  #empty dict
 "additional/place/zone": "1",  #third level
 "additional/place/cell": "2"}
Sophia has already written the code for this task, but it has a bug. You need to find and fix this bug.

Input: An original dictionary as a dict.
Output: The flattened dictionary as a dict.

How it is used:
This concept can be useful if you need to parse config files and simplify structures for grandfathered systems and file structures. You can easily modify this idea for your own specifications. Besides that, it's a useful skill to be able to read code and search for bugs.

ニコラは目に見えるすべてのものを分類するのが好きだ. あるときステファンは彼の誕生日のためにラベルメーカーをプレゼントしたところ, ロボットたちは数週間のために船内のあらゆるラベルをはがした. 彼はそれ以来研究室の試薬, 図書室の本や机の上のノートなどすべてを分類した. しかし彼がpythonの辞書を学んだところ, ソフィアのドローンのために全ての可能な設定を分類した. 今そのファイルは深いネスト構造になっているが, ソフィアはこれが好きではない. フラットな辞書にするためにソフィアを助けよう.
pythonの辞書は設定を保存, 処理するのに便利なデータ構造だ. それらはネストされた構造を作るキーによってデータを保存する. あなたには文字列であるキーと文字列である値, またはネストした辞書を含んだ辞書が与えられる. 目的はフラットになった辞書であるが, キー内の構造は保持する. 結果はネストしていない辞書である必要がある. キーは元の辞書の親キーを含むパスでなければならない. パス内のキーはスラッシュで区切られる. 値が空の辞書なら, それは文字列""に置き換えられる. 例を見てみよう.
{
    "name": {
        "first": "One",
        "last": "Drone"
    },
    "job": "scout",
    "recent": {},
    "additional": {
        "place": {
            "zone": "1",
            "cell": "2"}
    }
}
結果は次のようになる.
{"name/first": "One",           #1つの親キー
 "name/last": "Drone",
 "job": "scout",                #ルートキー
 "recent": "",                  #空の辞書
 "additional/place/zone": "1",  #三層のキー
 "additional/place/cell": "2"}

入力:辞書形式としてオリジナルの辞書
出力:辞書形式としてフラットになった辞書

備考
このコンセプトは大抵あなたが設定ファイルの解析や古いシステムの単純な好悪図やファイル構造のために必要となる. あなたは容易にこのアイデアを自身の設計に適用できる. 加えて, それはコードを読んだりバグを探したりするのに便利なスキルだ.

How to find friends

Drones want to feel loved too...

Sophia's drones are not soulless and stupid drones; they can make and have friends. In fact, they are already are working for the their own social network just for drones! Sophia has received the data about the connections between drones and she wants to know more about relations between them.
We have an array of straight connections between drones. Each connection is represented as a string with two names of friends separated by hyphen. For example: "dr101-mr99" means what the dr101 and mr99 are friends. Your should write a function that allow determine more complex connection between drones. You are given two names also. Try to determine if they are related through common bonds by any depth. For example: if two drones have a common friends or friends who have common friends and so on.
Let's look at examples:
scout2 and scout3 have the common friend scout1 so they are related. super and scout2 are related through sscout, scout4 and scout1. But dr101 and sscout are not related.

Input: Three arguments: Information about friends as a tuple of strings; first name as a string; second name as a string.
Output: Are these drones related or not as a boolean.

How it is used:
This concept will help you find not too obvious connections with the building of bond networks. And how to work social networks.

ソフィアのドローンは魂を持っており, 愚かではない. ドローンは友達を作ることができる. 事実, それらは既にドローンのためだけのソーシャルネットワークのために働いている. ソフィアはドローン間の接続に関するデータを受信して, それらの間の関係について知りたがっている.
私たちはドローン間の直接接続の配列を持っている. それぞれの接続はハイフンで区切られた友人同士の2つの名前の文字列で表現される. たとえば, "dr101-mr99"はdr101とmr99が友人同士であることを意味する. あなたはドローン間のより複雑な接続を判断する関数を書く. あなたには2つの名前も与えられる. ドローン同士がどのようにつながり, 関わっているか判断してみよう. たとえば, 2つのドローンが共通の友人または共通の友人の友人を持っている場合だ.
例を見てみよう
scout2とscout3は共通の友人としてscout1がおり, scout1はそれらと関連している. superとscout2はsscoutを通して関連しており, scout4はscout1と関連している. しかしdr101とsscoutに関連はない.

入力:3つの引数, 文字列のタプルでドローン同士のつながり, 最初のドローンの名前, 次のドローンの名前.
出力:引数の後者2つのドローンに関連があるかどうかをbooleanで.

備考
このコンセプトでは, ネットワーク網の構築時の明白でないつながりを見つける. そして, ソーシャルネットワークでの働き方を助けてくれる.

Feed Pigeons

The pigeons need to be fed specific portions. How many pigeons get to eat?

I start to feed one of the pigeons. A minute later two more fly by and a minute after that another 3. Then 4, and so on (Ex: 1+2+3+4+...).
One portion of food lasts a pigeon for a minute, but in case there's not enough food for all the birds, the pigeons who arrived first ate first.
Pigeons are hungry animals and eat without knowing when to stop.
If I have N portions of bird feed, how many pigeons will be fed with at least one portion of wheat?

Input: A quantity of portions wheat, a positive integer.
Output: The number of fed pigeons, an integer.

How it is used:
This task illustrates how we can model various situations.
Of course, the model has a limited approximation, but often-times we don't need a perfect model.

私はハトに餌を上げ始める. 1分後に2匹飛んできて, 更に1分後に3匹飛んでくる. 4分後もまた同じ(1+2+3+4...).
餌が残っていればハトは餌を食べ続けるが, 餌が十分でないとき, ハトは誰かのところで最初から食べ直す.
ハトは飢えた動物で, 食べ止めるということを知らない.
私がN個の鶏の餌を持っているなら, いくつのハトが餌を食べに来るか?

入力:餌の数, 整数
出力:餌を食べたハトの数, 整数

備考
このタスクは様々なシチュエーションのモデル化を学ぶものである.
もちろん, このモデルは限られた近似ではあるが, 私たちはしばしば完璧なモデルを必要としない.

Roman numerals

Translate modern numbers into Roman Numerals

Roman numerals come from the ancient Roman numbering system.
They are based on specific letters of the alphabet which are combined to signify the sum (or, in some cases, the difference) of their values.
The first ten Roman numerals are:
I, II, III, IV, V, VI, VII, VIII, IX, and X.
The Roman numeral system is decimal based but not directly positional and does not include a zero.
Roman numerals are based on combinations of these seven symbols:
Symbol Value
I 1 (unus)
V 5 (quinque)
X 10 (decem)
L 50 (quinquaginta)
C 100 (centum)
D 500 (quingenti)
M 1,000 (mille)
More additional information about roman numerals can be found on the Wikipedia article.
For this task, you should return a roman numeral using the specified integer value ranging from 1 to 3999.

Input: A number as an integer.
Output: The string in the form of a Roman numeral.

How it is used:
This is an educational task that allows you to explore different numbering systems.
Since roman numerals are often used in the typography, it can alternatively be used for text generation.
The year of construction on building faces and cornerstones is most often written by Roman numerals.
These numerals have many other uses in the modern world and you read about it here... Or maybe you will have a customer from Ancient Rome ;-)

ローマ数字は古代ローマの数系だ.
それらはその数値の和を表すアルファベットを組み合わせた特殊な文字である.
10までのローマ数字は以下のとおりである.
I, II, III, IV, V, VI, VII, VIII, IX, X
ローマ数系は10進数ではあるが, 直接表さず, また0も含まない.
ローマ数字は以下の7つのシンボルからなる.
シンボルと値:
I 1 (unus)
V 5 (quinque)
X 10 (decem)
L 50 (quinquaginta)
C 100 (centum)
D 500 (quingenti)
M 1,000 (mille)
他にも色々あるが, これ以上知りたければWikipediaを見てほしい.
このタスクを解くためには, あなたは提示された整数(1から3999)をローマ数字して返す必要がある.

入力:ある整数の数
出力:ローマ数字の形の文字列

備考
これは教育的なタスクで, あなたに異なる数系を発見させるだろう.
ローマ数字はしばしばタイポグラフィ(新聞などの印刷に使われる技法)で使われ, それは代わりにテキスト生成のために使うこともできる.
建物を建てたときの礎石などにはしばしばローマ数字で建設年が描かれる.
これらの数字は現代世界やあなたが読むものに多く使われる. またはあなたが古代ローマからの客人かもしれないが ;-)

Min and Max

We are going to write our own min/max. With blackjack and... other people! In fact, forget the min/max!

In this mission you should write you own py3 realisation of the built-in functions min and max. Some builtin functions are closed here: import, eval, exec, globals. Don't forget you should realize two functions in your code.
max(iterable, *[, key]) or min(iterable, *[, key])
max(arg1, arg2, *args[, key]) or min(arg1, arg2, *args[, key])
Return the largest (smallest) item in an iterable or the largest of two or more arguments.
If one positional argument is provided, it should be an iterable. The largest (smallest) item in the iterable is returned. If two or more positional arguments are provided, the largest (smallest) of the positional arguments is returned.
The optional keyword-only key argument specifies a function of one argument that is used to extract a comparison key from each list element (for example, key=str.lower). The default value of None means that iterable items are compared directly without calculating a separate key value.
If multiple items are maximal (minimal), the function returns the first one encountered.
Python Documentation (Built-in Functions)

Input: One positional argument as an iterable or two or more positional arguments. Optional keyword argument as a function.
Output: The largest item for the "max" function and the smallest for the "min" function.

How it is used:
This task will help you understand how some of the built-in functions work on a more precise level.

このミッションではあなたはpython3の組み込み関数であるminとmaxを実装する. いくつかの組み込み関数, import, eval, exec, globalsはここでは使えない. あなたのコードは2つの関数を実装するということを忘れてはならない.
max(iterable, *[, key]) または min(iterable, *[, key])
max(arg1, arg2, *args[, key]) または min(arg1, arg2, *args[, key])
イテレータブルなデータ(リストなど)か, 2つ以上の引数のうち最大(最小)要素を返す.
引数が1つだけなら, それはイテレータブルなデータとする. イテレータブルなデータのうち最大(最小)要素を返す. 2つ以上の引数が与えられたら, 引数のうち最大(最小)を返す.
補助引数としてそれぞれのリストの要素に適用されるのに使われるキー(たとえば, key=str.lower)が与えられる場合もある. キーがNoneの場合, それはイテレータブルなデータがキーの値によらず, 直接計算されることを意味する.
複数の最大(最小)要素がある場合, 関数は最初にチェックした要素を返す.

入力:イテレータブルなデータ1つか, 2つ以上の引数. 加えてオプションのキーワード引数.
出力:max関数では最大の要素を, min関数では最小の要素を返す.

備考
このタスクではあなたに, 組み込み関数のいくつかがより正確なレベルでどのように機能するかを理解させる手助けとなる.

Prime Palindrome Golf

Score a palindromic hole-in-one.

Do you know how to play Prime Palindrome Golf? You are given a number and your challenge is to find the closest palindromic prime number that greater than what you were given.
A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed, such as 79197. These numbers appear to be symmetrical.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In this task you will be given an positive integer. You should find the closest integer that:
  • is greater than the given number;
  • is prime;
  • is palindromic.
For example: for the number 13, the closest greater palindromic prime is 101. Or, for the number is 2, the answer is 3, because any one-digit number is a palindrome.
We have one more rule for this challenge. This is a code golf mission and your main goal is to make your code as short as possible. The shorter your code, the more points you earn. Your score for this mission is dynamic and directly related to the length of your code. For reference, scoring is based on the number of characters used. 250 characters is the maximum allowable and it will earn you zero points. For each character less than 250, you earn 1 point. For example for 200 character long code earns you 50 points.
Important: We are using default recursion limit (100). So don't try to solve this mission with recursion.

Input: A number as an integer.
Output: The closest greater palindromic prime as an integer.

How it is used:
Prime numbers are very useful for many CS areas, however; this task is not about elegant or performance code. This is about hacks and tricks in python which help you to shorten your code. You don't need to use this in production, but it can help for deeper comprehension of Python.

あなたは素数回文ゴルフを知ってるかな? あなたにはある数が与えられる. あなたは与えられた数より大きな, 回文となった直近の素数を探すことに挑戦する.
回文数字, もしくは数字の回文とは, 数の桁を逆順にしても元の数と同じ数であるもの, たとえば79197などのことをいう. これらの数は対称的に見える.
素数とは1より大きな数で, 1と自身でしか割り切れない自然数のことを言う. このタスクではあなたは正の整数が与えられる. あなたはその整数に最も近い, 次の条件を満たす数を探す.
  • 与えられた数より大きい.
  • 素数である.
  • 回文である.
たとえば, 13が与えられた場合, 直近の回文素数は101だ. また2の場合, 答えは3だ. 一桁の数は全て回文なのだから.
私たちはこの挑戦に更にルールを追加する. これはコードゴルフミッションで, あなたの目的はあなたのコードを可能な限り短くすることだ. あなたのコードが短ければ, あなたはより多くのポイントを得る. このミッションでのあなたのスコアは動的で, あなたのコードの長さに直接関連している. 参考までに, スコアは使われた文字数を元にしている. 250文字が許される最大の文字数で, それを超えるとあなたは0ポイントだ. 250文字より少なければ, あなたは1ポイントを得る. たとえば200文字の場合はあなたは50ポイントを得る.
重要なこと, 私たちは標準的な再帰制限(100)を使う. だからこのミッションでは再帰を使って解こうとしないでほしい.

入力:ある整数.
出力:入力より大きな直近の回文素数を整数で.

備考
素数はとても多くのコンピュータサイエンスで使われるが, このタスクでは優雅なコードやパフォーマンス重視のコードについては求めていない. このpythonでのハック&トリックはあなたのコードを短くするのを助けてくれる. あなたは生産(職業上のコーディングのこと?)ではこれを使う必要がないが, それはpythonの深い理解の助けとなる.

Golden Pyramid

Help Stephen find the best route down a pyramid.

Our Robo-Trio need to train for future journeys and treasure hunts. Stephan has built a special flat model of a pyramid. Now the robots can train for speed gold running. They start at the top of the pyramid and must collect gold in each room, choose to take the left or right path and continue down to the next level. To optimise their gold runs, Stephan need to know the maximum amount of gold that can be collected in one run.
Consider a tuple of tuples in which the first tuple has one integer and each consecutive tuple has one more integer then the last. Such a list of lists would look like a triangle. You should write a program that will help Nikola find the highest possible sum on the most profitable route down the pyramid. All routes down the pyramid involve stepping down and to the left or down and to the right.

Hints:
Think of each step down to the left as moving to the same index location or to the right as one index location higher. Be very careful if you plan to use recursion here.

Input: A tuple of tuples. Each tuple contains integers.
Output: The maximum possible sum as an integer.

How it is used:
This is a classical problem which shows you how to use dynamic programming. This concept is a core component of many optimisation tasks.


私たちのロボトリオは将来の旅行と宝探しのためのトレーニングを必要としている. ステファンは特別なピラミッドの簡単なモデルを組み立てた. 今ロボットは金を運ぶ速さの訓練をしている. 彼らはピラミッドの上からスタートし, それぞれの部屋の金を集める. 次の段に墜ちるには左か右を選ばなければならない. 彼らの金の収集を最適化するために, ステファンは1回の実行で集められる金の最大量を知る必要がある.
(ピラミッドは)タプルのタプルとみなす. 最初のタプルは1つの整数で, それぞれの連続するタプルは1つ以上の整数を持っている. 三角形のようなリストのリストみたいなものだ. あなたはピラミッドの下に降りるルートのうち最も和が大きいものを見つけるプログラムをニコラを助けるために書く. すべてのルートは下に降りて左か右に行くかである.

ヒント
それぞれのステップでは, 左に移動する場合同じインデックスで, 右に移動する場合インデックスを1つだけずらせばよい. もしあなたが再帰を使おうとしているなら注意するべきである.

入力:タプルのタプル. それぞれのタプルは整数からなる.
出力:可能な最大の和

備考
これは古典的な動的計画法で解く問題である. これは多くの最適化タスクの核となっている.

Open Labyrinth

Use your skills to navigate through a complex maze

The labyrinth has no walls, but pits surround the path on each side.
If a players falls into a pit, they lose. The labyrinth is presented as a matrix (a list of lists): 1 is a pit and 0 is part of the path.
The labyrinth's size is 12 x 12 and the outer cells are also pits. Players start at cell (1,1). The exit is at cell (10,10).
You need to find a route through the labyrinth.
Players can move in only four directions--South (down [1,0]), North (up [-1,0]), East (right [0,1]), West (left [0, -1]).
The route is described as a string consisting of different characters: "S"=South, "N"=North, "E"=East, and "W"=West.

Input: A labyrinth's map. A list of lists with 1 and 0.
Output: A route. A string that contain "W", "E", "N" and "S".

Hints: It can help, if you get stuck
The labyrinth in this task can be represented as graph. Just think about where you can go from each cell and find the correlating path in the graph.
The simplest way is Breadth-First-Search algorithm. But don't mix up graph and tree search.
Do you want nice and quick solution? Read about A* search algorithm and don't forget about admissible heuristic.

How it is used:
This is a classical problem for path-finding in graphs -- Yes, the maze can be represented as a graph.
It can be used in navigation software for a to b navigation and computer games for artificial intelligence.
You can find your way anywhere you wish. Just divide a map into square cells and mark up the "bad" cells.

この迷路には壁がないが, くぼみのまわりには通路がある.
もしプレイヤーがくぼみに落ちたら, 彼らの負けである. 迷路は行列(リストのリスト)で表現され, 1がくぼみで, 0が通路である.
迷路の大きさは12×12で, 外側のセルはすべてくぼみである. プレイヤーは(1,1)のセルからスタートする. 出口は(10,10)だ.
あなたは迷路を通り抜けるルートを見つける必要がある.
プレイヤーは4つの方向に動くことができる, 南(下[1, 0]), 北(上 [-1, 0]), 東(右 [0, 1]), 西(左 [0, -1]).
このルートはS(南), N(北), E(東), W(西)の異なる文字から成る文字列で表現される.

入力:ある迷路のマップ, 1と0からなるリストのリスト.
出力:出口までのルート, WENSで表現される.

ヒント
このタスクの迷路はグラフとして表現可能である. 各々のセルからあなたが行くことができる場所は, グラフでは相関として見つけることができる.
単純な方法は幅優先探索アルゴリズムである. ただし, グラフと木の探索を混ぜてはならない.
早く良い解法を望んでいるか? A*(エースター)探索アルゴリズムを読むと言い, ただし許容されるヒューリスティックを忘れないこと!

備考
これは古典的なグラフでの経路探索の問題である, そう, 迷路はグラフで表現可能なのだ.
それはナビゲーションソフトウェアやゲームの人工知能で使われている.
あなたはどこでも, あなたが望むようなあなたの解法を見つけることができる. マップを分割して, 四角のセルの中にいれて, よくないセルをマークアップするだけだ.

問題概要と解法のメモ
+ ...
迷路が与えられ, (1,1)から(10,10)までの経路を返す問題(最短経路でなくてもよい).
単純に左手法で解いてもいいし, グラフ化して幅優先探索してもよい(少なくとも幅優先探索なら最短経路になる).
ここで言う"グラフ"とは"グラフ理論"で用いるグラフのことであることに注意.
グラフ理論のアルゴリズムを使うなら, ダイクストラ法や, ここでも述べているA*アルゴリズムを使うとより早く, 最短経路を探索することができる.
ダイクストラ法やA*を使う場合, 適切な評価値を使わなければならない. 迷路の場合出口までの距離が大抵使われる(マンハッタン距離だったりユークリッド距離だったり).
なお大抵のRTSゲームの自動移動アルゴリズムはA*らしい. A*サイッキョ.
最終更新:2014年07月08日 16:45