ãã®æã®åé¡ã¯ãåææ°ã§ããããå¤å®ããã®ã§ã¯ãªããåææ°ãçæããã®ãå®çªã§ããåææ°ãçæããã«ã¯ãä¾ãã°987ãªãå転ãã¦789ã«ãã¦çµåãã¦987789ã¨ãã¾ããã¾ããå転ã§ãã
:reverse setlocal if %1 == 0 exit /b %2 set /a d = %1 %% 10 set /a n = %1 / 10 call :reverse %n% %2%d% exit /b %ERRORLEVEL%
ä¸ã®æ°åãä¸ã«æã£ã¦ããã ãã§ããæååã§ãªãæ´æ°ã¨ãã¦æ±ãã®ã¯ãæååã ã¨çµäºå¤å®ããã¾ããããªãããã§ãããã®é¢æ°ã®å¼æ°ã¯2ã¤ãªã®ã§ãããæåã«å¼ã³åºãããã¨ãã¯1ã¤ã§ã%2ã«å¤ãã»ããããã¦ãã¾ãããããããæååã«ããã¨æå¾ã«ç¬¬1å¼æ°ãé·ã0ã®æååã«ãªãã第2å¼æ°ã%1ã«ãªãã¾ããããããã¨æåã¨åºå¥ãã¤ããªããªãã¾ãã
@echo off set /a k = 990 :loop call :create_palindrome %k% set /a n = %ERRORLEVEL% call :is_product %n% if %ERRORLEVEL% == 0 ( set /a k -= 1 goto :loop ) echo %n% exit /b 0 rem // 123 -> 123321 :create_palindrome setlocal call :reverse %1 set /a n = %1 * 1000 + %ERRORLEVEL% exit /b %n% rem // 123 -> 321 :reverse setlocal if %1 == 0 exit /b %2 set /a d = %1 %% 10 set /a n = %1 / 10 call :reverse %n% %2%d% exit /b %ERRORLEVEL% rem // 3æ¡ã®æãç®ã«ãªã£ã¦ããã :is_product setlocal set /a d = 999 :loop_is_product set /a q = %1 / %d% if %q% GTR %d% exit /b 0 set /a r = %1 %% %d% if %r% == 0 exit /b 1 set /a d -= 1 goto :loop_is_product