ðåæžã
ååãã°ã©ãçè«ããã®è±ç·ãšããŠïŒ£ïŒ¯ïŒ¢ïŒ¯ïŒ¬ã®æå¹æ§ããå¥ã®ããã°ã©ã ãšãã³ãããŠæ€èšŒããããšããããŸãããããããåå©ã§ããã®ãã ããšãããã¯ãè¶ è¶ã³ãã©ãŒããšããŠã¯äžç²æãªãææãšãªããŸããã
ãªãããæããããŠãããŸããããè¶ è¶ããšã¯ãªã«ãã³ãã©ãŒãšããŠã®åè¶ããæè¡ãšãã趣æšãæã£ãŠè¿°ã¹ããã®ã§ã¯ãªããã³ã©ããäºæ³ã«åãçµãã çµæããè¶ è¶æ°ãã§ãããã€ãã¢æ°ïœ ãšçžåœå æé¢ä¿ãããããã ããšãã趣æšã§ãããŸããèŠçŽããã°ãäžäºç ããšããããšã§ãã
ãããã«ããŠãããã®ãŸãŸã§ã¯çµãããªããæéçãç·Žã£ãŠã第äºã®åæãè¡ããŸãã
ðãããïŒãããã°âŠïŒïŒ
ãŸãã¯ãä»åã®ïŒ£ïŒ¯ïŒ¢ïŒ¯ïŒ¬çµæå ±åã§ãã
ãïŒïŒ¥ïŒãïŒïŒïŒïœïœ
ããã¯ãååã®çµæããé床ãïŒïŒåçšåºŠåäžããŠããããšæ¯èŒããŠãåãããšãå£ããªãææããããŠããŸããäžã®ïŒµïŒ³ïŒ¥ïŒ²ã¿ã€ã ãã以åã®ãã®ã®çµæã§ããæåãã§ãåŸãã§ãã
èšèªïŒããïŒïŒ¥
ïŒä»¥åã®ãã®ïŒ
ïŒãïŒïŒïŒïŒïœïœ
ããããïŒãããïŒïŒïœïœ
ïŒä»åã®ãã®ïŒ
ïŒããïŒïŒïŒïœïœ
ãã³ããèŠããŠãã®ã§ãªããªã®ã§ãããããã¯èŠæãªãšãã ããå©çšããŠïŒ£ïŒ¯ïŒ¢ïŒ¯ïŒ¬ã«åã蟌ãã ãã®ã§ããåœãçæ¿ïŒ£ïŒ¯ïŒ¢ïŒ¯ïŒ¬ã®ãã®äžèº«ã¯ïŒ£ãšããããšã§ããããŸãã«ããã°ãïŒïŒ¯ïŒ°ïŒ¥ïŒ®ïŒïŒ£ïŒ¯ïŒ¢ïŒ¯ïŒ¬ã¯ããèªäœãã§ãã
æ¹æ³ã¯ããŸãååã®ïŒ£ã®ã³ã©ããããã°ã©ã ãã©ã€ãã©ãªãŒåœ¢åŒã«ããŸããå ·äœçã«ã¯åŒã³åºãå称ïŒããã§ã¯ïœïœïœïœïœïœïœïŒã確èªããå®è¡ããã°ã©ã ïŒïœïœïœïœãåé€ããŸãã
unsigned long collatz(unsigned long n);
åŽã§ã³ãŒã«ã³ãã³ããèšè¿°ããŸãã
>>D DISPLAY "WK_I: " WK_I
CALL 'collatz' USING BY VALUE WK_I RETURNING RTC
>>D DISPLAY "RTC: " RTC
ããã°ã©ã ãšäžç·ã«ã³ã³ãã€ã«ããŸãã
cobc -x -free collatz_c.cob collatz_cob.c
time ./collatz_c
ãã®çµæãæäžå³ã«ãªããŸãã
ðããåãããªãä»æ§
ããããããªã®ã§ããšèšãããã°ãããªã®ã§ããããšãããããšåçã®é«éæ§èœãåŒãåºããŠé¢ç®èºåŠãšãã£ããšããã§ããããããã©ããè ã«èœã¡ãªããä»åºŠã¯ãåã«ïŒãé£ç¶çã«å ããŠåºåããæ¹æ³ã§ãã³ãããŒã¯ããŠã¿ãŸãã
ããã°ã©ã ããšã®æéèšæž¬æ¹æ³ã«ïŒãªéšåãããã®ã§ãå¯èœãªéãå€éšãããæéèšæž¬ããŠã¿ãŸãã
ãŸããã§ãã
cobc -x -free cobbench.cob
time ./cobbench
次ã¯ãã§ãã
gcc cobbench.c -o cobbench_c
time ./cobbench_c
æåŸã«ãã®æ¯èŒå¯Ÿè±¡ãšãããããïœïœïœã§ãã
javac.exe Egg/CobBench.java
java Egg.CobBench
ïŒãçµæïŒãå éšèšæž¬æéïŒå€éšèšæž¬æéïŒïŒµïŒ³ïŒ¥ïŒ²ïŒïŒç·æéïŒïŒ²ïŒ¥ïŒ¡ïŒ¬ïŒã
ïŒãããïŒïŒïœïœïŒããïŒïŒïŒïœïœïŒãïŒïŒïŒïœïœ
ããããïŒããïŒïŒïŒïœïœïŒãããïŒïŒïœïœïŒãïŒïŒïŒïœïœ
ïœïœïœãïŒãïŒïŒïŒïŒïœïœïŒããããïŒïœïœïŒãããïŒïœïœ
ã³ã³ãã€ã«æéã¯èæ ®ããŠãŸããããç·æéããšå€§å·®ããªãã®ã§æ¯èŒçé«éã«èŠããŸãããããŠãïœïœïœã«å¯ŸããŠã¯å§åçã«é«éã«ããèŠãããŸãã
ãããããã®ããã°ã©ã ïŒã®äŒç»ïŒèªäœãæ ªåŒäŒç€ŸïŒ£ïŒ¯ïŒ¢ïŒ¯ïŒ¬ãšãããšããã«ãã£ãŠãªãããŠãããã®ã§ãããèªç€Ÿåºåãå«ãã ã€ã³ããã»ããªãã¯ãªããã°ã©ã ïŒèšç»ïŒã§ããå¯èœæ§ããããŸãã
ããã§ãã³ãã³ãã©ã€ã³ãžã®åºåããªãããŠã¿ãŸããæé©åãããªãããå ¥åãäžå®å€ã«ãããŸããããçµæã¯ã»ãŒåãã§ããã®ã§çç¥ããŸãã
ãŸããã§ãã
PROCEDURE DIVISION.
ACCEPT STIME FROM TIME.
PERFORM UNTIL CNT = 100000
ADD 1 TO CNT
*> DISPLAY CNT" TIMES EXECUTION."
END-PERFORM.
ã§ãã
do {
i++;
// printf("%7d times execution.\n", i);
} while (i < NUMBER);
ïœïœïœã§ãã
// loop
while (i < len) {
i = i + 1;
num = num + i;
sum = sum + num;
// System.out.println(i + "time's execution.");
}
ïœïœïœãå€éšæéèšæž¬ããŠã¿ãŸããã
pwsh.exe
Measure-Command {java Egg.CobBench}
ïŒãçµæïŒãå éšèšæž¬æéïŒãå€éšèšæž¬æéïŒèšïŒ
ïŒããããïŒïœïœïŒãããïŒïŒïœïœ
ããããïŒãããïŒïŒïœïœïŒããããïŒïœïœ
ïœïœïœãïŒããããïŒïœïœïŒããïŒïŒïŒïœïœ
æ®å¿µãªããããã®çµæããåããããšã¯äœããããŸããããå€éšèšæž¬æéã¯å®éã®æèŠã«è¿ããã®ã§ãããã²ãã£ãšãããïœïœïœã®æ¹ã¯ããããããèæ¯ç»åãšæªãããªããã¹ãã®å ããïœïœïœãåºããããŠïŒåãã«ããããŠããã®ãããããŸããâŠïŒå®éã«ã¯æ ªåŒäŒç€ŸïŒ£ïŒ¯ïŒ¢ïŒ¯ïŒ¬ã®æž¬å®çµæãšåçšåºŠã§ããïŒ
ïŒïŒé²æ°ãïŒïŒé²æ°ã«çŽããŠè¡šç€ºããããšãããšããã«ïŒªïœïœïœãšïŒ£ïŒ¯ïŒ¢ïŒ¯ïŒ¬ã®ãªã«ããã®å·®ç°ã¯ãããããããŸãããïŒãã€ãïŒïŒé²æ°ãªããããŒã¿ãäœåãªèšç®ãããã«çŽæ¥å€æã§ããŸããæ°å€ãå«ããããã¹ãã®ãã¡ã€ã«åŠçãåŸæããšããã®ã¯ãããããšããã«ããã®ã§ãããã
ãïœïœïœã«å¯ŸããŠé«éã«ãèŠããããšããã®ã¯ãããã¹ãåºåã«å¯Ÿããããããå«ã¿ãæãããè¡šçŸã§ãããã©ãããªãããããããèæ¯ç»åãããèŠããŠã¯ãããªãããã«ããèŠããŠãããâŠ
ïŒæã®ãã£ã¡ç³»ã¯ãåŸãããã¡ãã£ãšãèŠããããšããæããã§èŠ³æž¬ããã°ãèŠããããšãããããªç²Ÿç¥ä¿®è¡ã§ããâŠããããããŒãœãã«ã³ã³ãã¥ãŒã¿ã¯ããããçšéã®ããã®ãã·ã³ã ã£ãâŠãããïŒ
ðããŸã
å æ¥ãã§ïŒ¬ïŒ¡ïŒïŒ¢ïŒ€ïŒ¡é¢æ°ãäžè¬å ¬éããããšã®ããšã§ããã®ã§ãã§ãã³ã©ããäºæ³ããã£ãŠã¿ãŸããã
ç°¡åã«å³ã«ã§ãããšããã¯ïŒ¥ïŒžïŒ£ïŒ¥ïŒ¬ã®ã¡ãªããã§ããã
åæç¶æ³ããšãããŠã¿ãŸããããã ããã¥ãŒã倧ãããªããã¡ãªã®ã§é¢çœã¿ã«æ¬ ããŸãã
æ¹æ³ã¯æ¬¡ã®ããã«ããŸãã
ïŒïŒ¢ïŒ€ïŒ¡é¢æ°ã®äœææ¹æ³ïŒ
â æ°åŒãéžæã
â¡ååã®ç®¡çãéžæã
â¢æ°èŠäœæãéžæã
â£ååïŒä»»æïŒæ¬ã«ïŒ£ïœïœïœïœïœïœãšå ¥åã
â€åç §ç¯å²ã®ãšããã«ä»¥äžãå ¥åã
=LAMBDA(x, IF(x=1, 1, IF(MOD(x, 2)=0, (Collatz(x/2)+1), (Collatz(x*3+1))+1)))
åŒã³åºãåŽã®ã»ã«ã§ã¯ã
=Collatz(<ä»»æã®ãã³ããŒãŸãã¯ã»ã«ïŒ)
ãªããã
=MAP(<ä»»æã®ãã³ããŒãŸãã¯ã»ã«ãŸãã¯ã¢ã¬ã€ïŒ, Collatz)
ãšããã°åºåã§ããŸãã
ãŸããã³ã©ããäºæ³ã®æ¬¡ã®æ°ãæ±ãããã®ãäœã£ãŠã¿ãŸãããååã¯ïŒ£ïŒ¯ïŒ¬ïŒ¿ïŒ®ïŒ¥ïŒžïŒŽãªã©ãšããã°ããã§ãããã
=LAMBDA(x, IF(MOD(x, 2)=0, x/2, x*3+1))
ãããšåãããšã¯ãïŒïŒ¢ïŒ€ïŒ¡é¢æ°ä»¥å€ã®ãããŸã§ã®ãã®ã§ãåæ§ã«ã§ããŸãããïŒïŒ¢ïŒ€ïŒ¡é¢æ°ä»¥å€ã®æ¹æ³ãå¿çšããŠè¡šããäœæããããšãããšãæãã¬çœ ã«ã¯ãŸããŸããã¹ãããäžå®æ§ã®åé¡ã§ããäŸãã°ã次ã®ãããªåŒãèããŸãã
=IF(MOD(ROW(), 2)=0,INDIRECT(ADDRESS(ROW()/2, COLUMN()))+1, INDIRECT(ADDRESS(ROW()*3+1, COLUMN()))+1)
ããã¯ã¢ãã¬ã¹å€æŽäžå¯ã®ã¢ãã«ã§ã¯ãããŸããã工倫ãããã°ããã¯åé¡ãªããªããŸããåé¡ã¯ããã®æ¹æ³ã¯èª¿æ»ç¯å²ãååã§ãªããšããšãã©ãåã€ããã·ã³ãšããŠåäœããããšããããšã§ããäžå³ã®ããã«ãªããŸãã
äžçªå·Šã®ã€ã³ããã¯ã¹ãå ¥åå€ããã¹ãããæ°ãã¯åããŠæ¬åœã®çããå°ãåºããåã以éïŒïŒ£ã¯ïŒåç®ïŒã¯æ¢çŽ¢ç¯å²ãïŒïŒŸïœãšããŠäžèšåŒïŒãã ããå ¥åãïŒã®ãšãã¯ïŒïŒãåœãŠã¯ããçãã§ãã
ã©ããŸã§èª¿ã¹ããã©ã®ãããªããšã説æïŒèšŒæïŒã§ããã®ãããšããã®ã¯äºéåŠå®ã®é€å»ãèš±ããªãçŽèŠ³äž»çŸ©è«çãšæ·±ãé¢ããããããŸããèªå·±ãè¶ è¶ãã次ã®äžçã«ãããŠåããŠçŸäžçã®èªå·±ã説æã§ãããã©ããããšããå¯èœæ§ããã³ã©ããäºæ³ãå°é£ã«ããŠããåé¡ãšãããããã§ãã
åŒå ã§åŠçããããã«ã¯ãåŒäžã«ã¹ã¿ãã¯ãé©åã«åŠçã§ããèœåããªããã°ãªããŸãããã¹ã¿ãã¯ããç©ãã§ããªãšã³ããªãŒããŠãäžãããŠããªã¿ãŒã³ããŠãæåŸã®ã¹ã¿ãã¯ã®ãªã¿ãŒã³ãæ»ãå€ïŒçµæïŒã§ãããã®ã¹ã¿ãã¯ãä»®æ³çã«ååšãããããæ¹æ³ãããšã¯ã»ã«ã®ïŒ¬ïŒ¡ïŒïŒ¢ïŒ€ïŒ¡é¢æ°ãšããããã§ããåçã®ã¹ã¿ãã¯ãã·ã³ãååã«æåŸ ã§ããã®ã§ãããã§ãã¥ãŒãªã³ã°å®å šãšããããšã«ãªããŸãã
話ã¯å€ãããŸãããã¯ããã°ã©ãã³ã°èšèªãã©ããããšãã話é¡ããããŸããã²ãšã€é¢çœãèå¯ãäžããŠã¿ãŸãããã
äžèšã®åŒã¯ãè¥åŽããé çªã«èšç®ããã ããªãã°ãèšç®ãçµããªãéšåãæ®ããŸãããããã䜿çšããŠããã³ã³ãã¥ãŒã¿ãç°å¢ã«ããããŸããããªã³ã¯å ã«æŽæ°ããã£ãå Žåã¯å床èšç®ããæ°ããå€ãè¿ããŸãããããã»ã«ã®ã²ãšã€ã²ãšã€ããå éšã®å ¥åããåºåãç»é¢ã«è¿ãé¢æ°ãšããã°ããšã¯ã»ã«ã¯ãéåæããã€ãã»ã«ã®æ°ã ãçæããããã«ãã¹ã¬ãããããã³ããã«ããã£ã³ãã«ã®ããã°ã©ã ããšãããã®ã§ã¯ãªãã§ãããããäžèšã®ãåã€ããã·ã³ãã¯ãããã¯ïŒïŒïŒïŒã«ãªããŸã§ãã£ãŠã¿ãŸããããããããã®ã»ã«ãäœåºŠãã®æŽæ°ãæç¥ã»ååŸããåèšç®ããŠã¯æŽæ°ãâŠã®éçšãèªåã§è¡ã£ããã®ã§ãã
話ãæ»ããŸããããã®å ŽåãïŒïŒ¢ïŒ€ïŒ¡é¢æ°ãåãåããé¢æ°ã¯å€ãã¯ãããŸãããé åããé åãåãåºãé¢æ°ã䜿çšããŠã¿ãŸãã
=BYROW(A2:A2001,Collatz)
ä»åã¯å®éã«çšæãããæ°ã䜿çšããŠåãåºããŸãããããªã©ã€ã³ããã¯ã¹ã䜿çšããæ¹æ³ã§ãåé¡ãªãã§ããŸããïŒïŒ¡ïŒ°é¢æ°ã䜿çšããŸãã
=MAP(ROW(A1:A2001),Collatz))
ãã ãïŒïŒ¡ïŒ°ãšãã£ãŠããã®å Žåã¯ãé åã瞊æ¹åã«è¿ããŠããã®ã§ããã®ãŸãŸã ãšã»ã«ãæ¶è²»ããŸããããããäŸãã°æ¬¡ã®ããã«ããã°ãã»ã«ãæ¶è²»ãããïŒïŒ¢ïŒ€ïŒ¡é¢æ°ã®ã¡ãªããã¯çããŠããããã«æããŸãã
=MAX(MAP(ROW(A1:A2001),Collatz))
ðçµããã«
ä»åããããããããŠã¿ãŸããããçµæã¯æºè¶³ã§ãããã®ã§ããã§ããããïŒã³ã©ããäºæ³ãã¡ã€ã³ããŒãã§ããããªãã ãã䞻匵ã®èŠãã«ããèšäºã«ãªã£ãŠããŸããŸããã
ã³ã©ããäºæ³ã¯ãªãŒãã³äºæ³åæ§ã«ãå®å®ãè¶ ããããªã人éããšããåãçµãã§ããåé¡ã§ã¯ãªãã®ãããããŸããããã¡ã©å€åŽã®äžçããããšãããããåãããã«ç¡éã«ç¶ãèŠããªãäžçãããã«ãã«ããããšããæãã«ããªããšããŠãèŠãŠããããšããŠããã®ãããããŸããã
ã§ãã倧äžå€«ã
ç§ãã¡ã¯ãèŠããŠã¯ãããªãããã«ãèŠãè¡ããç¥ã£ãŠããŸããçãã¯ãã£ãšãããã«ããããŸãããã³ãâŠ
ïŒåèïŒè«çåŠã¯ããã§ããŸãããã¢ãã©ã«ããã©ã¯çãåœãïŒïŒ
âãïœããããŸããïœãâ