<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ramblings of a Geek...</title>
	<atom:link href="http://www.bhuwankhattar.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bhuwankhattar.com/blog</link>
	<description>Life, The Universe and Everything</description>
	<lastBuildDate>Tue, 28 Feb 2012 13:32:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<div id='fb-root'></div>
					<script type='text/javascript'>
						window.fbAsyncInit = function()
						{
							FB.init({appId: 180303682005136, status: true, cookie: true, xfbml: true});
						};
						(function()
						{
							var e = document.createElement('script'); e.async = true;
							e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
							document.getElementById('fb-root').appendChild(e);
						}());
					</script>	
						<item>
		<title>Birthday</title>
		<link>http://www.bhuwankhattar.com/blog/2011/05/27/birthday/</link>
		<comments>http://www.bhuwankhattar.com/blog/2011/05/27/birthday/#comments</comments>
		<pubDate>Fri, 27 May 2011 17:32:17 +0000</pubDate>
		<dc:creator>Bhuwan</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.bhuwankhattar.com/?p=132</guid>
		<description><![CDATA[17 years ago, he ceased to be a fetus. An instance of human, he has existed since thus. The boy that was then materialized, a yearly timer, with him, was initialized. It&#8217;s code: this.age++; &#60;/uber geek limerick&#62; &#60;!&#8211;Note to self: Write on blog more often. &#8211;&#62; No points for guessing that the boy is yours]]></description>
			<content:encoded><![CDATA[<div style="margin-left: 10px;">17 years ago, he ceased to be a fetus.<br />
An instance of human, he has existed since thus.<br />
The boy that was then materialized,<br />
a yearly timer, with him, was initialized.<br />
It&#8217;s code: <em style="color: #0000ff;">this.age++;</em></div>
<p><span style="color: #0000ff;">&lt;/uber geek limerick&gt;</span><br />
<span style="color: #008000;">&lt;!&#8211;Note to self: Write on blog more often. &#8211;&gt;</span></p>
<p>No points for guessing that the boy is yours truly :P.</p>
<p>PS: The cake is a lie.</p>
<div class='wpfblike' ><fb:like href='http://www.bhuwankhattar.com/blog/2011/05/27/birthday/' layout='default' show_faces='true' width='600' action='like' colorscheme='light' send='true' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.bhuwankhattar.com/blog/2011/05/27/birthday/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Restore the &#8220;Comment&#8221; Button on Facebook [Greasemonkey]</title>
		<link>http://www.bhuwankhattar.com/blog/2011/03/16/restore-comment-button-on-facebook/</link>
		<comments>http://www.bhuwankhattar.com/blog/2011/03/16/restore-comment-button-on-facebook/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 17:51:55 +0000</pubDate>
		<dc:creator>Bhuwan</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Greasemonkey]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[bring fb comment button back]]></category>
		<category><![CDATA[Facebook Comment Button Restorer]]></category>
		<category><![CDATA[Facebook Comments Submit Button]]></category>
		<category><![CDATA[fb]]></category>
		<category><![CDATA[fb comment button]]></category>

		<guid isPermaLink="false">http://www.bhuwankhattar.com/?p=83</guid>
		<description><![CDATA[Script Last Updated (January 25, 2012). Now works with the sidebar ticker too. Detailed changelog below. Earlier today, Facebook dropped the comment button. And a lot of people have been complaining about this change. My Class XI annual exams ended today (Okay. Computer Science is still left. But who studies for it anyway? =P), so]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 20px; color: red; font-weight: bold;">Script Last Updated (January 25, 2012). Now works with the sidebar ticker too. Detailed changelog below.</span></p>
<p>Earlier today, Facebook <a href="http://thenextweb.com/facebook/2011/03/16/facebook-drops-the-comment-button-allows-users-to-edit-replies/">dropped the comment button</a>. And <a href="http://search.twitter.com/search?q=facebook+comment+button">a lot</a> <a href="http://www.google.com/search?q=facebook+comment+button">of people</a> have been complaining about this change.</p>
<p>My Class XI annual exams ended today (Okay. Computer Science is still left. But who studies for it anyway? =P), so I <del>was kind of jobless</del> had some free time on my hands. Also, I hadn&#8217;t really coded anything in a long time. I was a little tired. But since coding has somewhat of a therapeutic effect on me, I decided to work on a <a href="http://en.wikipedia.org/wiki/Greasemonkey">Greasemonkey</a> script to restore the comment button.</p>
<p>I ran into a few hurdles while working on the script. But I don&#8217;t really feel like writing about it right now. Still kind of tired, you see. Some other time, perhaps.</p>
<p>To my knowledge, it works perfectly fine with Firefox(<a href="https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/">Greasemonkey</a> required), Chrome and Opera. But in case you find any bugs, you can report them in the comments below or just shoot me an email.<br />
<strong><br />
<h3><a href="http://userscripts.org/scripts/show/99131">Download v1.20</a> (Updated January 25, 2012)</h3>
<p></strong><br />
<strong><br />
<h3>Changelog</h3>
<p></strong></p>
<ul>
<li><strong>v1.20 (January 25, 2012)
<ul>
<li>NEW: Added support for the real-time ticket in the sidebar.</li>
<li>Improved implementation.</li>
</ul>
<p>	</strong></li>
<li>v1.11 (March 25, 2011)
<ul>
<li>Added https support.</li>
</ul>
</li>
<li>v1.10 (March 17, 2011)
<ul>
<li>NEW: Facebook resized the comment box to allow one line. Added functionality to dynamically resize the comment box.</li>
<li>BUGFIX: Sometimes, the script used run too early and comment boxes didn&#8217;t get changed. Added live binding of focus and blur events to comment boxes.</li>
</ul>
</li>
<li>v1.05 (March 16, 2011)
<ul>
<li>First public release</li>
</ul>
</li>
</ul>
<div class='wpfblike' ><fb:like href='http://www.bhuwankhattar.com/blog/2011/03/16/restore-comment-button-on-facebook/' layout='default' show_faces='true' width='600' action='like' colorscheme='light' send='true' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.bhuwankhattar.com/blog/2011/03/16/restore-comment-button-on-facebook/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>My Class XI Computer Science Project (Sudoku Solver)</title>
		<link>http://www.bhuwankhattar.com/blog/2011/02/11/my-class-xi-computer-science-project/</link>
		<comments>http://www.bhuwankhattar.com/blog/2011/02/11/my-class-xi-computer-science-project/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 12:47:40 +0000</pubDate>
		<dc:creator>Bhuwan</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[School]]></category>
		<category><![CDATA[C++ Project]]></category>
		<category><![CDATA[CBSE]]></category>
		<category><![CDATA[Class XI]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Sudoku Solver]]></category>
		<category><![CDATA[Turbo C++]]></category>

		<guid isPermaLink="false">http://www.bhuwankhattar.com/?p=24</guid>
		<description><![CDATA[I honestly wasn&#8217;t planning on writing another post so soon. But anyway, here it is :P. With the academic session nearing its end and the deadline to submit projects and labfiles coming closer, I&#8217;ve had a lot of people ask me questions such as &#8220;What are you making for your CS Project?&#8220;, &#8220;Can I use]]></description>
			<content:encoded><![CDATA[<p>I honestly wasn&#8217;t planning on writing another post so soon. But anyway, here it is :P.</p>
<p>With the academic session nearing its end and the deadline to submit projects and labfiles coming closer, I&#8217;ve had a lot of people ask me questions such as &#8220;<em>What are you making for your CS Project?</em>&#8220;, &#8220;<em>Can I use your project?</em>&#8220;, &#8220;<em>Will you help me with/make my project?</em>&#8220;. Now that I have a blog set up, I&#8217;d rather reply to everyone here than individually.</p>
<p><em>I made a Sudoku Solver. <strong>No, you may not use mine</strong>. And well, depending upon what all you require help with and how much time I can find to spare, I will help you with yours. But sorry, I won&#8217;t make yours.</em></p>
<p>I&#8217;m putting up my project here(attached at the end of the post) for you to see. Please note that this is <strong><em>for reference purposes only</em></strong>. You are more than welcome to use ideas and logic from this code in your project. However, you may not copy this in all its entirety and submit it as your own. Apart from committing plagiarism, you would also be spelling trouble for yourself during the vivas.</p>
<p>I should also mention that this code makes use of some libraries, functions and methods that are not covered under the current CBSE prescribed syllabus for Class XI.<br />
But I feel that, since the code is well-commented, none of you should have much trouble trying to understand any part of the code. But in case you do run into a stone wall, TurboC++ 3.0 has a help section where you can find documentation on any of the header files and predefined functions used in this program. And then there is always Google. If you still don&#8217;t find your answers, I&#8217;d be glad to help. But please do search before you decide to trouble me for help.</p>
<p><em><strong>PS:</strong> Turbo C++ sucks. I don&#8217;t know why CBSE still bases its curriculum on it. It&#8217;s almost two decades old. Doesn&#8217;t match the <a href="http://en.wikipedia.org/wiki/C%2B%2B#Language_standard">language standards</a> created over 12 years ago. The compiler(<a href="http://en.wikipedia.org/wiki/Turbo_C%2B%2B#Historical_versions">TC++ 3.0</a>) is DOS Based and is no longer even supported by its own developer. And yet, here we are, </em>apparently <em>in the 21st century, still using it throughout high schools in India. And this is just one of the many sorry tales of education under CBSE. </em>&lt;/rant&gt;</p>
<p><em><strong>PPS:</strong> I have a lot more to say about, or rather against, the prevalent formal education system. But I think I&#8217;ll save it for a huge post sometime later.</em></p>
<p><strong>View full post to see the attached code.</strong><br />
<span id="more-24"></span></p>
<pre class="brush: cpp; collapse: true; highlight: [3,4,5,6,10]; light: false; title: ; toolbar: true;">
/*
 * ----------------------------------------------------------------------------
 * File		: SudokuSolver.cpp
 * Author	: Bhuwan Khattar (BhuwanKhattar.com)
 * Created	: Not so long ago, in a galaxy not too far away...
 * Revision	: 42
 * ----------------------------------------------------------------------------
 */

#define BGI_PATH &quot;C:\\tc\\bgi&quot; // Please change this accordingly. (Is there a better way to do this is?)
// Header files
#include &lt;conio.h&gt;
#include &lt;dos.h&gt;
#include &lt;graphics.h&gt;
#include &lt;iostream.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
// Defining some keycodes.
#define K_BKSPC 8
#define K_CTRL_R 18
#define K_ESC 27
#define K_F5 319
#define K_UP 328
#define K_LEFT 331
#define K_RIGHT 333
#define K_DOWN 336
#define K_DEL 339

// Just some declarations.
typedef enum bool { false, true }; // TC++ doesn't have a bool data type. Let's define it on our own.
int	i,j,x1,y1,x2,y2,cellHeight,cellWidth;
enum {EMPTY, USER_DEFINED, LOGIC_FIND, BRUTE_FORCED};
struct { int type, value; } cell[9][9];
bool canEditCell(int x, int y),
	isComplete(),
	isValid(int x, int y, int number),
	logicStep1(),
	logicStep2();
int	cursorAtCell(int x, int y);
void bruteForce(),
	clearCell(int x, int y),
	drawSudoku(),
	solveUsingLogic(),
	updateCell(int x, int y, int number, int color=WHITE);

void main(){
	clrscr(); // Let's clear everything.
	int i,j,x,y; // Just some declarations
	// Initiallizing all cells as empty.
	for(i=0;i&lt;9;i++)
		for(j=0;j&lt;9;j++){
			cell[i][j].value=0;
			cell[i][j].type=EMPTY;
		}
	// Initiallizing Graphics Driver
	int gdriver = DETECT, gmode, errorcode;
	initgraph(&amp;gdriver, &amp;gmode, BGI_PATH);
	errorcode = graphresult();
	if (errorcode != grOk){ // If we got an error. Display it and exit.
		printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode));
		printf(&quot;Press any key to halt:&quot;);
		getch();
		exit(1);
	}
	// Okay. Graphics works. Let's draw the Sudoku Grid
	drawSudoku();
	i=0; j=0; // Reset i and j to 0.
	while(1){ // Infinite Loop
		int keycode = cursorAtCell(i,j);
		if(!keycode) keycode = 256+getch(); // Hack to add support for extended ASCII Codes
		if(keycode==K_DOWN){
			if(i&lt;8) i++;
		}else if(keycode==K_UP){
			if(i&gt;0) i--;
		}else if(keycode==K_LEFT){
			if(j&gt;0) j--;
		}else if(keycode==K_RIGHT){
			if(j&lt;8) j++;
		}else if((keycode&gt;='1')&amp;&amp;(keycode&lt;='9')){ // If the key pressed is a valid number(1-9)
			clearCell(i,j);
			updateCell(i,j, keycode-'0'); // Update current cell with the number corresponding to the ASCII key code
		}else if((keycode==K_BKSPC)||(keycode==K_DEL)){
			clearCell(i,j);
		}else if(keycode==K_CTRL_R){
			int error=0;
			// Let's loop through all the cells and see if they're valid enteries.
			for(x=0;x&lt;9;x++)
				for(y=0;y&lt;9;y++)
					if(!isValid(x,y,cell[x][y].value)){
						updateCell(x,y,cell[x][y].value,RED);
						error=1;
					}
			if(!error){ // Okay. Everything is fine. Time to solve.
				// Loop through all the cells. If it has a value, it must be user-defined.
				for(x=0;x&lt;9;x++)
					for(y=0;y&lt;9;y++)
						if(cell[x][y].value!=0)
							cell[x][y].type=USER_DEFINED;
				solveUsingLogic(); // Let's try to solve using defined logics.
				if(!isComplete()){ // If it didn't work.
					setcolor(RED); // Add formatting
					outtextxy(10,10,&quot;Couldn't solve using defined logic. Attempting to brute force...&quot;); // Print message
					bruteForce();
				}
				if(isComplete()){ // Reached a solution.
					drawSudoku(); // Redraw sudoku with the solution.
					setcolor(WHITE); // Add formatting
					outtextxy(10,10,&quot;Sudoku Solved. Press any key to clear sudoku and restart.&quot;); // Print message
				}else{
					setcolor(RED); // Add formatting
					outtextxy(10,20,&quot;Couldn't find a solution.&quot;); // Print message
					outtextxy(20,30,&quot;Press F5 to change values and try again.&quot;); // Print message
					outtextxy(20,40,&quot;Or press any other key to clear sudoku and restart.&quot;); // Print message
				}
				keycode = getch();
				if(!keycode) keycode = 256+getch(); // Hack to add support for extended ASCII Codes
				if((keycode==K_F5) &amp;&amp; !(isComplete())){ // If a solution wasn't reached and the user pressed F5, let's revert back to the original user entered grid.
					for(x=0;x&lt;9;x++)
						for(y=0;y&lt;9;y++)
							if(cell[x][y].type!=USER_DEFINED)
								clearCell(x,y);
				}else // Okay. Safe to empty the grid.
					for(x=0;x&lt;9;x++)
						for(y=0;y&lt;9;y++)
							clearCell(x,y);
				i=0;j=0; // Return to the first cell.
				drawSudoku();
			}else{
				settextstyle(0,0,1); setcolor(RED); // Add formatting
				outtextxy(10,10,&quot;Conflicting values(highlighted in red) found. Change and try again.&quot;); // Print message
			}
		}else if(keycode==K_ESC){ // Time to exit.
			break; // End infinite loop. Oh, the irony!
		}
	}
}

void updateCell(int x, int y, int number, int color	){ // Updates cell(x,y) in the grid with number. Default color is white.
	// Let's convert the number from int to string.
	char number_string[1];
	sprintf(number_string, &quot;%d&quot;, number);
	// Add formatting.
	setcolor(color);
	settextstyle(0,0,2);
	outtextxy(x1+16+y*cellHeight, y1+10+x*cellWidth, number_string); // Write in the cell
	cell[x][y].value=number; // Update the sudoku array
}

void clearCell(int x, int y){ // Empties cell(x,y) in the grid.
	// Since we cannot erase, we'll overwrite the number with itself but with the background color.
	// Let's convert the current number in the cell from int to string.
	char number_string[1];
	sprintf(number_string, &quot;%d&quot;, cell[x][y].value);
	// Add formatting. Using background color to achieve erasing effect.
	setcolor(LIGHTGRAY);
	settextstyle(0,0,2);
	outtextxy(x1+16+y*cellHeight, y1+10+x*cellWidth, number_string); // Over-writing to erase.
	// Update the sudoku array and cell type.
	cell[x][y].value=0;
	cell[x][y].type=EMPTY;
}

int cursorAtCell(int x, int y){ // Puts a cursor in the cell(x,y) in the grid. Returns keycode when a key is hit.
	// We shall use the underscore character for the cursor. To achieve blinking effect, we shall alternate the color of the cursor between white and the background color every 100ms.
	char cur_string[2] = &quot;_&quot;;
	int color = LIGHTGRAY;
	while(1){ // Infinite loop.
		(color==WHITE)?(color=LIGHTGRAY):(color=WHITE); // Alternate cursor color to achieve blinking effect.
		// Add formatting.
		setcolor(color);
		settextstyle(0,0,2);
		outtextxy(x1+16+y*cellHeight, y1+10+x*cellWidth+2, cur_string); // Add cursor
		if(kbhit()){ // Oops. Someone hit a key. Time to stop the blinking.
			if(color==WHITE){ // Wait. Before we get out of this loop, we must &quot;erase the cursor&quot;. For this, we must make sure the color of the cursor is same as the background color.
				setcolor(LIGHTGRAY);
				outtextxy(x1+16+y*cellHeight, y1+10+x*cellWidth+2, cur_string);
			}
			break; // Okay. It's fine to break out of the loop now.
		}
		delay(100); // Let's wait 100ms before updating the cursor in order to make the blinking visible.
	}
	return getch(); // Return the key pressed so that we can process it.
}

void drawSudoku(){ // Draws the sudoku grid. Also adds text and numbers.
	cleardevice(); // Let's clear everything on the screen.
	clrscr();
	// Getting and setting co-ordinate values
	x1 = getmaxx()/5;
	y1 = getmaxy()/5;
	x2 = 4*getmaxx()/5;
	y2 = 4*getmaxy()/5;
	cellHeight = (x2 - x1)/9;
	cellWidth = (y2 - y1)/9;
	// Define background and pen colors
	setbkcolor(LIGHTGRAY);
	setcolor(DARKGRAY);
	rectangle(x1-3, y1-3, x2+3, y2+3); // Draw the outer border of the grid.
	rectangle(x1, y1, x2, y2); // Draw the inner border of the grid.
	// Loop to draw vertical lines
	for(int i=1; i&lt;9; i++){
		line((x1+i*cellHeight), y1, (x1+i*cellHeight), y2);
		if(i==3||i==6) // And highlight the 3rd and 6th line
			line((x1+i*cellHeight+3), y1, (x1+i*cellHeight+3), y2);
	}
	// Loop to draw horizontal lines
	for(i=1; i&lt;9; i++){
		line(x1, (y1+i*cellWidth), x2, (y1+i*cellWidth));
		if(i==3||i==6) // And highlight the 3rd and 6th line
			line(x1, (y1+i*cellWidth+3), x2, (y1+i*cellWidth+3));
	}
	// Loop to fill the cells with numbers
	for(i=0; i&lt;9; i++)
		for(j=0; j&lt;9; j++){
			if(cell[i][j].value!=0){ // If the cell isn't empty
				int color=WHITE; // Let's define the color
				if(cell[i][j].type==BRUTE_FORCED) color=BLUE;
				else if(cell[i][j].type==LOGIC_FIND) color=GREEN;
				updateCell(i,j, cell[i][j].value, color); // Write the number in the cell
			}
		}
	// Now let's add a title and some instructions.
	// Add formatting.
	setcolor(WHITE);
	settextstyle(0,0,3);
	outtextxy(x1+40, y1-30, &quot;Sudoku Solver&quot;); // Co-ordinates found by experimentation. Let's hope this displays fine on all screens.
	// Instead of placing all instructions manually, let's put them in a structure and loop to place them.
	struct {char message[80]; int size; int color;} Messages[] = {{&quot;Instructions&quot;,2,WHITE},
																  {&quot;1. Use arrows keys to navigate and fill up all the known cells.&quot;,1,WHITE},
																  {&quot;2. Press Ctrl+R to solve the sudoku.&quot;,1,WHITE},{&quot;3. Press Esc to exit.&quot;,1,WHITE},
																  {&quot;White: User Entered Values&quot;,1,WHITE},{&quot;Green: Found Using Logic&quot;,1,GREEN},
																  {&quot;Blue: Found Using Brute Force&quot;,1,BLUE},{&quot;Red: Invalid Values&quot;,1,RED}};
	int x=10, y=y1+10+9*cellWidth; // Initial x and y co-ordinates
	for(i=0; i&lt;8; i++){
		settextstyle(0,0,Messages[i].size);
		setcolor(Messages[i].color);
		outtextxy(x, y, Messages[i].message);
		y += textheight(Messages[i].message)+2; // Update y co-ordinate based on current message's height
	}
}

bool isValid(int x, int y, int number){ // Check if the number in the cell(x,y) on the grid is valid.
	if(number==0) // If the number is 0, that means the cell is empty. It's valid. Return true.
		return true;
	// Check for conflicts in the column.
	for(int i=0;i&lt;9;i++)
		if(i!=x &amp;&amp; cell[i][y].value == number) // Checking the cell for conflicts with itself doesn't make sense, does it?
			return false;
	// Check for conflicts in the row.
	for(int j=0; j&lt;9; j++)
		if(j!=y &amp;&amp; cell[x][j].value == number) // Checking the cell for conflicts with itself doesn't make sense, does it?
			return false;
	// Check for conflicts in the box.
	int bx = (x/3)*3; // X coordinate of first cell in the box.
	int by = (y/3)*3; // Y coordinate of first cell in the box.
	for(i=0;i&lt;3;i++)
		for(j=0; j&lt;3; j++)
			if((!(bx+i==x &amp;&amp; by+j==y)) &amp;&amp; cell[bx+i][by+j].value == number) // Checking the cell for conflicts with itself doesn't make sense, does it?
				return false;
	// Okay, if we're here means that there are no conflicts. This is a valid move. Let's return true.
	return true;
}

bool canEditCell(int x, int y){ // Checks if the cell is safe to be editing while bruteforcing.
	if(cell[x][y].type==USER_DEFINED||cell[x][y].type==LOGIC_FIND) // If the cell was filled by the user or filled on the basis of basic logic, we better not touch it.
		return false;
	// If not, we're fine.
	return true;
}

void bruteForce(){ // Brute-forces empty cells with all possible values until a solution is reached.
	// We're going to work through all possible values seiuentially until a solution or contradiction is reached.
	int i=0,x,y;
	bool flag; // Initializing some variables.
	while(i&lt;81){ // Loop until we've crossed the last cell.
		// Let's find the x and y co-ordinates
		x = i/9; y = i%9;
		if(canEditCell(x,y)){
			flag=false; // Flag to see whether the cell was edited.
			for(int j=cell[x][y].value+1;j&lt;10;j++){ // Loop through all possible values.
				if(isValid(x,y,j)){
					cell[x][y].value=j;
					cell[x][y].type=BRUTE_FORCED;
					flag=true;
					break; // We found a value that fits, time to break out of the loop and move to the next cell.
				}
			}
		}
		if(!flag){ // Oops, we didn't find any value to fit in the cell.
			if(canEditCell(x,y)) cell[x][y].value=0; // Let's empty this cell, if we're allowed to edit it.
			i--; // And go back to the previous cell.
		}
		else
			i++; // We found a valid move. Next cell, here we come!
		if(i==-1) // Oops, we can't go the cell previous to the first cell.
			break; // No solution exists. Must break out of the loop.
	}
}

bool isComplete(){ // Checks if all the cells in the sudoku have been filled.
	for(i=0;i&lt;9;i++)
		for(j=0;j&lt;9;j++)
			if(cell[i][j].value==0)
				return false;
	return true;
}

bool logicStep1(){ // A.k.a there is only one possibility
	int i,j,k,count,number;
	bool flag=false;
	// Loop through all the cells
	for(i=0;i&lt;9;i++)
		for(j=0;j&lt;9;j++){
			if(cell[i][j].value==0){ // If it's empty
				count = 0; // Number of possible values for this cell.
				for(k=1;k&lt;10;k++) // Let's loop from 1 to 9.
					if(isValid(i,j,k)){ // And if it's valid in this cell
						count++; // Number of possibilities++
						number=k; // Let's store this number for now. We might need it later on.
					}
				if(count==1){ // There's only one possibility for this cell. Yay!
					cell[i][j].value=number; // This is why we stored that number.
					cell[i][j].type=LOGIC_FIND;
					flag=true; // We found something when this function was called.
				}
			}
		}
	if(flag)
		return logicStep1(); // This wasn't a futile call. Let's do it again.
	else
		return false; // This was a futile call
}

bool logicStep2(){ // A.k.a it only fits here.
	bool flag=false;
	// Let's loop through the columns and check if any value fits in only one of the cells
	for(int c=0;c&lt;9;c++){
		int no[]={0,0,0,0,0,0,0,0,0,0}, pos[]={0,0,0,0,0,0,0,0,0}; // Sorry I wasted 2 bytes.
		for(int r=0;r&lt;9;r++)
			if(cell[r][c].value==0)
				for(int k=1;k&lt;10;k++)
					if(isValid(r,c,k)){
						no[k]++;
						pos[k]=r;
					}
		for(int k=1; k&lt;10; k++) // Loop from 1 to 9.
			if(no[k]==1){ // This number only fits at one place. Let's put it there.
				cell[pos[k]][c].value=k;
				cell[pos[k]][c].type=LOGIC_FIND;
				flag=true;
			}
	}
	// And now the rows
	for(int r=0;r&lt;9;r++){
		int no[]={0,0,0,0,0,0,0,0,0,0},pos[]={0,0,0,0,0,0,0,0,0};
		for(int c=0;c&lt;9;c++)
			for(int k=1;k&lt;10;k++)
				if(cell[r][c].value==0)
					if(isValid(r,c,k)){
						no[k]++;
						pos[k]=c;
					}
		for(k=1; k&lt;10; k++)
			if(no[k]==1){
				cell[r][pos[k]].value=k;
				cell[r][pos[k]].type=LOGIC_FIND;
				flag=true;
			}
	}
	// Also the boxes.
	int no[]={0,0,0,0,0,0,0,0,0},posx[]={0,0,0,0,0,0,0,0,0},posy[]={0,0,0,0,0,0,0,0,0};
	for(int i=0;i&lt;3;i++)
		for(int j=0;j&lt;3;j++){
			for(r=i*3;r&lt;i*3+3;r++)
				for(c=j*3;c&lt;j*3+3;c++)
					if(cell[r][c].value==0)
						for(int k=1;k&lt;10;k++)
							if(isValid(r,c,k)){
								no[k]++;
								posx[k]=r;
								posy[k]=c;
							}
			for(int k=1; k&lt;10; k++)
				if(no[k]==1){
					cell[posx[k]][posy[k]].value=k;
					cell[posx[k]][posy[k]].type=LOGIC_FIND;
					flag=true;
				}
		}
	if(flag)
		return logicStep2(); // This wasn't a futile call. Let's do it again.
	else
		return false; // This was a futile call
}

void solveUsingLogic(){ // Keeps on calling the two defined logic functions until the calls become futile.
	bool flag1 = logicStep1();
	bool flag2 = logicStep2();
	if((flag1||flag2) &amp;&amp; !isComplete())
		solveUsingLogic();
	else
		drawSudoku(); // Let's update the sudoku with all that we have.
}
// Oops. Line not found =P.
</pre>
<div class='wpfblike' ><fb:like href='http://www.bhuwankhattar.com/blog/2011/02/11/my-class-xi-computer-science-project/' layout='default' show_faces='true' width='600' action='like' colorscheme='light' send='true' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.bhuwankhattar.com/blog/2011/02/11/my-class-xi-computer-science-project/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>(For the lack of a better title,) Hello world</title>
		<link>http://www.bhuwankhattar.com/blog/2011/02/10/hello-world/</link>
		<comments>http://www.bhuwankhattar.com/blog/2011/02/10/hello-world/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 09:31:29 +0000</pubDate>
		<dc:creator>Bhuwan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[First Post]]></category>
		<category><![CDATA[Introduction]]></category>

		<guid isPermaLink="false">http://www.bhuwankhattar.com/blog/wordpress/?p=1</guid>
		<description><![CDATA[Hello There After having procrastinated for quite some time, I’ve finally succumbed to my wish of having a personal blog (again). While this isn&#8217;t my first foray into blogging, it is certainly one I don&#8217;t ever intend to give up on. Part of the reason why it took me so long to start this online endeavor was]]></description>
			<content:encoded><![CDATA[<div>
<p>Hello There <img src='http://www.bhuwankhattar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>After having procrastinated for quite some time, I’ve finally succumbed to my wish of having a personal blog (again). While this isn&#8217;t my first foray into blogging, it is certainly one I don&#8217;t ever intend to give up on.</p>
<p>Part of the reason why it took me so long to start this online endeavor was my want of the perfect theme for this blog. When I bought this domain back in September ‘10, I picked up the <a href="http://themeshaper.com/">Thematic Framework</a> and threw myself into a quest to shape it into the greatest WordPress theme man had ever seen. Turns out, it is <strong><em>a lot harder</em></strong> to come up with a design for your own personal needs that it is to create something for a client. Perhaps, the prolonged procrastination was a result of me chasing fantasies of perfectionism. (Or at least, so I’d like to believe.)</p>
<p>Anyway, I recently realized that nothing productive was going to come out of this stalling for time. So, I looked around for some free wordpress themes. Of the ones I saw, I liked <a href="http://wordpress.org/extend/themes/mystique">Mystique</a> the most. I went ahead and downloaded the theme, played around with it and tweaked it a little to cater to my rather eccentric needs. And this, what you’re seeing, is how it finally turned out to be. Albeit not exactly the perfect layout I had initially wanted, I think this shall more than do for the time being.</p>
<p>Now, for those of you who have never had the blessed opportunity of knowing me (&lt;/overly-narcissistic&gt;), here is your chance to get to know me. And for those of you who do know me, in one way or the other, an opportunity to perhaps get to know me better as I type down my thoughts and experiences for the purpose of disseminating them through the <a href="http://knowyourmeme.com/memes/series-of-tubes">tubes</a>.</p>
<p>Subscribe to the RSS, look out for my future(edifying and enlightening :P) blog posts, and leave comments regularly so that we can engage in curious discussions. Any suggestions and or constructive criticism is always welcome.</p>
<p>Until then<br />
Bhuwan</p>
</div>
<div class='wpfblike' ><fb:like href='http://www.bhuwankhattar.com/blog/2011/02/10/hello-world/' layout='default' show_faces='true' width='600' action='like' colorscheme='light' send='true' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.bhuwankhattar.com/blog/2011/02/10/hello-world/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
