Created
January 31, 2016 05:26
-
-
Save masayuki5160/99acc7b15f808c265508 to your computer and use it in GitHub Desktop.
プログラマ脳を鍛える数学パズルQ01
This file contains hidden or 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 | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
勉強会での出題
10進数で回文
【予備知識】
回文数?
逆から数字を読んでも同じ数になる数のことを"回文数"といいます
たとえば、"12321", "888"とかですね
【問題】
10進数、2進数、8進数のいずれで表現しても回文数となる数のうち、10進数の10以上で最小の値を求めてください。
例(ただし10進数で10未満なので対象外)
ex. 9(10進数) = 1001(2進数) = 11(8進数)
注意
使用する言語は自由
関数を使用するのはもちろんあり