memory 0 export solution min 1 global cnt export cnt as mut f64 ; solves knight tour problem func knight export knight param x as i32 and y as i32 and lv as i32 result i32 local pos as i32 code getglobal cnt dconst 1 dadd setglobal cnt ; bound check get x iconst 8 iges get x iconst 0 ilts ior get y iconst 8 iges get y iconst 0 ilts ior ior if iconst 0 return end ; get array index get x get y iconst 3 ishl iadd iconst 2 ishl set pos ; test if a square is visited get pos iload align 4 if iconst 0 return end get pos get lv istore align 4 ; test if finished get lv iconst 64 iges if iconst 1 return end block get lv iconst 1 iadd set lv ; try every direction get x iconst 1 iadd get y iconst 2 iadd get lv call knight brif 0 get x iconst 2 iadd get y iconst 1 iadd get lv call knight brif 0 get x iconst 2 iadd get y iconst m1 iadd get lv call knight brif 0 get x iconst 1 iadd get y iconst m2 iadd get lv call knight brif 0 get x iconst m1 iadd get y iconst m2 iadd get lv call knight brif 0 get x iconst m2 iadd get y iconst m1 iadd get lv call knight brif 0 get x iconst m2 iadd get y iconst 1 iadd get lv call knight brif 0 get x iconst m1 iadd get y iconst 2 iadd get lv call knight brif 0 ; no moves get pos iconst 0 istore align 4 iconst 0 return end iconst 1 end