è¿·è·¯ã®è©¦é¨åé¡ã解ãã¦ã¿ã
åèï¼人材獲得作戦・4 試験問題ほか: 人生を書き換える者すらいた。
Lv4ã«è©ä¾¡ãããããã«ã¯ãæçæ§ã®å®å
¨ãªãã§ãã¯ãå¿
è¦ã ã£ãã®ã§Coqã§è¨¼æãã¦ã¿ãã
ã¾ããaccessiblesã¨ããé¢æ°ãå®ç¾©ãã以ä¸ã®æ§è³ªã証æããã
ããã§plengthã¯ãã¹ã®é·ããè¨ãé¢æ°ã§ãPath x pã¯pãxãèµ·ç¹ã¨ãããã¹ã§ããã¨ããè¿°èªãendofã¯ãã¹ã®çµç¹ãæ±ããé¢æ°ã
Fixpoint accessibles (start : node) (len : nat) : list path := match len with | O => (PUnit start) :: nil | S n' => div_equiv path_equiv_dec @@ (flat_map expand @@ accessibles start n') end.
ãã®é¢æ°ã¯startããå§ã¾ã£ã¦lenã®é·ãã®ãã¹ãå°éã§ããç¹(ãçµç¹ã¨ãããã¹)å ¨ä½ãè¿ãé¢æ°ã表ç¾ãã¦ããã
Theorem soundness : forall x n p, In p (accessibles x n) -> Path x p /\ plength p = n.
ãã®å®çã¯ããªã¹ã(accesibles x n)ã®ãã¹ã¦ã®å pã¯Path x pãã¤é·ããnã§ããããã¨ãããã¨ãè¨ã£ã¦ããã
Theorem completeness : forall x p, Path x p -> exists p0, endof p = endof p0 /\ plength p = plength p0 /\ In p0 (accessibles x (plength p)).
ããã¯ãxããã®ãã¹pãåå¨ãããªãã°ãpã¨åãçµç¹ã«ãã©ãçããpã¨åãé·ãã§ãããããªp0ã(accesibles x (plength p))ã®ä¸ã«åå¨ããããã¨ãããã¨ã
åæ¢ããªãå¦çãCoqã§è¨è¿°ã§ããªããããçµæãç¡éãªã¹ãã¨ãã¦å®ç¾©ããOCamlã«æ¸¡ãããOCamlå´ã§ã¯ç¡éãªã¹ããé çªã«è¦ã¦ããã解ãããã°åºåããã
ä¸è¨ã®å®çããããã¹ã®é·ãã«é¢ãã¦åä¸è¦ããã¨ãã¹ã¦ã®ã´ã¼ã«ã¸ãã©ããã¹ã¯å¾ãããç¡éãªã¹ãã«å«ã¾ãã¦ãããç¡éãªã¹ãã¯çãé ã«ä¸¦ãã§ããããã£ã¦ç¡éãªã¹ããé çªã«ã¿ãçµæè¦ã¤ãã£ã解ãæçã§ãããã¨ãä¿è¨¼ãããã
ã½ã¼ã¹ã³ã¼ãå
¨ä½ã¯ä»¥ä¸ã
http://bitbucket.org/yoshihiro503/maze_solver/src/
å®è¡çµæ
$ cat input.txt ************************** *S* * * * * * * ************* * * * * ************ * * * * ************** *********** * * ** *********************** * * G * * * *********** * * * * ******* * * * * * **************************
$ time ./run < input.txt ************************** *S* *$$$$$ * *$* *$ * $************* * *$*$$$* $$************ * *$$$ * $$$$$ * **************$*********** * $$$$$$$$$$$$$ * **$*********************** * $$$$$*$$$$$$$$$$$$$$G * * * $$$ *********** * * * * ******* * * * * * ************************** real 0m0.129s user 0m0.124s sys 0m0.000s