TheAlgorithms-C/de/dac/sudoku__solver_8c.html

177 lines
13 KiB
HTML
Raw Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.19"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C: misc/sudoku_solver.c File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Algorithms_in_C
&#160;<span id="projectnumber">1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.19 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('de/dac/sudoku__solver_8c.html','../../'); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">sudoku_solver.c File Reference</div> </div>
</div><!--header-->
<div class="contents">
<p>Sudoku Solver using recursive implementation of brute-force algorithm.
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;assert.h&gt;</code><br />
<code>#include &lt;inttypes.h&gt;</code><br />
<code>#include &lt;math.h&gt;</code><br />
<code>#include &lt;stdbool.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for sudoku_solver.c:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d8/db5/sudoku__solver_8c__incl.svg" width="634" height="112"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d18/structsudoku.html">sudoku</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">Structure to hold the matrix and dimensions. <a href="../../dc/d18/structsudoku.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga85d25d3b40017436f264a103685e4c55"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/df4/group__sudoku.html#ga85d25d3b40017436f264a103685e4c55">OKrow</a> (const struct <a class="el" href="../../dc/d18/structsudoku.html">sudoku</a> *a, int x, int y, int v)</td></tr>
<tr class="memdesc:ga85d25d3b40017436f264a103685e4c55"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if <code>x</code>^th row is valid. <a href="../../d5/df4/group__sudoku.html#ga85d25d3b40017436f264a103685e4c55">More...</a><br /></td></tr>
<tr class="separator:ga85d25d3b40017436f264a103685e4c55"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga6503128d4f5ce0a0826f72f73f9e0b2a"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/df4/group__sudoku.html#ga6503128d4f5ce0a0826f72f73f9e0b2a">OKcol</a> (const struct <a class="el" href="../../dc/d18/structsudoku.html">sudoku</a> *a, int x, int y, int v)</td></tr>
<tr class="memdesc:ga6503128d4f5ce0a0826f72f73f9e0b2a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if <code>y</code>^th column is valid. <a href="../../d5/df4/group__sudoku.html#ga6503128d4f5ce0a0826f72f73f9e0b2a">More...</a><br /></td></tr>
<tr class="separator:ga6503128d4f5ce0a0826f72f73f9e0b2a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1cd43df3f4187845ce186042fe53e6f1"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/df4/group__sudoku.html#ga1cd43df3f4187845ce186042fe53e6f1">OKbox</a> (const struct <a class="el" href="../../dc/d18/structsudoku.html">sudoku</a> *a, int x, int y, int v)</td></tr>
<tr class="memdesc:ga1cd43df3f4187845ce186042fe53e6f1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if a 3x3 box is valid. <a href="../../d5/df4/group__sudoku.html#ga1cd43df3f4187845ce186042fe53e6f1">More...</a><br /></td></tr>
<tr class="separator:ga1cd43df3f4187845ce186042fe53e6f1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga3a0ec150ac9d0cb6b28279d36d95d72f"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/df4/group__sudoku.html#ga3a0ec150ac9d0cb6b28279d36d95d72f">OK</a> (const struct <a class="el" href="../../dc/d18/structsudoku.html">sudoku</a> *a, int x, int y, int v)</td></tr>
<tr class="memdesc:ga3a0ec150ac9d0cb6b28279d36d95d72f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if element <code>v</code> is valid to place at (x,y) location. <a href="../../d5/df4/group__sudoku.html#ga3a0ec150ac9d0cb6b28279d36d95d72f">More...</a><br /></td></tr>
<tr class="separator:ga3a0ec150ac9d0cb6b28279d36d95d72f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga702ff4f95dde780c7d04fcdd1021b6c1"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/df4/group__sudoku.html#ga702ff4f95dde780c7d04fcdd1021b6c1">print</a> (const struct <a class="el" href="../../dc/d18/structsudoku.html">sudoku</a> *a)</td></tr>
<tr class="memdesc:ga702ff4f95dde780c7d04fcdd1021b6c1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Print the matrix to stdout. <a href="../../d5/df4/group__sudoku.html#ga702ff4f95dde780c7d04fcdd1021b6c1">More...</a><br /></td></tr>
<tr class="separator:ga702ff4f95dde780c7d04fcdd1021b6c1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga62e94fc39f116e2c81daed8f5437431b"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/df4/group__sudoku.html#ga62e94fc39f116e2c81daed8f5437431b">get_next_unknown</a> (const struct <a class="el" href="../../dc/d18/structsudoku.html">sudoku</a> *a, int *x, int *y)</td></tr>
<tr class="memdesc:ga62e94fc39f116e2c81daed8f5437431b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Find and get the location for next empty cell. <a href="../../d5/df4/group__sudoku.html#ga62e94fc39f116e2c81daed8f5437431b">More...</a><br /></td></tr>
<tr class="separator:ga62e94fc39f116e2c81daed8f5437431b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gadfe0ed5085b4775d8fa00b434cc0fdfc"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/df4/group__sudoku.html#gadfe0ed5085b4775d8fa00b434cc0fdfc">solve</a> (struct <a class="el" href="../../dc/d18/structsudoku.html">sudoku</a> *a)</td></tr>
<tr class="memdesc:gadfe0ed5085b4775d8fa00b434cc0fdfc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to solve a partially filled sudoku matrix. <a href="../../d5/df4/group__sudoku.html#gadfe0ed5085b4775d8fa00b434cc0fdfc">More...</a><br /></td></tr>
<tr class="separator:gadfe0ed5085b4775d8fa00b434cc0fdfc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae1a3968e7947464bee7714f6d43b7002"><td class="memItemLeft" align="right" valign="top"><a id="ae1a3968e7947464bee7714f6d43b7002"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><b>test</b> ()</td></tr>
<tr class="separator:ae1a3968e7947464bee7714f6d43b7002"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top"><a id="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../de/dac/sudoku__solver_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Sudoku Solver using recursive implementation of brute-force algorithm. </p>
<p>Given an incomplete N*N Sudoku and asked to solve it using the following recursive algorithm:</p><ol type="1">
<li>Scan the Sudoku from left to right row-wise to search for an empty cell.</li>
<li>If there are no empty cells, print the Sudoku. Go to step 5.</li>
<li>In the empty cell, try putting numbers 1 to N while ensuring that no two numbers in a single row, column, or box are same. Go back to step 1.</li>
<li>Declare that the Sudoku is Invalid.</li>
<li>Exit.</li>
</ol>
<dl class="section author"><dt>Authors</dt><dd><a href="https://github.com/anujms1999">Anuj Shah</a> </dd>
<dd>
<a href="https://github.com/kvedala">Krishna Vedala</a> </dd></dl>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_a52f4d3d586a58b02f3a4ddf0a992157.html">misc</a></li><li class="navelem"><a class="el" href="../../de/dac/sudoku__solver_8c.html">sudoku_solver.c</a></li>
<li class="footer">Generated by <a href="http://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.19 </li>
</ul>
</div>
</body>
</html>