Library

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


Fizz Buzz

A word game used to the teach robots about division.

"Fizz buzz" is a word game we will use to teach the robots about division. Let's learn computers.
You should write a function that will receive a positive integer and return:
"Fizz Buzz" if the number is divisible by 3 and by 5;
"Fizz" if the number is divisible by 3;
"Buzz" if the number is divisible by 5;
The number as a string for other cases.

Hints:
You can easily solve this task with: if-else, % operator and string conversion.

Input: Two arguments. Integers.
Output: The string.

How it is used:
Here you can learn how to write the simplest function and work with if-else statements.

"Fizz buzz"はロボットに境界ついて教えてるために使われる言葉遊びだ. コンピュータについて学ぼう.
あなたは正の整数を受け取り, 次のような文字列を返す関数を作る.
正の整数が3と5で割り切れるなら"Fizz Buzz"を返す.
正の整数が3で割り切れるなら"Fizz"を返す.
正の整数が5で割り切れるなら"Buzz"を返す.
それ以外は数字を文字列としてそのまま返す.

ヒント
if-else構文と, %演算子(剰余演算子), 文字列変換を使えばこのタスクは容易に解くことができる.

備考
あなたはここでif-else構文を使った単純な関数の書き方を学ぶことができる.

Even the last

How to work with arrays indexes.

You are given an array of integers. You should find the sum of the elements with even indexes (0th, 2nd, 4th...) then multiply this summed number and the final element of the array together. Don't forget that the first element has an index of 0.
For an empty array, the result will always be (zero).

Hints:
This task can be solved using Lists indexes, Slices and Built-in Function "sum".

Input: A list of integers.
Output: The number as an integer.

How it is used:
Indexes and slices are important elements of coding in python and other languages. This will come in handy down the road!

あなたに整数の配列が与えられる. あなたは偶数番目の要素の和と, 配列の最後の要素をかけたものを返す.
空のリストの場合, 0を返す.

ヒント
このタスクはリストのインデックスと, スライス操作, そして組み込み関数の"sum"を使って解くことができる.

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

備考
インデックスとスライスはpythonや他の言語でのコーディングにかんして重要な要素である. これらは道中を便利にするだろう.

Three words

How to discern words and numbers.

Let's teach the Robots to distinguish words and numbers.
You are given a string with words and numbers separated by whitespaces (one space). The words contains only letters.
You should check if the string contains three words in succession.

Hints:
You can easily solve this task with these useful functions: str.split, str.isalpha and str.isdigit.

Input: A string with words.
Output: True or False, a boolean.

How it is used:
This teaches you how to work with strings and introduces some useful functions.

ロボットに単語と数を区別させることを教えよう.
あなたにはスペースで区切られた単語と数からなる文字列が与えられる. その単語は文字だけを含んでいる.
あなたは文字列に3つの単語が連続して含まれているかどうかチェックする.

ヒント
str.split, str.isalpha, str.isdigitなどの関数を使えばこのタスクを容易に解くことができる.

入力:単語を伴う文字列
出力:TrueかFalse, boolean型

備考
あなたは文字列操作とよくつかわれるいくつかの関数を学ぶ.

The Most Numbers

Determine the difference between the smallest and the biggest numbers.

Let's work with numbers.
You are given an array of numbers (floats). You should find the difference between the maximum and minimum element.
Your function should be able to handle an undefined amount of arguments. For an empty argument list, the function should return 0.
Floating-point numbers are represented in computer hardware as base 2 (binary) fractions (read about this here).
So we should check the result with ±0.001 precision.

Hints:
Think about how to work with an arbitrary number of arguments.

Input: Undefined amount of arguments, numbers.
Output: The difference between maximum and minimum.

How it is used:
Here you will learn about passing an undefined amount of arguments to functions.

数について学ぼう.
あなたには数(float, 浮動小数点型)の配列が与えられる. あなたは要素の最大値と最小値の差を求める.
あなたの関数は可変長な引数である. 引数のリストが空の場合, 関数は0を返すべきである.
浮動小数点はコンピュータハードウェア上では2進数の分数で表現される.
そのため結果には±0.001の精度のチェックをするべきである.

ヒント
引数の任意の数を操作する方法を学べるだろう.

入力:可変長の引数, 数値
出力:最大値と最小値の差

備考
あなたは可変長引数について学ぶことができる.

Digits Multiplication

How to work with numbers by non standard way.

You are given a positive integer. Your function should calculate the product of the digits excluding any zeroes.
For example: The number given is 123405. The result will be 1*2*3*4*5=120 (don't forget to exclude zeroes).

Hints:
This task can be solved with a simple conversion from int to str and versus. Read more about built-in types here.

Input: A positive integer.
Output: The product of the digits as an integer.

How it is used:
This task can teach you how to solve a problem with simple data type conversion.

あなたに正の整数がが与えられる. あなたの関数は0を除いた桁の積を計算する.
たとえば, 123405という数の場合, その結果は1*2*3*4*5120となる(0を除くことを忘れないように).

ヒント
このタスクは整数から文字列への単純な変換を使えば解くことができる.

入力:正の整数
出力:整数の桁の積

備考
このタスクはあなたにデータの変換問題を解く方法を教える.

The end of other

How to find suffixes.

For language training our Robots want to learn about suffixes.
In this task, you are given a set of words in lower case.
Check whether there is a pair of words, such that one word is the end of another (a suffix of another).
For example: {"hi", "hello", "lo"} -- "lo" is the end of "hello", so the result is True.

Hints:
For this task you should know how to iterate through set types and string data type functions. Read more about set type here and string functions here.

Input: A set of words.
Output: True or False, as a boolean.

How it is used:
Here you can learn about iterating through set type and string data type functions.

ロボットの言語訓練のために, サフィックス(接尾辞)を学びたい.
このタスクでは, 小文字の単語のセットが与えられる.
2つの単語をチェックし, 片方の単語がもう片方の終わりかどうか調べる(もう片方の接尾辞かどうか).
たとえば, {"hi", "hello", "lo"}というリストの場合, "lo"は"hello"の末尾と一致するので, 結果はTrueとなる.

ヒント
このタスクは集合型に対するイテレータと文字列型の関数について学ぶことができる.

入力:単語の集合
出力:TrueかFalse, boolean型

備考
あなたはここで集合型のイテレータと文字列型の関数を学ぶことができる.

Binary count

How to work with binary formatting.

For the Robots the decimal format is inconvenient. If they need to count to "1", their computer brains want to count it in the binary representation of that number. You can read more about binary here.
You are given a number (a positive integer). You should convert it to the binary format and count how many unities (1) are in it.

Hints:
This task can be easily solved with two functions -- bin and count.

Input: A number as a positive integer.
Output: The quantity of unities in the binary form, an integer.

How it is used:
How to convert a number to the binary form. It can be useful for Computer Science purposes.

ロボットにとって10進数は不便だ. 彼らが"1"をカウントする必要があるなら, 彼らのコンピュータ頭脳は数字の2進数表現にしてカウントしたい. あなたはここで2進数を読むことができる.
あなたに正の整数が与えられる. あなたはそれを2進数に変換し, 1の数を数えるのだ.

ヒント
このタスクはbin()とcount()という2つの関数で容易に解ける.

入力:ある正の整数
出力:2進表記での1の数, 整数型

備考
ある数を2進数に変換する方法を学べる. これはコンピュータサイエンス処理でよく使われる.

Number Base

How to work with numeral systems.

Do you remember the radix and Numeral systems from math class? Let's practice with it.
You are given a positive number as a string along with the radix for it. Your function should convert it into decimal form.
The radix is less than 37 and greater 2. The task uses digits and the letters A-Z for the strings.
Watch out for cases when the number cannot be converted. For example: "1A" cannot be converted with radix 9.
For these cases your function should return -1.

Hints:
You can easily solve this task with int() conversion and handling exceptions (Look at ValueError).

Input: Two arguments. A string and an integer.
Output: The number. An integer.

How it is used:
Here you will learn how to work with the various numeral systems and handle exceptions.

基数とmathクラスの進数を覚えているかな? これはその練習だ.
あなたに正の整数が文字列とその基数が与えられる. あなたの関数はそれを10進数に変換する.
基数は2以上で37より小さい. ここでは桁は数値(0-9)とA-Zの文字を使う.
変換できない数値の場合もある. たとえば"1A"は基数が9だと変換できない.
その場合関数は-1を返す.

ヒント
int()を使えば容易に変換できるが, 例外に注意.

入力:2つの引数, 文字列と整数
出力:数, 整数

備考
ここでは様々な進数と例外の扱いについて学ぶことができる.

The Common Words

Try to find what is common between two strings.

Let's continue examining words. You are given two string with words separated by commas.
Try to find what is common between these strings. The words are not repeated in the same string.
Your function should find all of the words that appear in both strings.
The result must be represented as a string of words separated by commas in alphabetic order.

Hints:
You can easily solve this task with several useful functions: str.split, str.join and sorted. Also try using the built-in type -- set.

Input: Two arguments. Strings.
Output: The common words as a string.

How it is used:
Here you can learn how to work with strings and sets. This knowledge can be useful for linguistic analysis.

引き続き単語についてよく調べよう. あなたにコンマで区切られた単語からなる2つの文字列が与えられる.
これらの文字列に共通するものを探そう. その単語は同じ文字列内では繰り返さない.
結果はアルファベット順に, コンマで区切られた単語の文字列として表現するべきである.

ヒント
str.split()とstr.join(), そしてsorted()関数を使うことで容易に解くことができる. もし試すなら, 組み込み型のsetも使ってもよい.

入力:2つの引数, 文字列
出力:共通の単語を文字列として

備考
あなたはここで文字列と集合の操作を学ぶことができる. この知識は言語処理でよく使われる.

The absolute sorting

How to sort an array by absolute values.

Let's try some sorting. Here is an array with the specific rules.
The array (a tuple) has various numbers. You should sort it, but sort it by absolute value in ascending order.
For example, the sequence (-20, -5, 10, 15) will be sorted like so: (-5, 10, 15, -20). Your function should return the sorted list or tuple.

Hints:
This task can be easily solved using these functions: sorted and abs. You should try to use the key parameter for sorting.

Precondition:
The numbers in the array are unique by their absolute values.

Input: An array of numbers , a tuple..
Output: The list or tuple (but not a generator) sorted by absolute values in ascending order.

How it is used:
Sorting is a part of many tasks, so it will be useful to know how to use it.

ソートに挑戦しよう. ここでは特殊なルールが用いられる.
配列(タプル)は様々な値を持っている. あなたはそれをソートするが, 要素の絶対値で昇順ソートする.
たとえば, (-20, -5, 10, 15)は(-5, 10, 15, -20)としてソートされる.
あなたの関数はソートされたリストかタプルを返す.

ヒント
このタスクはsorted()とabs()を使うことで容易に解ける. あなたはソートの引数にキーを使うことを試すべきだ.

前提条件
全ての数の絶対値は重複しない.

入力:数値の配列, タプル
出力:絶対値で昇順ソートされたリストまたはタプル

備考
ソートは多くのタスクで使われる, その使い方を知っておくとよい.
最終更新:2014年04月29日 18:25