Created
August 12, 2014 06:40
-
-
Save suzuken/70ad9c1b9226a6c8ce29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 教室に二人一組で座ることのできるテーブルが10台あり、生徒が20人いる時、 生徒の座席の位置をランダムに決定するプログラムをPHPで書きなさい。 | |
// 生徒名やテーブル名等の情報は任意に定義してかまいません。 | |
// 出力例. テーブル名をA~Jのアルファベットとし 生徒名を1~20の数字として表しています | |
// A - 6, 19 | |
// B - 1 ,4 | |
// C - 20,8 | |
// D - 16,11 | |
// E - 10,7 | |
// F - 5 ,14 | |
// G - 3 ,17 | |
// H - 12,2 | |
// I - 9 ,13 | |
// J - 18,15 | |
$students = range(1, 20); | |
$tables = range("A", "J"); | |
shuffle($students); | |
foreach ($tables as $t) { | |
$seat[$t][] = array_shift($students); | |
$seat[$t][] = array_shift($students); | |
} | |
foreach ($seat as $t => $s) { | |
echo "$t - ". $s[0] . "," . $s[1] . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment