Skip to content

Instantly share code, notes, and snippets.

@masayuki5160
Created February 28, 2016 14:04
Show Gist options
  • Save masayuki5160/6a83119a79ae283ad589 to your computer and use it in GitHub Desktop.
Save masayuki5160/6a83119a79ae283ad589 to your computer and use it in GitHub Desktop.
プログラマ脳を鍛える数学パズルQ03
<?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";
@masayuki5160
Copy link
Author

微妙な回答だ。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment