File indexing completed on 2024-06-16 07:04:28

0001 /***************************************************************************
0002  *   Copyright 2007      Francesco Rossi <redsh@email.it>                  *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0018  ***************************************************************************/
0019 
0020 #include "stdio.h"
0021 
0022 int w = 21; //width
0023 int h = 21; //height
0024 int o = 9;  //order
0025 
0026 int index(int r, int c)
0027 {
0028     return w*r+c;
0029 }
0030 
0031 int row(int index)
0032 {
0033     return index/w;
0034 }
0035 
0036 int col(int index)
0037 {
0038     return index%w;
0039 }
0040 
0041 void print_head()
0042 {
0043     printf("<clique size=\"%d\" >", o);
0044 }
0045 
0046 void print_tail()
0047 {
0048     printf("</clique>\n");
0049 }
0050 
0051 void print_row(int r, int c) //rc row column
0052 {
0053     print_head();
0054     int s0 = r*w+c;
0055     for(int j=0; j<o; j++)
0056     {
0057         printf("%d ", s0+j);
0058     }
0059     print_tail();
0060 }
0061 
0062 void print_col(int r, int c)
0063 {
0064     print_head();
0065     for(int j=0; j<o; j++)
0066     {
0067         printf("%d ", index(r+j,c));
0068     }
0069     print_tail();
0070 }
0071 
0072 void print_3x3(int r0, int c0)
0073 {
0074     print_head();
0075     int r,c;
0076     for(r=0; r<3; r++)      
0077     {
0078         for(c=0; c<3; c++)
0079         {
0080             printf("%d ", index(r0+r, c0+c));
0081         }
0082     }
0083     print_tail();
0084 }
0085 
0086 void print_9x9_sudoku(int r0, int c0)
0087 {
0088     int i,j;
0089     for(i=0; i<9; i++)
0090     {
0091         print_row(r0+i,c0);
0092     }
0093     for(i=0; i<9; i++)
0094     {   
0095         print_col(r0,c0+i);
0096     }
0097     for(i=0; i<9; i++)
0098     {   
0099         print_3x3(r0+(i/3)*3,c0+(i%3)*3);
0100     }
0101 }
0102 
0103 int main(void)
0104 {
0105     print_9x9_sudoku(0,0);
0106     printf("\n");
0107     print_9x9_sudoku(0,12);
0108     printf("\n");
0109     print_9x9_sudoku(12,0);
0110     printf("\n");
0111     print_9x9_sudoku(12,12);
0112     printf("\n");
0113     print_9x9_sudoku(6,6);
0114     printf("\n");
0115 
0116 }