fork(3) download
  1. ((y,z):l)&(w,x)|x*y<1=(w+y,x+z):l
  2. (q:l)&p=p:q:l
  3. (p@(u,v):r@(y,z):l)%q@(w,x)=[((y-w,z):l)&q&(u,v-x)|w<=y,x<=v]++[p:m|m<-(r:l)%q]
  4. _%_=[]
  5. g m(p:n)l=any(g[]$m++n)(l%p)||g(p:m)n l
  6. g[]_[_,_,_]=0<1
  7. g _[]_=0<0
  8. f=($[(0,9^9),(9^9,0)]).g[]
  9.  
  10. main = do
  11. print (f [(1,1),(1,5),(2,6)])
  12. print (f [(1,1),(2,2)])
  13. print (f [(1,1),(1,2),(1,2),(2,1),(2,1)])
  14. print (f [(3,2),(4,1),(2,1),(4,1),(2,1),(5,2),(3,2),(1,4),(3,2),(2,1),(2,1),(1,1),(5,1)])
Success #stdin #stdout 4.27s 8388607KB
stdin
Standard input is empty
stdout
True
False
True
True