ååã®ãµã³ãã«ã¯ããã¦ã¼ã¶ã¼ã®å ¥åããµã¼ãã¼ã®ããã°ã©ã ã«åæ ãããã«ã¯ã©ãããããã¨ãããã®ã§ããã以åã®ãã®ããã°ã§ããããå¤æ°ãå¤æ´å¯è½ãªããã°ã©ãã³ã°è¨èªã§æ¸ãããã®ããå¤æ°ãå¤æ´ä¸å¯è½ãªãã®ã«æ¸ãæããã¨ãããã¨ããã£ã¦ãã¾ããã
ã¦ã¼ã¶ã¼ãã¢ã¯ã»ã¹ãããã¨ã«æ°ãããã¼ã¸ã§ã³ã®ããã°ã©ã ã«ã¢ã¯ã»ã¹ããããã«ãªã£ã¦ããã¨ãã¾ãã
ã¦ã¼ã¶ã¼ããã®1åç®ã®ã¢ã¯ã»ã¹ã¯ãã¼ã¸ã§ã³1
ã¦ã¼ã¶ã¼ããã®2åç®ã®ã¢ã¯ã»ã¹ã¯ãã¼ã¸ã§ã³2
â¦â¦
ãããªã£ã¦ããã¨ãã¦ããã¼ã¸ã§ã³âãèãã¾ããããã¯ãã¼ã¸ã§ã³1ããã¼ã¸ã§ã³2ãâ¦ããã¹ã¦å«ããã®ã¨ãã¾ãããã®ãã¼ã¸ã§ã³âã¯ã¦ã¼ã¶ã¼ãå®è¡ãã¦ãããã¨ããµã¼ãã¼ã§å®è¡ãããã¨ã«ãªãã®ã§ã¯ãªãããã¨ãããã¨ã調ã¹ã¦ãã¾ãã
ãã¼ã¸ã§ã³âãã©ã表ãã°è¯ããã¨ããåé¡ãèããããã«ãå¤æ°ãå¤æ´ä¸å¯è½ã¨ããã°èãããããªãã®ã§ã¯ãªãã(ãã¨ãã°å½¢å¼çã¹ãç´æ°ã«å¯¾å¿ãããããã®ã§ã¯ãªãã)ã¨ãããã¨ã§ããã¦ã¼ã¶ã¼ã®å ¥åããµã¼ãã¼ã®ããã°ã©ã ã«åæ ãããã«ã¯ã¨ãããããã¯æ¼ ç¶ã¨ãã¦ãã¦ã¯é£ããã®ã§ãã¾ããå¤æ°ã®å¤æ´å¯è½ãªãã®ãå¤æ´ä¸å¯è½ã«å¤æ´ããã¨ã©ããªãããã調ã¹ã¦ãã¾ãã
以åã®ãã®ããã°ã§ã¯ TypeScriptãF#ãGo ã«æ¸ãæãã¦ãã¾ã(ãé¢æ°ããã°ã©ãã³ã°ã¨ç¡éè«çå¤é å¼ã)ãTypeScriptãF# 㯠Visual Studio ã§ãã使ãã¾ããGo 㯠Visual Studio Code ãã使ããããã«ãã¦ããã¾ãããããã¶ãç°¡åã«ã¤ã³ã¹ãã¼ã«ã§ãããããã£ã¦ã¿ãã¨æããã¾ããä»ã®ããã°ã©ãã³ã°è¨èªã¯ã¤ã³ã¹ãã¼ã«ãã¦ãããã®ãããã¾ããã Visual Studio Code ãã使ããããã«ãã¦ã¯ããªãã£ãã®ã§ãç°¡åã«ã§ãããã«ãªãã®ã§ãããã®ããããã¾ãããä»ã¯ãããããã¾ããã
ãã¦ã¼ã¶ã¼ã®å ¥åããµã¼ãã¼ã®ããã°ã©ã ã«åæ ãããã«ã¯ã©ãããããã§ã¯ãªããå¤æ°ã®å¤æ´å¯è½ãªãã®ãå¤æ´ä¸å¯è½ã«å¤æ´ããã¨ã©ããªãããã®ãµã³ãã«ã¨ãã¦ã¯ RepeatGenerator() ã ãã§è¯ãã®ã§ãããã§ã¯ããããã£ã¦ã¿ã¾ããCalc ã¯ã©ã¹ã¯ GUI ãã使ãããã«å¦çãã¾ã¨ããã¯ã©ã¹ãªã®ã§ GUI ã使ããªãã¨ãã¯ä¸è¦ã¨ããã°ä¸è¦ã§ãã
ããã¯ãã¯ãã¼ã¸ã£ã¼ã使ãã¦ãå¤æ°ã®å¤æ´å¯è½ãå¤æ´ä¸å¯è½ãæå®ã§ããããã°ã©ãã³ã°è¨èªã§ããã°è¯ãã®ã§ãä»ã®ããã°ã©ãã³ã°è¨èªã§ãã§ããã°ãã£ã¦ã¿ã¾ããããã¯ããã©ã¦ã¶ã¼å´ã®ããã°ã©ãã³ã°è¨èªã®èª¿æ»ãå ¼ãã¦ãã¾ãã
Lisp ã«ã¤ãã¦ã調æ»ãã¦ãã¾ãããããã¯ä¸è¨ã®ãã¨ã«ä»ãå ãã¦ããã¯ãã¼ã¸ã£ã¼ã使ãã¦ãå¤æ°ã®å¤æ´å¯è½ãå¤æ´ä¸å¯è½ãæå®ã§ããããã°ã©ãã³ã°è¨èªãã Lisp ã®æ§æã§æ¸ããªããããããã調ã¹ã¦ãã¾ã(å®éã«ã¯ãã£ã¦ããªããããªã®ã§ãããããã¾ãã)ãLOGO ã«ã¤ãã¦ã調æ»ãããã¨ãã¦ããããã§ããããããåæ§ã¨æããã¾ã(ã¾ã ãã£ã¦ããªãã®ã§ãããããã¾ãã)ããã®å¾ç¬èªã®ããã°ã©ãã³ã°è¨èªãä½ã£ã¦ãã(ãã©ã ãè¨ç®ã¨ç¡éã©ã ãå¤é å¼ã)ã®ã§ Lisp ã§ã¯(ãããã)ä½ããã¦ãã¾ããã
以ä¸ã®çç±ã§ä»å㯠ChatGPT 㧠RepeatGenerator() ãå®è¡ããé¨åã ããæ¸ãæãã¦ãããã¾ããã
{-# LANGUAGE DeriveFunctor #-} import Data.Decimal import Control.Monad (forM_) -- Numbers ãã¼ã¿å data Numbers = Numbers { number :: Decimal , squareDifference :: Decimal , scale :: Int } deriving (Show) -- æ°åãä½æããããã®ã³ãã¼ copy :: Numbers -> Numbers copy nums = Numbers (number nums) (squareDifference nums) (scale nums) -- 次ã®10é²æ°æ¡ãåå¾ããé¢æ° getNextDecimalDigit :: Numbers -> (Int, Numbers) getNextDecimalDigit nums = go 9 nums where go dd n | dd < 0 = (0, n) | otherwise = let zd = fromIntegral dd `scaleB` (-scale n) two = Decimal 2 0 numberSqDiff = number n * zd * two + zd * zd in if numberSqDiff <= squareDifference n then (dd, Numbers (number n + zd) (squareDifference n - numberSqDiff) (scale n + 1)) else go (dd - 1) n -- NumbersGenerator ãã¼ã¿å data NumbersGenerator = NumbersGenerator { nums :: Numbers } deriving (Show) -- NumbersGenerator ã®ã¤ã³ã¹ã¿ã³ã¹çæ createGenerator :: NumbersGenerator createGenerator = NumbersGenerator (Numbers (Decimal 0 0) (Decimal 3 0) 0) -- 次ã®10é²æ°æ¡ãåå¾ããé¢æ° getNextDecimalDigitGen :: NumbersGenerator -> (Int, NumbersGenerator) getNextDecimalDigitGen generator = let (digit, newNums) = getNextDecimalDigit (nums generator) in (digit, generator { nums = newNums }) -- ã¡ã¤ã³é¢æ° main :: IO () main = do let count = 21 generator = createGenerator let (result, _) = foldl (\(resultNum, gen) e -> let (digit, newGen) = getNextDecimalDigitGen gen zd = fromIntegral digit `scaleB` (-e) in (resultNum + zd, newGen)) (Decimal 0 0, generator) [0..count - 1] print result