Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 1.42 KB | None | 0 0
  1. declare
  2. local Yo Match Find Lp Hp Lq Hq Line Matrix Run P Q in
  3.    P=[[0 1 0][0 1 0][1 1 1]]
  4.    Q=[[1 0 0 1 1][1 0 1 0 1][0 0 0 0 1]]
  5.    Lp={Length P.1}
  6.    Hp={Length P}
  7.    Lq={Length Q.1}
  8.    Hq={Length Q}
  9.  
  10.    fun{Yo A B} %check une ligne de P avec une ligne de Q
  11.       case A of H|T then
  12.      if H==1 then
  13.         if B.1==0 then {Yo T B.2}
  14.         else no end
  15.      else yes end
  16.       else yes
  17.       end
  18.    end
  19.    
  20.    fun{Match P Q}
  21.       case P of H|T then
  22.      if {Yo H Q.1}==yes then {Match T Q.2}
  23.      else no end
  24.       else yes
  25.       end
  26.    end
  27. %................................................
  28.    fun{Line L A B}
  29.       local C in
  30.      C={NewCell nil}
  31.      for I in B..A;~1 do
  32.         C:={Nth L I}|@C
  33.      end
  34.      @C
  35.       end
  36.    end
  37.    
  38.    %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)
  39.    fun{Matrix Q I J}
  40.       local C in
  41.      C={NewCell nil}
  42.      for K in I+Hp-1..I;~1 do
  43.         C:={Line {Nth Q K} J J+Lp-1}|@C
  44.      end
  45.      @C
  46.       end
  47.    end
  48.    %fonction parcourt l'entierete de Q pour trouver un bon endroit ou placer la matrice P
  49.    fun{Run P Q I J}
  50.       if I > Hq-Hp+1 then notfound
  51.       else
  52.      if J > Lq-Lp+1 then {Run P Q I+1 J}
  53.      else
  54.         if {Match P {Matrix Q I J}}==yes then found(I J)
  55.         else {Run P Q I J+1} end
  56.      end
  57.       end
  58.    end
  59.    fun{Find P Q}
  60.       {Run P Q 1 1}
  61.    end
  62.    {Browse {Find P Q}}
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement