Created
February 28, 2016 14:04
-
-
Save masayuki5160/6a83119a79ae283ad589 to your computer and use it in GitHub Desktop.
プログラマ脳を鍛える数学パズルQ03
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 | |
$card_arr = array_fill(0, 100, 0);// カードを配列で用意(0:裏返し、1:) | |
for($i = 1;$i <= 100;$i++){// 人が行うカードへの処理 | |
$offset = $i; | |
for($j = $i;$j <= 100;$j = $j + 1 + $offset){ | |
if($card_arr[$j] > 0){ | |
$card_arr[$j] = 0;// カードが表の時は裏にする | |
}else{ | |
$card_arr[$j] = 1;// カードが裏の時は表にする | |
} | |
} | |
} | |
echo "**********************\n"; | |
echo "裏返しのカード番号\n"; | |
echo "**********************\n"; | |
foreach($card_arr as $key=>$val){ | |
if($val === 0){ | |
$tmp_card_num = $key + 1; | |
echo "{$tmp_card_num}\n";// 裏返しのカード情報の表示 | |
} | |
} | |
echo "**********************\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
微妙な回答だ。。