mirror of
https://github.com/TheAlgorithms/C
synced 2024-12-16 16:33:05 +03:00
266 lines
27 KiB
HTML
266 lines
27 KiB
HTML
<!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=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.2"/>
|
|
<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<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.9.2 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
|
|
/* @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:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(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:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(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> |
|
|
<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 <assert.h></code><br />
|
|
<code>#include <inttypes.h></code><br />
|
|
<code>#include <math.h></code><br />
|
|
<code>#include <stdbool.h></code><br />
|
|
<code>#include <stdio.h></code><br />
|
|
<code>#include <stdlib.h></code><br />
|
|
<code>#include <string.h></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="635" 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 id="nested-classes" name="nested-classes"></a>
|
|
Data Structures</h2></td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d18/structsudoku.html">sudoku</a></td></tr>
|
|
<tr class="memdesc:"><td class="mdescLeft"> </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"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:ga85d25d3b40017436f264a103685e4c55"><td class="memItemLeft" align="right" valign="top">bool </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"> </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"> </td></tr>
|
|
<tr class="memitem:ga6503128d4f5ce0a0826f72f73f9e0b2a"><td class="memItemLeft" align="right" valign="top">bool </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"> </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"> </td></tr>
|
|
<tr class="memitem:ga1cd43df3f4187845ce186042fe53e6f1"><td class="memItemLeft" align="right" valign="top">bool </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"> </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"> </td></tr>
|
|
<tr class="memitem:ga3a0ec150ac9d0cb6b28279d36d95d72f"><td class="memItemLeft" align="right" valign="top">bool </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"> </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"> </td></tr>
|
|
<tr class="memitem:ga702ff4f95dde780c7d04fcdd1021b6c1"><td class="memItemLeft" align="right" valign="top">void </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"> </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"> </td></tr>
|
|
<tr class="memitem:ga62e94fc39f116e2c81daed8f5437431b"><td class="memItemLeft" align="right" valign="top">bool </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"> </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"> </td></tr>
|
|
<tr class="memitem:gadfe0ed5085b4775d8fa00b434cc0fdfc"><td class="memItemLeft" align="right" valign="top">bool </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"> </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"> </td></tr>
|
|
<tr class="memitem:ae1a3968e7947464bee7714f6d43b7002"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../de/dac/sudoku__solver_8c.html#ae1a3968e7947464bee7714f6d43b7002">test</a> ()</td></tr>
|
|
<tr class="separator:ae1a3968e7947464bee7714f6d43b7002"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </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"> </td><td class="mdescRight">Main function. <a href="../../de/dac/sudoku__solver_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </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" target="_blank">Anuj Shah</a> </dd>
|
|
<dd>
|
|
<a href="https://github.com/kvedala" target="_blank">Krishna Vedala</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int main </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Main function. </p>
|
|
<div class="fragment"><div class="line"><a id="l00247" name="l00247"></a><span class="lineno"> 247</span>{</div>
|
|
<div class="line"><a id="l00248" name="l00248"></a><span class="lineno"> 248</span> <a class="code hl_function" href="../../d8/d30/decimal__to__binary__recursion_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a>();</div>
|
|
<div class="line"><a id="l00249" name="l00249"></a><span class="lineno"> 249</span> </div>
|
|
<div class="line"><a id="l00250" name="l00250"></a><span class="lineno"> 250</span> <span class="keyword">struct </span><a class="code hl_struct" href="../../dc/d18/structsudoku.html">sudoku</a> <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>; <span class="comment">// store the matrix as a 1D array</span></div>
|
|
<div class="line"><a id="l00251" name="l00251"></a><span class="lineno"> 251</span> scanf(<span class="stringliteral">"%"</span> SCNu8, &(<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N));</div>
|
|
<div class="line"><a id="l00252" name="l00252"></a><span class="lineno"> 252</span> <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.a = (uint8_t *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N * <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N * <span class="keyword">sizeof</span>(uint8_t));</div>
|
|
<div class="line"><a id="l00253" name="l00253"></a><span class="lineno"> 253</span> <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N2 = (uint8_t)sqrt(<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N);</div>
|
|
<div class="line"><a id="l00254" name="l00254"></a><span class="lineno"> 254</span> </div>
|
|
<div class="line"><a id="l00255" name="l00255"></a><span class="lineno"> 255</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N; i++)</div>
|
|
<div class="line"><a id="l00256" name="l00256"></a><span class="lineno"> 256</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N; j++) scanf(<span class="stringliteral">"%"</span> SCNu8, &(<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.a[i * <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N + j]));</div>
|
|
<div class="line"><a id="l00257" name="l00257"></a><span class="lineno"> 257</span> </div>
|
|
<div class="line"><a id="l00258" name="l00258"></a><span class="lineno"> 258</span> printf(<span class="stringliteral">"Entered a %udx%ud matrix with block size: %"</span> SCNu8 <span class="stringliteral">"\n"</span>, <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N, <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N,</div>
|
|
<div class="line"><a id="l00259" name="l00259"></a><span class="lineno"> 259</span> <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N2);</div>
|
|
<div class="line"><a id="l00260" name="l00260"></a><span class="lineno"> 260</span> <span class="comment">// print(&a);</span></div>
|
|
<div class="line"><a id="l00261" name="l00261"></a><span class="lineno"> 261</span> printf(<span class="stringliteral">"\n\n"</span>);</div>
|
|
<div class="line"><a id="l00262" name="l00262"></a><span class="lineno"> 262</span> <span class="keywordflow">if</span> (<a class="code hl_function" href="../../d5/df4/group__sudoku.html#gadfe0ed5085b4775d8fa00b434cc0fdfc">solve</a>(&<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>))</div>
|
|
<div class="line"><a id="l00263" name="l00263"></a><span class="lineno"> 263</span> printf(<span class="stringliteral">"Valid solution found!\n"</span>);</div>
|
|
<div class="line"><a id="l00264" name="l00264"></a><span class="lineno"> 264</span> <span class="keywordflow">else</span></div>
|
|
<div class="line"><a id="l00265" name="l00265"></a><span class="lineno"> 265</span> printf(<span class="stringliteral">"Invalid\n"</span>);</div>
|
|
<div class="line"><a id="l00266" name="l00266"></a><span class="lineno"> 266</span> <a class="code hl_function" href="../../d5/df4/group__sudoku.html#ga702ff4f95dde780c7d04fcdd1021b6c1">print</a>(&<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>);</div>
|
|
<div class="line"><a id="l00267" name="l00267"></a><span class="lineno"> 267</span> </div>
|
|
<div class="line"><a id="l00268" name="l00268"></a><span class="lineno"> 268</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.a);</div>
|
|
<div class="line"><a id="l00269" name="l00269"></a><span class="lineno"> 269</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a id="l00270" name="l00270"></a><span class="lineno"> 270</span>}</div>
|
|
<div class="ttc" id="adecimal__to__binary__recursion_8c_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../d8/d30/decimal__to__binary__recursion_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">void test()</div><div class="ttdoc">Test function.</div><div class="ttdef"><b>Definition:</b> decimal_to_binary_recursion.c:20</div></div>
|
|
<div class="ttc" id="agroup__sudoku_html_ga702ff4f95dde780c7d04fcdd1021b6c1"><div class="ttname"><a href="../../d5/df4/group__sudoku.html#ga702ff4f95dde780c7d04fcdd1021b6c1">print</a></div><div class="ttdeci">void print(const struct sudoku *a)</div><div class="ttdoc">Print the matrix to stdout.</div><div class="ttdef"><b>Definition:</b> sudoku_solver.c:126</div></div>
|
|
<div class="ttc" id="agroup__sudoku_html_gadfe0ed5085b4775d8fa00b434cc0fdfc"><div class="ttname"><a href="../../d5/df4/group__sudoku.html#gadfe0ed5085b4775d8fa00b434cc0fdfc">solve</a></div><div class="ttdeci">bool solve(struct sudoku *a)</div><div class="ttdoc">Function to solve a partially filled sudoku matrix.</div><div class="ttdef"><b>Definition:</b> sudoku_solver.c:172</div></div>
|
|
<div class="ttc" id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><div class="ttdeci">#define malloc(bytes)</div><div class="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:18</div></div>
|
|
<div class="ttc" id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><div class="ttdeci">#define free(ptr)</div><div class="ttdoc">This macro replace the standard free function with free_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:26</div></div>
|
|
<div class="ttc" id="astructsudoku_html"><div class="ttname"><a href="../../dc/d18/structsudoku.html">sudoku</a></div><div class="ttdoc">Structure to hold the matrix and dimensions.</div><div class="ttdef"><b>Definition:</b> sudoku_solver.c:33</div></div>
|
|
<div class="ttc" id="astructsudoku_html_a507f788b793d4d3d6f6a70415be84ded"><div class="ttname"><a href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">sudoku::a</a></div><div class="ttdeci">uint8_t * a</div><div class="ttdoc">matrix as a flattened 1D row-major array</div><div class="ttdef"><b>Definition:</b> sudoku_solver.c:34</div></div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="ae1a3968e7947464bee7714f6d43b7002" name="ae1a3968e7947464bee7714f6d43b7002"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae1a3968e7947464bee7714f6d43b7002">◆ </a></span>test()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<div class="fragment"><div class="line"><a id="l00222" name="l00222"></a><span class="lineno"> 222</span>{</div>
|
|
<div class="line"><a id="l00223" name="l00223"></a><span class="lineno"> 223</span> printf(<span class="stringliteral">"Test begin...\n"</span>);</div>
|
|
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno"> 224</span> </div>
|
|
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno"> 225</span> uint8_t test_array[] = {3, 0, 6, 5, 0, 8, 4, 0, 0, 5, 2, 0, 0, 0, 0, 0, 0,</div>
|
|
<div class="line"><a id="l00226" name="l00226"></a><span class="lineno"> 226</span> 0, 0, 8, 7, 0, 0, 0, 0, 3, 1, 0, 0, 3, 0, 1, 0, 0,</div>
|
|
<div class="line"><a id="l00227" name="l00227"></a><span class="lineno"> 227</span> 8, 0, 9, 0, 0, 8, 6, 3, 0, 0, 5, 0, 5, 0, 0, 9, 0,</div>
|
|
<div class="line"><a id="l00228" name="l00228"></a><span class="lineno"> 228</span> 6, 0, 0, 1, 3, 0, 0, 0, 0, 2, 5, 0, 0, 0, 0, 0, 0,</div>
|
|
<div class="line"><a id="l00229" name="l00229"></a><span class="lineno"> 229</span> 0, 0, 7, 4, 0, 0, 5, 2, 0, 6, 3, 0, 0};</div>
|
|
<div class="line"><a id="l00230" name="l00230"></a><span class="lineno"> 230</span> <span class="keyword">struct </span><a class="code hl_struct" href="../../dc/d18/structsudoku.html">sudoku</a> <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a> = {.N = 9, .N2 = 3, .a = test_array};</div>
|
|
<div class="line"><a id="l00231" name="l00231"></a><span class="lineno"> 231</span> assert(<a class="code hl_function" href="../../d5/df4/group__sudoku.html#gadfe0ed5085b4775d8fa00b434cc0fdfc">solve</a>(&<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>)); <span class="comment">// ensure that solution is obtained</span></div>
|
|
<div class="line"><a id="l00232" name="l00232"></a><span class="lineno"> 232</span> </div>
|
|
<div class="line"><a id="l00233" name="l00233"></a><span class="lineno"> 233</span> uint8_t expected[] = {3, 1, 6, 5, 7, 8, 4, 9, 2, 5, 2, 9, 1, 3, 4, 7, 6,</div>
|
|
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno"> 234</span> 8, 4, 8, 7, 6, 2, 9, 5, 3, 1, 2, 6, 3, 4, 1, 5, 9,</div>
|
|
<div class="line"><a id="l00235" name="l00235"></a><span class="lineno"> 235</span> 8, 7, 9, 7, 4, 8, 6, 3, 1, 2, 5, 8, 5, 1, 7, 9, 2,</div>
|
|
<div class="line"><a id="l00236" name="l00236"></a><span class="lineno"> 236</span> 6, 4, 3, 1, 3, 8, 9, 4, 7, 2, 5, 6, 6, 9, 2, 3, 5,</div>
|
|
<div class="line"><a id="l00237" name="l00237"></a><span class="lineno"> 237</span> 1, 8, 7, 4, 7, 4, 5, 2, 8, 6, 3, 1, 9};</div>
|
|
<div class="line"><a id="l00238" name="l00238"></a><span class="lineno"> 238</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N; i++)</div>
|
|
<div class="line"><a id="l00239" name="l00239"></a><span class="lineno"> 239</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N; j++)</div>
|
|
<div class="line"><a id="l00240" name="l00240"></a><span class="lineno"> 240</span> assert(<a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.a[i * <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N + j] == expected[i * <a class="code hl_variable" href="../../dc/d18/structsudoku.html#a507f788b793d4d3d6f6a70415be84ded">a</a>.N + j]);</div>
|
|
<div class="line"><a id="l00241" name="l00241"></a><span class="lineno"> 241</span> </div>
|
|
<div class="line"><a id="l00242" name="l00242"></a><span class="lineno"> 242</span> printf(<span class="stringliteral">"Test passed\n"</span>);</div>
|
|
<div class="line"><a id="l00243" name="l00243"></a><span class="lineno"> 243</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</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="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|