ãã°ã®ãªãããã°ã©ã ã®æ¸ãæ¹
ä»åãã¡ãã£ã¨æè¿æãã¨ãããæç« ã«ãã¦ã¿ããããã¡ããã¡ãç²ããã
é£ããããããããªããããã¼ããªã§ãã«ãªã£ã¦ãã¾ã£ãã
â¦ãããããã
ãã°ã®ãªãããã°ã©ã ã®æ¸ãæ¹
çªç¶ã§ããããããã°ã©ã ã«ã¯ãã°ãä»ãç©ã ã
ããããã«ãçµ±åéçºç°å¢ã«ã¯GUIãããã¬ãã¤ãã¦ããããã¦
ããã°ã©ã ã®å¦çã追ãããããªã£ã¦ãããã
ãã¹ãã±ã¼ã¹ãæ¸ããããã¦é¨åçã«ãã°ã®çºçãå¶å¾¡ãããããã
ã ããããã¯æ¬å½ã ããã?
ãã£ã¨å¥ã®æ¹æ³ã§ãã°ã®çºçèªä½ãæå¶ã§ããªãã®ã ãããã
ããã®ã¨ããç§ã¯ãã®ãã¨ã°ãããèãã¦ããã
Haskellãã¯ãããã®ããã®ããã ã
ããã¦ããã¯ç§ã®ä¸ã§ãããããçµè«ã«éãã¤ã¤ããã
(ãã¼ãããããªæ·±é ãªãã¼ãã«è»½ã
ããçµè«ãªã©ã¨è¨ã£ã¦ãããã®ã)
ããã§ãçµè«ããè¨ãã°ããã°ãæããæ¹æ³ãããã®ã¯ééããªãã
å®éã«æè¿ç§ãæ¸ã(C++ã®)ã³ã¼ãã®ãã°çºççã¯ä»¥åã¨æ¯ã¹ã¦
èããä½ä¸ããããã®å¤åã£ã·ãã«èªåã§ãé©ããã¨ãã°ãã°ãªã®ã ã
ãã¯ããªã«ãã³ããããã®ã ããã
ã§ã¯ããã®ã³ãã¨ã¯ãªãã ããã?
ç§ã®åã³ã¼ãã®ãã°ãå°ãªããªã£ãææãèãã¦ã¿ãã¨ã
ã©ãããã¨ãããããã¯ãã¨ããããHaskellãåå¼·ãã¦ããææã¨ãã¶ãããã ã
Haskellã§ã®ã³ã¼ãã£ã³ã°ã¹ã¿ã¤ã«ãC++ã§ã®ã³ã¼ãã£ã³ã°ã«ãå½±é¿ãä¸ãã
ãã®çµæãã°ã®åºã«ããã³ã¼ããæ¸ããããã«ãªã£ããã ãããã
ããããããã¯ãã¾ãã«ãæ½è±¡çã§ããã
ãã£ã¨å
·ä½çã«ä½ãã©ã®ããã«å¤ããã®ã?
ãããåããã°ãã°ã®ãªãããã°ã©ã ãæ¸ãããã®ä¸å©ã¨ãªããããããªãã
ããã«å¯¾ããç§ã®è¦è§£ã§ããããä¸è¨ã§è¨ã£ã¦ãã¾ãã°ã
ãç¡çãããªããã§ããã
ãããããã¨ã«ã¤ãã¦ç¡çãããªãã
ç¡çãããã«èªæãªã³ã¼ãã ãæ¸ãã¦ããã°ãã°ã®å
¥ãä½å°ããªããªãã
Haskellãããã ãã¦ããç´°ãããã¨ãæ¸ããªããªã£ã
(æ¸ããããªããªã£ã)ããããããã¨ãæ¸ãã°ããã®ã§ããã
ããã¯ããæå³ã§å¯è±ªçããã°ã©ãã³ã°ã«éããã®ã§ãããã
ä»åã®è©±ã¯å¯è±ªçã¨ããã¨ããã«ã¨ã©ã¾ããªãã
å¾¹åºçã«é¦å°¾ä¸è²«ãã¦æãæãã¨ããã®ã§ããã
éã«è¨ãã¨ãæãæãããã«ææ
®æ·±ããªããã¨ãããã¨ã ã
ããã°ã©ã ãæ¸ãåã«ãã¡ãã£ã¨å¾
ã£ãã
ãã£ããã¨èããå·¡ããã¦ãã£ã¨ç°¡ç´ ã«ãããªãããèããã
ããã§è¨ãç°¡ç´ ã¨ããã®ã¯ããã°ã©ã ã®é·ãã§ã¯ãªãã
ã³ã¼ãåããéã«ãããã«èããä½å°ãå
¥ããªããã§ããã
ããã§ããã¾ãã«æ½è±¡çã§ããã
å
·ä½çã«èããä½å°ãæ¸ããã¬ã¤ãã©ã¤ã³ãèãã¦ã¿ãã
Haskellã¨C++ã§ã®éãã§ãããããã¯ããã£ã¨ã大ããªéãã¯
ç´ç²é¢æ°çã¨ãããã¨ã ããã
ããã°ã©ã ãç´ç²é¢æ°çã§ãããªãã°ã
å
¥åã«ããåºåã決ã¾ãã®ã§ãã°ã®å
¥ãä½å°ã¯å§åçã«
å°ãªããªãã¯ãã§ããã
ãã®æãããã®ã¨ãã¦ãå¤æ°ã«ä»£å
¥ã許ããªãã
ãããC++ã§ããªãã¹ãå®ãããã«ããã
ãã¡ãããC++ã§å¤æ°ã«ä»£å
¥ãããã«ããã°ã©ã ãä½ãã®ã¯
ã¨ã¦ãé£ãããã ãããå®å
¨ã«æé¤ããã®ã§ã¯ãªãã¦ã
代å
¥ã«ãã£ã¦ããã°ã©ã ã®è¦éããæªããªããªãããã«å¿æããã
ããã°ã©ã ã®é¢ããå ´æã§åãå¤æ°ã«ä»£å
¥ãè¡ããªãã¨ãã
å¤æ°ã®å
容ãææ¡ãããããã°ããããã»ã©
ããã°ã©ã ããèããä½å°ã¯æ¸ãã¨æãã
åããããªçç±ã§å¤æ°ã®çååºéãå°ããããã®ãæå¹ã ããã
åãå¤æ°ããããããªã¨ããã§ä½¿ããªãã®ãéè¦ã ã
ãã£ã¨ç´æ¥çãªé¢æ°çãªèãæ¹ã¨ãã¦ã¯ã
å帰çãªã¢ã«ã´ãªãºã ãç¹°ãè¿ãã«å¤æããªããã¨ããã®ãããã ãããã
å帰çãªé¢æ°ã¨ç¹°ãè¿ãã«å¤æãããã®ã§ã¯
ããã¦ãå帰çãªé¢æ°ã®ã»ããç解ããããææ¡ããããã
int gcd_r(int a,int b) { if (a%b==0) return b; else return gcd_r(b,a%b); } int gcd_i(int a,int b) { while(a%b!=0){ int c=b; b=a%b; a=c; } return b; }
ãã¨ãã°ãGCDãªããä¸ã®å帰çã¯ã¾ã£ããã®å®ç¾©ã®éãã§ã
æ£ãããã¨ã¯èªæã§ãããã
ç¹°ãè¿ãçã¯æ³¨ææ·±ãèªã¾ãªãã¨æ£ãããã¨ãåãããªãã
é度ã®åé¡ããããããããªãããç¹°ãè¿ãã«å¤æã§ãã
å帰é¢æ°ãªãã°ããããå®æ°åã§ããã
æ¬è³ªçã«åé¡ã¨ãªãã®ã¯ãå¼ã³åºãåæ°ããã¾ãã«ãå¤ããªã£ãã¨ã
ã¹ã¿ãã¯ãããµãããããããªããã¨ãããã¨ã§ãããã
ãã®ã¨ãã¯ç¢ºãã«ä»æ¹ããªãã
ããããé常ã¹ã¿ãã¯ã¯æ°MBåå¨ããã®ã§ã
ã¹ã¿ãã¯ãã¬ã¼ã ã§å¼ã³åºãä¸åãããæ°åBæ¶è²»ãããã¨ãã¦ã
åä¸åã¯å¼ã³åºããè¨ç®ã«ãªãããã®ãªã¼ãã¼ã®å帰åæ°ã
å¿
è¦ã«ãªãã¢ã«ã´ãªãºã ã¯ãªããªããªãã
(ãããã¯ãããã§ããã³ã³ãã¤ã©ãªãæ«å°¾å¼ã³åºãã®
æé©åãæå¾
ã§ãããããããªããVCã§ã¯æ«å°¾å帰å¼ã³åºã
ã ããªãä½ã¨ãããã°ã£ã¦ããã¦ãããããªæ°ãããã
ã¾ããæé©åãã¦ãããªããã®ã¨èãã¦ããã®ãæ£è§£ãããããªãã)
ã»ãã«ã¯ãDPãå®è£
ããã¨ãããããå
ã®å帰çãªã¢ã«ã´ãªãºã +
ãã£ãã·ã¥ã¨å®è£
ããã»ãããã¼ãã«ãçµç¹çã«åãã¦ããããã
楽ãªå ´åãå¤ãããã¼ãã«ãçµç¹çã«åããã«ã¯
æ·»ãåã®åé¡ãé åºãªã©ãããããã¨ç¥çµã使ããã¨ãå¤ãã
ãã¯ãèæ
®ãã¹ããã¨ã¯å°ãªããã°å°ãªãã»ããããã
å¾ã¯ãæè¿ã§ã¯å½ããåã§ãããã
é
åãæååãå¤ã¨ãã¦æ±ããã¤ã¾ãC++ã§ãã£ã¦ã
é
åããã¤ã³ã¿ã§æããªãã¨ãããã¨ã ã
(é
åã¯ã¨ããã)æååããã¤ã³ã¿ã§æã¤ã¨ãããã¡é·ãªã©
ããã¾ãè²ã
ã¨ç¥çµã使ããè¦ããã«ã³ã³ããã使ãã¨ãããã¨ã ã
ã¨ã¾ãã(ããããã¨èãã¦ã¯è¦ããã®ã®)
ããã¾ããããããã¨ã¯æ¸ããªãã£ããã
ãã¯ãããããã³ããããã®ã¯ééããªãã
æè¦çã«ããããã®ãããã®ã¯åããã®ã ãã
æç« ã«ããã®ã¯ã¨ã¦ãé£ããã
ä»åãè¨ããããã¨ãã»ã¨ãã©æ¸ãã¦ããªãã®ã ãã
ããã ãã¯è¨ãããé¢æ°åè¨èªãåå¼·ãããã¨ã«ãã
ããããèãæ¹ãC++ã§ã®ã³ã¼ãã£ã³ã°ã«ãå½±é¿ãåã¼ãã¦ããã®ã ã
(C++ãHaskellã使ãæ¹ã§ãåããããªèãã®äººã¯å±
ããã¾ãããâ¦?)