The Sleigh Packing problem

Santa's elves need help in determining if their current batch of presents will fit into santa's sleigh. Write the shortest program possible in the language of your choice to help them out.

Constraints

• Santa's sleigh measures 6ft wide by 12ft long and is 4ft deep.
• Presents may be fragile, so they may not be stacked on top of each other.
• You can rotate and flip the presents as you wish, but Santa's quite an obsessive-compulsive chap so keep the rotations to multiples of 90 degrees.
• North Pole health and safety regulations stipulate that presents may not stick out more than 1ft above the top of a sleigh (therefore they may not be more than 5ft high).

Input

Input will be on STDIN and will be one integer representing the number of presents in the batch followed by a list of the presents' dimensions - 1 present per line, 3 dimensions (in feet) separated by spaces.

Examples:

1
6 12 5

6
1 12 3
1 12 4
1 12 1
1 12 5
1 12 3
1 12 5

1
4 3 13

1
6 12 6

Output

Output should just be the word 'YES' if the presents can be packed into the sleigh or 'NO' if they cannot.

Output for the above examples:

YES

YES

NO

NO

Test scripts

As before, I've appropriated some test scripts written by Joey and Ventero to create some tests for this task:-

Usage: ./test [your program and its arguments]

Rewards

Each entry which I can verify that meets the spec, passes the tests and has obviously had some attempt at golfing will receive an upvote from me (so please provide usage instructions with your answer). The shortest solution by the end of the 2011 will be accepted as the winner.

• Are we allowed to rotate the presents? Flip them on their side? Rotate them by an angle that's not a multiple of 90°? – Ilmari Karonen Dec 24 '11 at 4:44
• @IlmariKaronen Yes, you can rotate the presents to any orientation you wish as long as they fit. I think the the maths involved in fitting boxes in at an angle that's not a multiple of 90 would be over-complicated wouldn't it? I've assumed only rotations of 90 degrees for the tests. – Gareth Dec 24 '11 at 8:17
• @IlmariKaronen Upon further thought, I think I need to eliminate rotations other multiples of 90 degrees to avoid over-complicating the question, and to ensure that the tests give correct answers. I'll add an extra constraint. – Gareth Dec 24 '11 at 10:16
• Why is example 3 a no when example 1 is a yes? 6x12x5 is bigger than 6x12x4 so are present allowed to poke out the top? In which case why is 3 a no as that too can stick out the top? – Skizz Dec 24 '11 at 11:41
• @Skizz: It's confusingly phrased, but see the fourth constraint: presents may stick 1ft out the top. So the effective depth of the sleigh is 5ft, not 4ft. – Ilmari Karonen Dec 24 '11 at 12:11

import Data.List
s(ξ:υ:_,λ:σ:η:_)(x:y:_,l:w:_)=(ξ+λ<=x||ξ>=x+l||υ+σ<=y||υ>=y+w)&&ξ+λ<7&&υ+σ<13&&η<6
y p l=[(v,r):l|v<-[[x,y,0]|x<-[0..5],y<-[0..11]],r<-permutations p,all(s(v,r))l]
main=do