è«çããã°ã©ãã³ã°èšèªPROLOGïŒä»¥äž-PROLOGUEïŒã¯ãã»ãšãã©ã®ããã°ã©ããŒã«ãšã£ãŠãæ··ä¹±ãæããå®çšã«é©ããªããã®ã®ããã§ãã åæã«ãã€ã³ã¿ãŒãããã¯ã·ã³ããªãã¯æ
å ±ã«åºã¥ããŠãããããçŸä»£ã®ããã°ã©ããŒã®ã»ãšãã©ãã·ã³ããªãã¯ããŒã¿æ§é ãåŠçããå¿
èŠã«çŽé¢ããŠãããPROLOGUEè«çããã°ã©ãã³ã°èšèªã¯ãã®ããã«èšèšãããŠããŸãã ãã®èšèªã¯ãã·ã³ããªãã¯æ§é ãããã¹ããã¡ã€ã«ã®æäœãããã³ã€ã³ããªãžã§ã³ãããã°ã©ã ã®æ§ç¯ã«æé©ã§ãã
PROLOGUEã§ã®é·å¹Žã®ä»äºã®åŸãç§ã¯ãã¹ãŠã®èè
ãèªãããã«èšã-ãé«ããšã³ããªãŒãããå€ããšèšãæ°ãã絡ã¿åã£ãHaskellã«åºäŒããŸããã ç§ã®æèŠã§ã¯ããã®ãããå€ã®ãé«ããã¯ãæ··ä¹±ããæ§æãšçµã¿èŸŒã¿ããã·ãŒãžã£ã®ããŒãã®çµæãšããŠåœ¢æãããŸããã ãã®ãé«ããã®ãã1ã€ã®åå ã¯ãèªè
ãããã°ã©ã ãæžããããšããªããã®ããã«æžãããå€æ°ã®ããã¥ã¢ã«ã®èè
ã®æ
¢ãã§ãã
ç§ã¯ããã«ããã€ãã£ããããããŒã°ã«æ»ãããã£ã-ã·ã³ãã«ã§ããããããã 宣èšçã»ãã³ãã£ã¯ã¹ãªã©ã®å±±ãªãã§èª¬æããã°ããéåžžã®ãããã°ã©ããŒã®è«çããã°ã©ãã³ã°ã«å
¥ãæéã¯30åãè¶
ããªãã§ãããã
æç¶ãåããã°ã©ãã³ã°ã®èŠ³ç¹ãã説æããããšããŸãã
PROLOGUEã«ã¯ãæç¶ãåèšèªãšã®2ã€ã®äž»ãªéãããããŸããèšç®ãæŽçããæ¹æ³ãšããŒã¿ã衚瀺ããæ¹æ³ã§ãã èšèªã®ãããã®åŽé¢ã®äž¡æ¹ã¯ãåŸæ¥ã®ããã°ã©ãã³ã°èšèªãšæ ¹æ¬çã«ç°ãªããŸãã ããããè«çããã°ã©ãã³ã°ã¯ãã©ã³ãã€ãã³ã¢ãŒããã¯ãã£ãšåããã·ã³äžã§å®è£
ãããããšãå¿ããªãã§ãã ããã
ãã¹ãŠã®æäœãããã·ãŒãžã£ã®åŒã³åºãã«éå®ãããããã°ã©ãã³ã°èšèªãæ³åããŠãã ããã ããã«ãåããã·ãŒãžã£ã«ã¯ããã€ãã®ããªã¢ã³ããååšããããã°ã©ã èªäœããããã·ãŒãžã£ã®ãœãŒã¹ããŒã¿å®è£
ãªãã·ã§ã³ïŒæ¬äœïŒã®ç¹å®ã®ããªã¢ã³ãããšã«é©åãªãããæ£ç¢ºã«é©åãªãã®ãéžæããŸãã é©åæ§ã®å€ææ¹æ³-ããã·ãŒãžã£å®è¡ã®çµæã«å¿ããŠãããã°ã©ã å®è¡äžã®åããã·ãŒãžã£åŒã³åºãã¯ãè«çå€ïŒTRUEãŸãã¯FALSEïŒãåãåããŸãã åãååãšã¢ãªãã£ãæã€äžé£ã®ããã·ãŒãžã£ã¯ãè¿°èªãšåŒã°ããŸãã
PROLOGUEèšèªã®åè¿°èªã¯ã2ã€ã®ãã©ã¡ãŒã¿ãŒïŒååãšã¢ãªãã£ïŒã®ãã©ã¡ãŒã¿ãŒã®æ°ã«ãã£ãŠèå¥ãããŸãã ããšãã°ããªã¹ãéè¿°èªã¯nrev / 2ãšããŠèå¥ããããªã¹ãçµåè¿°èªã¯append / 3ã§ãã ãã©ã¡ãŒã¿ãŒãå€æ°ã®å®£èšã¯å¿
èŠãããŸãããããã©ã¡ãŒã¿ãŒãããã·ãŒãžã£ããããŒã®ãã¿ãŒã³ã«å¶éã§ããŸãã ããšãã°ãè¿°èªã®ããããªã¢ã³ãã§ã¯ãæåã®ãã©ã¡ãŒã¿ãŒã[]-空ã®ãªã¹ããå¥ã®ãã©ã¡ãŒã¿ãŒ-[AãBãC]-3ã€ã®èŠçŽ ã®ãªã¹ãã3çªç®ã®ãã©ã¡ãŒã¿ãŒã§[H | T]-空ã§ã¯ãªãä»»æã®ãªã¹ããšããŠæå®ã§ããŸãã
ããã·ãŒãžã£æ¬äœã®æ¡ä»¶ãæºããããªãå Žåãå®è¡ã¯åæ¢ããããã·ãŒãžã£åŒã³åºããããæ£ç¢ºã«ã¯ãããã·ãŒãžã£æ¬äœã®æ¬¡ã®ããŒãžã§ã³ã®å®è¡ãåæ¢ããå€FALSEãååŸãããŸãã ãã®å Žåãèšèªã€ã³ã¿ãŒããªã¿ãŒã¯ãã®ããã·ãŒãžã£ã®æ¬¡ã®ããã£ããªã¢ã³ããèµ·åããŸãã ãã¹ãŠã®ãªãã·ã§ã³ãäžé©åã§ããããšãå€æããå Žåãåã®æé ã«æ»ãããªãã·ã§ã³ãåæããŸãããããã£ãŠãPROLOGUEã®èšç®ã¯ãæé ã®å
¥ãåããªãŒãèµ°æ»ããããšã«ãªããŸãã
åã®åŒã³åºãã«æ»ãããšãããã¯ãã©ããã³ã°ãšåŒã³ãŸãã ãã£ã³ã»ã«ãããããã·ãŒãžã£ã®å€æ°ãåãåã£ããã¹ãŠã®å€ããã£ã³ã»ã«ããããããããã¯æ¬è³ªçã«ããŒã«ããã¯ã§ãã ããã¯ãã©ããã³ã°ã¯ããã®èšèªã®ãŠããŒã¯ãªããŒã«ã§ãããä»ã®äžè¬çãªããã°ã©ãã³ã°èšèªã«ã¯é¡ãèŠãŸããã ããã¯ãã©ããã³ã°ã¯ãæšè«ããªãŒãå®å
šã«ãã©ããŒã¹ããç¥çåé¡ã解決ããããã®åºç€ãæäŸããŸãã
PROLOGUEã·ã¹ãã ã§ããã°ã©ã ã解éããïŒç®æšãéæããïŒããã®ã¢ã«ãŽãªãºã ã
å
¥å£ïŒã¿ãŒã²ããpïŒA1ãA2ã...ãAnïŒ
1.ã¡ã¢ãªå
ã§ãã¢ãªãã£nã®pãšããååã®ããã·ãŒãžã£ãèŠã€ããŸãã
2.èŠã€ãã£ãããã·ãŒãžã£ã®èŠåºãã§ã¿ãŒã²ããã®å
¥åãã©ã¡ãŒã¿ãçµ±äžããŸãã
3.ãã©ã¡ãŒã¿ã®çµ±äžã«åæ Œããå ŽåãèŠã€ãã£ãããã·ãŒãžã£ã®æ¬äœããæåã®ç®æšãéæããŸãã
4.çµ±åããã¹ããªãå ŽåãP / nããã·ãŒãžã£ã®æ¬¡ã®ããŒãžã§ã³ãèŠã€ããŸãã
5. P / nããã·ãŒãžã£ã®æ¬¡ã®ããŒãžã§ã³ãèŠã€ãããªãå ŽåãFAILçµæãçµäºããŸãã
6.æåã®ç®æšãå®äºãããã次ã®ç®æšã«é²ã¿ãŸãã
7.次ã®ç®æšãéæãããªãå Žåã¯ãåã®ç®æšã«æ»ãããã®å®è£
ã®æ¬¡ã®ããŒãžã§ã³ãå®äºããŸãã
8. P / nããã·ãŒãžã£ã®çŸåšã®å®è£
ãªãã·ã§ã³ãå®äºããŠããªãå Žåã¯ã次ã®ãªãã·ã§ã³ã«é²ã¿ãŸãã
9.æé ã®æ¬äœã®ãã¹ãŠã®ç®æšãå®äºããããçµæãTRUEã«ãªãããã«äœæ¥ãçµäºããŸãã
ãã®èšç®æ§é ã«é¢é£ããŠãããã·ãŒãžã£ãžã®ååŒã³åºãã¯ãéæå¯èœãŸãã¯äžå¯èœãªç®æšãšåŒã°ããŸãã PROLOGUEã®ãã¹ãŠã®èšç®ã«ã¯è«ççãªæå³ããããŸãã èšç®ã¯æšè«ïŒèšŒæ ïŒã®æ€çŽ¢ãšãåŒã°ããèšèªPROLOGUEã¯è«çããã°ã©ãã³ã°ã®èšèªã§ãã
ããããæ§æäžãPROLOGUEã¯ããã°ã©ãã³ã°èšèªã®äžã§æãåçŽã§ãã äž»ãªæ§ææç¶ãã¯è¿°èªã§ã-æç¶ãåŒã³åºãã«äŒŒãåŒ-ååãšåŒæ°ãªã¹ã-
PïŒx1ã... xnïŒã ååã¯å°æåã§ãå€æ°ã¯å€§æåã§æžããŸãã
詳现ãçç¥ãããšãPROLOGUEæ§æã¯æ¬¡ã®ããã«èšè¿°ã§ããŸãã
<PROLOGUEå¥> :: = <ã«ãŒã«> | <äºå®> | <ãªã¯ãšã¹ã>
<ã«ãŒã«> :: = <head >>ïŒ-'<body>
<ãã¡ã¯ã> :: = <ããã> 'ã'
<ã¯ãšãª> :: = <body> 'ã'
<body> :: = <target> / 'ã' <target> / 'ã'
<head> :: = <è¿°èª>
<ã¿ãŒã²ãã> :: = <è¿°èª> | <åŒ>
<è¿°èª> :: = <åå> / 'ïŒ' <term> / 'ã' <term> / 'ïŒ' /
<term> :: = <atom> | <predicate> | <list>
<ã¢ãã > :: = <å€æ°> | <çªå·> | <æåå> | <åå>
<ãªã¹ã> :: = <ã¿ã€ãã«ä»ããªã¹ã> | <ã·ã³ãã«ãªã¹ã>
<ã¿ã€ãã«ä»ããªã¹ã> :: = '[' <term> / 'ã' <term> / '|' <term> ']'
<ã·ã³ãã«ãªã¹ã> :: = '[' <term> / 'ã' <term> / ']' | '[' ']'
<åŒ> :: = <çšèª> / <æŒç®å> <çšèª> /
<æŒç®å> :: = 'is' | '=' | '==' | '\ =' | '> =' | '= <' | '= \ =' |
æ§æãããããããã«ããisãè¿°èªãé€ããPROLOGUEã«ã¯äºçŽåã¯ãããŸããããããŸããŸãªçµã¿èŸŒã¿è¿°èªã䟿å©ã§å€éšç°å¢ãšã®éä¿¡ã«äœ¿çšãããŸãã
äŸã¯å®¶æé¢ä¿ã§ãã
é¢ä¿ã®ã«ãŒã«-é
å¶è
ãåäŸãæ¯èŠªãåšãå
åŒãåå«ãå®çŸ©ããŸãã 家æé¢ä¿ã¯ããã€ããªïŒåé
ïŒè¿°èª-ã«ãŒã«ïŒå€æ°ã䌎ãè¿°èªïŒããã³ãã¡ã¯ãïŒå®æ°ã䌎ãè¿°èªïŒã«ãã£ãŠå®çŸ©ãããŸãã 家æé¢ä¿ã¯èª°ã«ãšã£ãŠãæãããªã®ã§ãã«ãŒã«ã¯ç解ããããã§ãã ããšãã°ãæåã®ã«ãŒã«ã§ã¯ãYãXã®åã§Xã女æ§ã®å ŽåãXã¯Yã®æ¯ã§ãã
æ¯ïŒXãYïŒïŒ-åïŒXãYïŒã女æ§ïŒXïŒã
åšïŒXãYïŒïŒ-åïŒYãXïŒã女æ§ïŒXïŒã
å«ïŒXãYïŒïŒ-åïŒXãZïŒãåïŒZãYïŒã
åå«ïŒXãYïŒïŒ-åïŒXãYïŒã
åå«ïŒXãYïŒïŒ-å«ïŒXãZïŒã
äºå®ã¯ãç¹å®ã®å®¶æã®èŠªrelativeã説æããŠããŸãã
骚é«ïŒãžã§ã³ãã¡ãªïŒã 女æ§ïŒã¡ãªïŒã
åïŒãžã§ã³ããžã£ãã¯ïŒã åïŒã¡ãªããžã£ãã¯ïŒã åäŸïŒãžã§ã³ãã±ã€ãïŒã
骚é«ïŒãžã£ãã¯ããžã§ãŒã³ïŒã 骚é«ïŒã±ã€ãããã£ãã¯ïŒã
åäŸïŒãžã£ãã¯ããã³ãªãŒïŒã åïŒãã£ããããžã§ã·ã¥ïŒã
ç·æ§ïŒãžã§ã³ïŒã 女æ§ïŒã¡ãªãŒïŒã
ç·æ§ïŒãã³ãªãŒïŒã 女æ§ïŒãžã§ãŒã³ïŒã
ç·æ§ïŒãžã§ã·ã¥ïŒã ç·æ§ïŒãã£ãã¯ïŒã
1ã€ã®ã«ãŒã«ã»ããïŒããã°ã©ã ïŒãããŸããŸãªãã¡ã¯ãã»ããïŒããŒã¿ïŒã«é©çšã§ããŸãã
å¯èœãªã¯ãšãªã®ã»ããã¯ãæ¢åã®ã«ãŒã«ã®ã»ããã«ãã£ãŠæ±ºå®ãããŸãã åã«ãŒã«ã®ããããŒã¯ãã¯ãšãªãæ§ç¯ããããã®åºç€ã§ãã
ãªã¯ãšã¹ãã«ã¯ã確èªãšæ€çŽ¢ã®2çš®é¡ããããŸãã
æ€çŽ¢ã¯ãšãªã®äŸïŒ
ãã£ããã¯èª°ã®åšã§ããïŒ -åšïŒXããã£ããïŒã
ãã³ãªãŒã¯èª°ã®å«ã§ããïŒ -å«ïŒXããã³ãªãŒïŒ
ãã¹ããªã¯ãšã¹ãã®äŸïŒ
ãã£ãã¯ã¯ã¡ãªã®èµ€ã¡ããã§ããïŒ -åäŸïŒã¡ãªãŒããã£ãã¯ïŒã
PROLOGUEã®äž»ãªæŠå¿µïŒãªã¹ããååž°ãçµ±åãããã¯ãã©ãã¯ã ãªã¹ãã¯ããã®èšèªã§äœ¿çšãããäž»èŠãªããŒã¿æ§é ã§ãã ãªã¹ãã¯ããã¹ãŠã®è€éãªèšç®ãæŽçããããã®åºç€ã§ãã ãªã¹ãã®äž»ãªããããã£ã®1ã€ã¯ããªã¹ãã®èŠçŽ ãšãµã€ãºã«å¶éããªãããšã§ãã ãã¹ããªã¹ããäœã«ãéå®ãããŸããã èšèªã®ãªã¹ãã¯ããheadããšãtailãã®2ã€ã®èŠçŽ ã®æ§é ãšããŠè§£éãããŸãã ãã®åé¢ã¯ãªã¹ãã®èšç®ã®åºç€ã§ãããããæãäžè¬çã«äœ¿çšããããªã¹ããã¿ãŒã³ã¯[H | T]ã§ãã
ãªã¹ãã®æåã®èŠçŽ ã¯ä»»æã®æ§é ãæã€ããšãã§ãã2çªç®ã®èŠçŽ ããªã¹ãã§ãã 空ã®ãªã¹ãã«ã¯èŠçŽ ãå«ãŸããŠãããã[]ãšããŠç€ºãããŸãã
èšèªã®2çªç®ã®åºæ¬æ§é åäœ-è¿°èªã®åœ¢åŒã¯-pïŒA1ãA2ã..ïŒã§ãã è¿°èªã¯ãããŒã¿ã1ã€ã®ã»ãã³ãã£ãã¯åäœã«ã°ã«ãŒãåããã®ã«äŸ¿å©ã§ãã ãªã¹ããšã¯ç°ãªããè¿°èªåŒæ°ã®æ°ã¯åºå®ãããŠããŸãã è¿°èªã®ååã¯å€§æåã§ãèšèªã®ãã¹ãŠã®å®æ°ã倧æåã§ãã
å€æ°ã¯åžžã«å€§æåã§å§ãŸããŸãã å€æ°ã«åºã¥ããŠããªã¹ãã®ãã¿ãŒã³ãäœæã§ããŸãã
ãªã¹ããã¿ãŒã³ã®äŸïŒ
[H | T]ã¯ç©ºã®ãªã¹ãã§ã¯ãããŸããã
[]-空ã®ãªã¹ãã
[A1ãA2ãA3]-3ã€ã®ä»»æã®èŠçŽ ã®ãªã¹ãã
[AãAãA | T]-æåã®3ã€ã®èŠçŽ ãäžèŽãããªã¹ãã
[xã10 | T]-èšå·å®æ°ãxããæåã«ãããæ°å€å®æ°10ã2çªç®ã«ãããªã¹ãã
ãªã¹ãæ§é ã®ååž°çæ§è³ªã¯ãååž°çã³ã³ãã¥ãŒãã£ã³ã°ãç·šæããäžã§éèŠãªèŠçŽ ã§ãã ååž°è¿°èªã«ã¯ãå°ãªããšã2ã€ã®æé ããããŸã-1ã€ã¯äžè¬çãªå Žåããã1ã€ã¯å®äºçšã§ãã
ãªã¹ãã®ååž°æ§ã«ããããªã¹ãã«å¯Ÿããæäœã®ã¢ã«ãŽãªãºã ãç°¡åã«å®åŒåã§ããŸãã
äŸïŒãªã¹ãã®é·ããèšç®ããŸãã
é·ãïŒ[H | T]ãNïŒïŒ-é·ãïŒTãN1ïŒãNã¯N1 + 1ã§ãã
é·ãïŒ[]ã0ïŒã
äŸïŒãªã¹ãã®å転ã
nrevïŒ[H | T]ãLïŒïŒ-nrevïŒTãL1ïŒãè¿œå ïŒL1ã[H]ãLïŒã
nrevïŒ[]ã[]ïŒã
PROLOGUEã«ã¯é¢æ°ããªãããããã¹ãŠã®æç¶ãåèšèªã§è¡ãããŠããããã«ãããšãã°ããªã¹ãã®é·ãïŒLïŒãåŒæ°ãšããŠæ¿å
¥ããããšã¯ã§ããŸããã
åæã«ãPROLOGUEã¯ã远跡ãé€ããã¹ãŠã®æäœãæ瀺çã«èšè¿°ãããå®å
šã«åœä»€çãªèšèªãšèŠãªãããšãã§ããŸãã
äžèŠçµ±äžããããšã§ãããçš®ã®è¬ãšäžå¯è§£ããèšèªã«å°å
¥ãããŸãããå®å
šã«æç¶ãçãªèª¬æããããŸãã
çµ±åã¯ããã©ã¡ãŒã¿ããã¿ãŒã³ã«çœ®æããããšã§ãããå
¥åãã©ã¡ãŒã¿ãéžæããã ãã§ãªããç®çã®ãªã¹ãã¢ã€ãã ãèªåçã«éžæããŠæäœããããã«ã䜿çšãããŸã-ãªã¹ãã®ãããèŠçŽ ãè¿œå ããã³åé€ããŸãã
äŸïŒãªã¹ããçµåããŸãã
è¿œå ïŒ[H | T]ãLã[H | L2]ïŒïŒ-è¿œå ïŒTãLãL2ïŒã
è¿œå ïŒ[]ãLãLïŒã
2çªç®ã®åŒæ°ã¯ãªã¹ãã§ããå¿
èŠãããããã2çªç®ã®åŒæ°ã[H1 | T1]ã®åœ¢åŒã§èšè¿°ããæ¹ãé©åã§ããã2çªç®ã®åŒæ°ã空ã®ãªã¹ãã«ãªãå¯èœæ§ããããããè¿°èªãè€éã«ãªããŸãã
PROLOGUEã®å€æ°ã¯è«ççã§ãã åãæé å
ã§ç¹°ãè¿ãçµ±äžããããšã¯äžå¯èœã§ãã L = [aãbãc]ããããŠL = [12]ãšæžãããšã¯ã§ããŸããã 1ã€ã®ããã·ãŒãžã£ã®æ¬äœå
ã®ãã¹ãŠã®çµ±äžã¯èšç®ããã»ã¹äžã«ä¿®æ£ã§ããªããããå€æ°ã®è«çã¯çµ±äžãè€éã«ããŸããã€ãŸããäºãã«ççŸããããšã¯ã§ããŸããã
è«çå€æ°ã®çµ±åã¯ãå®å
šã«åœä»€çãªèª¬æãæã€äºæããªãå¹æããããããŸãã
äŸïŒãªã¹ãçµåè¿°èªã®ãŠãŒã¹ã±ãŒã¹ã
æ¥ç¶ïŒ
è¿œå ïŒ[aãbãc]ã[dãeãf]ãLïŒã
L = [aãbãcãdãeãf] =>
ã¯ãã
ãªã³ã¯ãªã¹ãã®æ€èšŒïŒ
è¿œå ïŒ[aãbãc]ã[1,2,3]ã[aãbãcã1,2,3]ïŒã
ã¯ãã
ãªã¹ãå±éïŒ
è¿œå ïŒL1ãL2ã[aãbãc]ïŒã
L1 = [aãbãc]
L2 = []->;
L1 = [aãb]
L2 = [c]->;
L1 = [a]
L2 = [bãc]->;
L1 = []
L2 = [aãbãc]->;
ãã
ããã§ãã;ãèšå·ã¯ãããã¯ãã©ããã³ã°ãéå§ããŠå¥ã®ãœãªã¥ãŒã·ã§ã³ãèŠæ±ããããšãæå³ããŸãã
æžç®ãªã¹ãïŒ
è¿œå ïŒ[aãb]ãLã[aãbãcãd]ïŒã
L = [cãd]ã
PROLOGUEã§ã¯ãããã¯ãã©ããã³ã°ã䌎ãèšç®ïŒé決å®çïŒãšããã䌎ããªãèšç®ïŒæ±ºå®çïŒãåºå¥ããã®ãæ
£ç¿ã§ãã
é決å®çè¿°èªã®äŸïŒæ°å€ããºã«ã解ãã
/ *
ããã«ã
+
ãžã§ã©ã«ã
-ãããŒã* /
åèšïŒL1ãL2ãL3ïŒïŒ-
sum1ïŒL1ãL2ãL3ãL1ãL2ãL3.0ã[0,1,2,3,4,5,6,7,8,9]ïŒã
sum1ïŒL1ãL2ãL3ãL11ãL12ãL13ãIiãLvïŒïŒ-
dlïŒL11ãL111ãE1ïŒã
dlïŒL12ãL121ãE2ïŒã
dlïŒL13ãL131ãE3ïŒã
valïŒE1ãLvãLv1ïŒãvalïŒE2ãLv1ãLv2ïŒãvalïŒE3ãLv2ãLv3ïŒã
sdïŒE1ãE2ãE3ãIiãIoïŒã
sum1ïŒL1ãL2ãL3ãL111ãL121ãL131ãIoãLv3ïŒ
sum1ïŒL1ãL2ãL3ã[]ã_ã_ã0ã_ïŒïŒ-ïŒ..
dlïŒ[H | T]ã[H | T1]ãEïŒïŒ-dlïŒTãT1ãEïŒã
dlïŒ[H]ã[]ãHïŒã
valïŒEãLãLïŒïŒ-nonvarïŒEïŒã
valïŒEãL1ãL2ïŒïŒ-delïŒEãL1ãL2ïŒã
sdïŒAãBãCãIiãIoïŒïŒ-
C1ã¯A + B + Iiã
Cã¯C1 mod 10ã
Ioã¯C1 // 10ã
delïŒEã[E | T]ãTïŒã
delïŒEã[H | T]ã[H | T1]ïŒïŒ-delïŒEãTãT1ïŒã
sïŒ-
A1 = [DãOãNãAãLãD]ã
A2 = [GãEãRãAãLãD]ã
A3 = [RãOãBãEãRãT]ã
åèšïŒA1ãA2ãA3ïŒã
æžã蟌ã¿ïŒA1ïŒãnlã
æžã蟌ã¿ïŒA2ïŒãnlã
æžã蟌ã¿ïŒA3ïŒãnlã
è¿°èªsum / 3ã¯ãäžããããæååŒã®æ°å€ãéžæããåºæ¬æäœãå®è¡ããŸãã èšç®ã¯ãä»»æã®é·ãã®2ã€ã®æ°å€ãè¿œå ããããã®æ°åŒã«å¯ŸããŠå®è¡ãããŸãã æ¢ç¥ã®çªå·ãããå Žåã¯ãå€æ°ã®ä»£ããã«ããããæ¿å
¥ã§ããŸãã çšèªã®é·ããç°ãªãå Žåã察å¿ãããªã¹ãã®å
é ã«ãŒããæ¿å
¥ã§ããŸãã
è¿°èªsum1 / 8ã¯ãæåã®3ã€ã®åŒæ°ã䜿çšããŠçµæãæžã蟌ã¿ãŸãã4ã5ã6ã®çªå·ãä»ããããåŒæ°ã¯äœæ¥å€æ°ã7çªç®ã®åŒæ°ã¯æ¡äžãã®åæå€ã8çªç®ã®åŒæ°ã¯æå¹ãªæ°åã®ãªã¹ãã§ãã
dl / 3è¿°èªã¯ãå€æ°ã®ãªã¹ãããæåŸã®èŠçŽ ãéžæããŠåé€ããŸãã
è¿°èªval / 3ã¯æ®ãã®ãªãã·ã§ã³ã®ãªã¹ãããæå¹ãªå€ãéžæããŸãããéžæãããæ°åãªãã·ã§ã³ã¯æå¹ãªãªãã·ã§ã³ã®ãªã¹ãããåé€ãããŸãã
次ã®æåã®å€ãªãã·ã§ã³ã以åã«èšå®ãããŠããå Žåãå€æŽãããŸããã
sd / 5è¿°èªã¯ã1ã€ã®åã®æå®ããã3æ¡ã®æ°åã®ããªã¢ã³ãããã§ãã¯ããŸãã
A + B + Ii = C + Io * 10
sd / 5ã倱æãããšãããã¯ãã©ããã³ã°ãçºçããŸã-è¿°èªã®æåŸã®åŒã³åºãval / 3ã¯ãå€æ°E3ã«æ°ããå€ãå²ãåœãŠãŸãã ã©ã®E3å€ãé©åããªãå Žåãããã¯ãã©ããã³ã°ã¯1ã¹ãããæ»ããŸã-E2ã«æ°ããå€ãéžæããã次ã«-ãªãã·ã§ã³E3 E2ãE1ã«é©åã§ãªãå Žåã
è¿°èªsum1 / 8ã¯ãå
¥åå€æ°ãªã¹ãã䜿ãæãããããŸã§ååž°çã«å®è¡ãããŸãã
s / 0è¿°èªã¯ãsum / 3è¿°èªãåŒã³åºããŠ1ã€ã®ããºã«ããªã¢ã³ãã解決ããäŸã§ãã
ãã®äŸãããããããã«ãPROLOGUEããã°ã©ã ã¯éåžžã«ã³ã³ãã¯ãã«ã§ããŸãããæé»çãªé¢æ°åŒã³åºãã¯äœ¿çšãããªããããã¢ã«ãŽãªãºã ã¯ã·ã³ãã«ã§ééçã§ãã
ãã®ãããªããºã«ã解ãããã®ããã°ã©ã ãéçºããããšãã§ããŸããããšãã°ããã¹ãŠã®ã¿ã€ãã®æ°å€ããºã«ã«ã€ããŠãå
¥åããŒã¿ãæ¹åãããªã©ãæ®éçãªãã®ã«ããããšãã§ããŸãã
ãããè¡ãã«ã¯ãåå¥è§£æã解æãªã©ã®æäœãè¡ãå¿
èŠããããŸãã ãããã®æäœã«ã€ããŠã¯ã第2éšã§æ€èšããŸãã