Skip to content

Instantly share code, notes, and snippets.

@masayuki5160
Created January 31, 2016 05:26
Show Gist options
  • Save masayuki5160/99acc7b15f808c265508 to your computer and use it in GitHub Desktop.
Save masayuki5160/99acc7b15f808c265508 to your computer and use it in GitHub Desktop.
プログラマ脳を鍛える数学パズルQ01
<?php
for($i = 10; $i <= 1000; $i++){
if($i == strrev($i)
&& decbin($i) == strrev(decbin($i))
&& decoct($i) == strrev(decoct($i))){// 回文数だったら
echo $i. "\n";
echo decbin($i). "\n";
echo decoct($i). "\n";
break;
}
}
@masayuki5160
Copy link
Author

実行結果


$ php -f q01.php
585
1001001001
1111


@masayuki5160
Copy link
Author


勉強会での出題


10進数で回文
【予備知識】
回文数?
逆から数字を読んでも同じ数になる数のことを"回文数"といいます
たとえば、"12321", "888"とかですね
【問題】
10進数、2進数、8進数のいずれで表現しても回文数となる数のうち、10進数の10以上で最小の値を求めてください。

例(ただし10進数で10未満なので対象外)
ex. 9(10進数) = 1001(2進数) = 11(8進数)
注意
使用する言語は自由
関数を使用するのはもちろんあり

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