In an earlier post, I mentioned how I used CF to solve a simple puzzle. I was lazy again today and decided I would use it to solve another puzzle. This time the puzzle was a 4x4 grid with the letters W, X, Y, and Z. Each row had a different combination of letters with a sum at the end. So for example, W + X + Y + Z = 17 and W + Z + Z + W = 16. You had to solve for Y + X + X + Y. So, being the lazy person I am, I used a simple script:

<cfloop index="y" from=1 to=8>

<cfloop index="w" from=1 to=8>

<cfloop index="z" from=1 to=8>

<cfif (w + x + y + z is 17) and

(z + 2*x + y is 19) and

(z + 3*x is 18) and

(w + 2*y + w is 14)>

<cfoutput>

x=#x#, y=#y#, w=#w#, z=#z# is GOOD

</cfoutput>

<cfbreak>

</cfif>

</cfloop>

</cfloop>

</cfloop>

</cfloop>

I used 8 as a max as all the sums were below 20 and I figured it would be a safe assumption. Running the code took about one second and quickly spit out the solution:

x=4, y=5, w=2, z=6 is GOOD

I then solved for Y + X + X + Y to get 18. Once again CF saves the day!

## Archived Comments

Ray,

Nothing to do with your puzzle, but I've often wondered if there is a performance benefit to having cfoutput tags inside or outside nested loops.

Can you put a link to the original puzzle out there?

Thx,

B

PaulKD: Um, I can't think of any thing in particular. In my case I use cfbreak which immidiately ends once the solution is found.

Brian: Sorry, it's a physical calendar. The company actually has an online component as well, but you have to enter a code to get the calendar.

hmm... this reminds me of first year engineering... linear algebra... oh yes, systems of linear equasions.

i got a question for you ray, how do you know the answer you got is the only answer? or is that not important?

mike:

Nah, I'm not concerned. Of course you could remove the cfbreak and see for yourself. :)