Article View: alt.comp.lang.learn.c-c++
Article #221Re: TIC-TAC-TOE in C++ !
From: Larry Coon
Date: Fri, 16 Jan 1998 00:00
Date: Fri, 16 Jan 1998 00:00
64 lines
2114 bytes
2114 bytes
Dave Hamilton wrote: > >First, notice that you can label a 3x3 board with numbers 1..9 in the "magic > >square" fashion (ie. where every row, column and diagonal yields 15 when summed). > > What layout would meet this requirement? It's pretty easy to figure out. You know that some combinations of two numbers can't go on the same row, column or diagonal, because their sum would be >= 15. 9 can't go with 8, 7 or 6; and 8 can't go with 7. Since the center square is on the same row, column or diagonal with every other square, that means the largest number that can go in the center is 5. | | -+-+- |5| -+-+- | | 9 can't go with 8, 7 or 6. But if 9 goes in a corner, there are only two squares that aren't on the same row, column or diagonal. So 9 has to go on a side. |9| -+-+- |5| -+-+- | | The numbers that can go on the same row as 9 are 2 and 4. (1's taken, 3 would require another 3, 5's taken, and anything larger would be too big). Since the board is still symmetrical, we can place them on the same row in either order. 2|9|4 -+-+- |5| -+-+- | | Now sum the diagonals. 2|9|4 -+-+- |5| -+-+- 6| |8 Finally, fill in the rest. 2|9|4 -+-+- 7|5|3 -+-+- 6|1|8 Larry Coon University of California larry@assist.org and lmcoon@home.com
Technical Details
Message-ID:
<34BF9656.21F@assist.org>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01bd1f31$0a72dbc0$db4522cf@jwatson> <34BEA2B6.578B90E@us.oracle.com> <69nnvs$s9j$1@zebra.gi.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114592,750a5b3b86788347 X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,750a5b3b86788347 X-Google-Attributes: gid109fba,public X-Google-Thread: 10d4ba,750a5b3b86788347 X-Google-Attributes: gid10d4ba,public From: Larry Coon <larry@assist.org> Subject: Re: TIC-TAC-TOE in C++ ! Date: 1998/01/16 Message-ID: <34BF9656.21F@assist.org> X-Deja-AN: 316594821 Content-Transfer-Encoding: 7bit References: <01bd1f31$0a72dbc0$db4522cf@jwatson> <34BEA2B6.578B90E@us.oracle.com> <69nnvs$s9j$1@zebra.gi.net> Content-Type: text/plain; charset=us-ascii Organization: University of California Mime-Version: 1.0 Reply-To: larry@assist.org Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++