Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare
- local Yo Match Find Lp Hp Lq Hq Line Matrix Run P Q in
- P=[[0 1 0][0 1 0][1 1 1]]
- Q=[[1 0 0 1 1][1 0 1 0 1][0 0 0 0 1]]
- Lp={Length P.1}
- Hp={Length P}
- Lq={Length Q.1}
- Hq={Length Q}
- fun{Yo A B} %check une ligne de P avec une ligne de Q
- case A of H|T then
- if H==1 then
- if B.1==0 then {Yo T B.2}
- else no end
- else yes end
- else yes
- end
- end
- fun{Match P Q}
- case P of H|T then
- if {Yo H Q.1}==yes then {Match T Q.2}
- else no end
- else yes
- end
- end
- %................................................
- fun{Line L A B}
- local C in
- C={NewCell nil}
- for I in B..A;~1 do
- C:={Nth L I}|@C
- end
- @C
- end
- end
- %creation d'une sous matrice Q' dont les dimensions correspondent a celles de la matrice P, la premiere entree de Q' est situee aux positions (i,j)
- fun{Matrix Q I J}
- local C in
- C={NewCell nil}
- for K in I+Hp-1..I;~1 do
- C:={Line {Nth Q K} J J+Lp-1}|@C
- end
- @C
- end
- end
- %fonction parcourt l'entierete de Q pour trouver un bon endroit ou placer la matrice P
- fun{Run P Q I J}
- if I > Hq-Hp+1 then notfound
- else
- if J > Lq-Lp+1 then {Run P Q I+1 J}
- else
- if {Match P {Matrix Q I J}}==yes then found(I J)
- else {Run P Q I J+1} end
- end
- end
- end
- fun{Find P Q}
- {Run P Q 1 1}
- end
- {Browse {Find P Q}}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement