<?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>Daniel Hepper &#187; Howto</title>
	<atom:link href="http://daniel.hepper.net/blog/category/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://daniel.hepper.net/blog</link>
	<description>Random geeky stuff</description>
	<lastBuildDate>Wed, 04 Jan 2012 09:12:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to fix VariableDoesNotExist exception in Django</title>
		<link>http://daniel.hepper.net/blog/2010/11/how-to-fix-variabledoesnotexist-exception-in-django/</link>
		<comments>http://daniel.hepper.net/blog/2010/11/how-to-fix-variabledoesnotexist-exception-in-django/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 05:52:27 +0000</pubDate>
		<dc:creator>Daniel Hepper</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Howto]]></category>

		<guid isPermaLink="false">http://daniel.hepper.net/blog/?p=199</guid>
		<description><![CDATA[When Django greets you with this exception: TemplateSyntaxError at / Caught VariableDoesNotExist while rendering: Failed lookup for key [request] in... you are probably using a template tag that requires the request context processor. Simply add &#8216;django.core.context_processors.request&#8217; to the TEMPLATE_CONTEXT_PROCESSORS tuple &#8230; <a href="http://daniel.hepper.net/blog/2010/11/how-to-fix-variabledoesnotexist-exception-in-django/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When Django greets you with this exception:</p>
<p><code>TemplateSyntaxError at /</p>
<p>Caught VariableDoesNotExist while rendering: Failed lookup for key [request] in...</code></p>
<p>you are probably using a template tag that requires the <a href="http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-request">request context processor</a>. Simply add     &#8216;django.core.context_processors.request&#8217; to the TEMPLATE_CONTEXT_PROCESSORS tuple in your settings file.</p>
]]></content:encoded>
			<wfw:commentRss>http://daniel.hepper.net/blog/2010/11/how-to-fix-variabledoesnotexist-exception-in-django/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Howto clear Solr index</title>
		<link>http://daniel.hepper.net/blog/2010/11/howto-clear-solr-index/</link>
		<comments>http://daniel.hepper.net/blog/2010/11/howto-clear-solr-index/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 14:56:43 +0000</pubDate>
		<dc:creator>Daniel Hepper</dc:creator>
				<category><![CDATA[Howto]]></category>

		<guid isPermaLink="false">http://daniel.hepper.net/blog/?p=195</guid>
		<description><![CDATA[If you want to delete all items from Solr index, use the query &#60;delete&#62;&#60;query&#62;*:*&#60;/query&#62;&#60;/delete&#62; as described in the FAQ on the Solr Wiki. But how do you actually send this query? You can use this command: curl http://&#60;host&#62;:&#60;port&#62;/&#60;solr_base&#62;/update?commit=true -d '&#60;delete&#62;&#60;query&#62;*:*&#60;/query&#62;&#60;/delete&#62;' &#8230; <a href="http://daniel.hepper.net/blog/2010/11/howto-clear-solr-index/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div style="float:right; margin-right:-140px;"><script type="text/javascript"><!--
amazon_ad_tag = "danihepp-20"; amazon_ad_width = "120"; amazon_ad_height = "600";//--></script><br />
<script type="text/javascript" src="http://www.assoc-amazon.com/s/ads.js"></script></div>
<p>If you want to delete all items from Solr index, use the query</p>
<pre><tt>&lt;delete&gt;&lt;query&gt;*:*&lt;/query&gt;&lt;/delete&gt;
</tt></pre>
<p>as described in the <a href="http://wiki.apache.org/solr/FAQ#How_can_I_delete_all_documents_from_my_index.3F">FAQ on the Solr Wiki</a>.</p>
<p>But how do you actually send this query? You can use this command:</p>
<pre>curl http://&lt;host&gt;:&lt;port&gt;/&lt;solr_base&gt;/update?commit=true -d '&lt;delete&gt;&lt;query&gt;*:*&lt;/query&gt;&lt;/delete&gt;'</pre>
<p>Just replace the placeholders with the right values, e.g.</p>
<pre>curl http://localhost:8983/solr/update?commit=true -d  '&lt;delete&gt;&lt;query&gt;*:*&lt;/query&gt;&lt;/delete&gt;'</pre>
<p>If Solr responds with something like this:</p>
<pre><strong>HTTP Status 400 - missing content stream</strong>
Status report
<strong>message</strong> missing content stream
<strong>description</strong> The request sent by the client was syntactically incorrect (missing content stream).</pre>
<p>then you are probably missing the commit parameter i.e. ?commit=true</p>
]]></content:encoded>
			<wfw:commentRss>http://daniel.hepper.net/blog/2010/11/howto-clear-solr-index/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to solve the 36 Cube puzzle &#8211; hints &amp; solution</title>
		<link>http://daniel.hepper.net/blog/2010/01/how-to-solve-the-36-cube-puzzle/</link>
		<comments>http://daniel.hepper.net/blog/2010/01/how-to-solve-the-36-cube-puzzle/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 19:00:51 +0000</pubDate>
		<dc:creator>Daniel Hepper</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://daniel.hepper.net/blog/?p=128</guid>
		<description><![CDATA[For Christmas, I got the ThinkFun 36 Cube. It is consists of 36 towers in 6 colors and 6 different sizes and a base plate with 6 by 6 slots to plug in the towers. These slots are of different &#8230; <a href="http://daniel.hepper.net/blog/2010/01/how-to-solve-the-36-cube-puzzle/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For Christmas, I got the <a href="http://www.amazon.com/gp/product/B001F7VI30/ref=as_li_ss_tl?ie=UTF8&#038;tag=danihepp-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=B001F7VI30">ThinkFun 36 Cube</a><img src="http://www.assoc-amazon.com/e/ir?t=&#038;l=as2&#038;o=1&#038;a=B001F7VI30&#038;camp=217145&#038;creative=399369" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. It is consists of 36 towers in 6 colors and 6 different sizes and a base plate with 6 by 6 slots to plug in the towers. These slots are of different heights. The goal is to place one towers of every color in each row and column. And the  towers must fit to form a level cube.</p>
<p>After some tries, I came to the conclusion that this puzzle is the work of the devil and that I should not waste more brain cycles on solving it. So I wrote a little python script to solve the puzzle for me.</p>
<p><a onclick="document.getElementById('34cube').style.display='inline';" href="javascript:void(0)">Show sourcecode</a></p>
<div id="34cube" style="display: none;">

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
COLORS = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span><span style="color: #008000;">zip</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> <span style="color: #66cc66;">&amp;</span>lt<span style="color: #66cc66;">;&amp;</span>lt<span style="color: #66cc66;">;</span> i <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span><span style="color: #483d8b;">'P'</span>,<span style="color: #483d8b;">'Y'</span>,<span style="color: #483d8b;">'O'</span>,<span style="color: #483d8b;">'B'</span>,<span style="color: #483d8b;">'R'</span>,<span style="color: #483d8b;">'G'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
COLORS<span style="color: black;">&#91;</span><span style="color: #008000;">False</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'X'</span>
&nbsp;
used_towers = <span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
cube = <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
solution = <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #008000;">False</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
used = <span style="color: #008000;">tuple</span><span style="color: black;">&#40;</span><span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> test_color<span style="color: black;">&#40;</span>pos, solution, used_towers, color, size<span style="color: black;">&#41;</span>:
 <span style="color: #808080; font-style: italic;">#check if tower of this size and color has already been used</span>
 <span style="color: #ff7700;font-weight:bold;">if</span> color <span style="color: #66cc66;">&amp;</span>amp<span style="color: #66cc66;">;</span> used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span>:
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
 <span style="color: #808080; font-style: italic;">#check if tower has already been used in row or column:</span>
 <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">if</span> color == solution<span style="color: black;">&#91;</span>pos/<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> color == solution<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#93;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
 <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> print_solution<span style="color: black;">&#40;</span>solution<span style="color: black;">&#41;</span>:
 <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">zip</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>COLORS<span style="color: black;">&#91;</span>c<span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> c <span style="color: #ff7700;font-weight:bold;">in</span> solution<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span> - s <span style="color: #ff7700;font-weight:bold;">for</span> s <span style="color: #ff7700;font-weight:bold;">in</span> cube<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> solve<span style="color: black;">&#40;</span>pos, solution, used_towers, best<span style="color: black;">&#41;</span>:
 <span style="color: #ff7700;font-weight:bold;">if</span> pos == <span style="color: #ff4500;">36</span>: <span style="color: #ff7700;font-weight:bold;">return</span> best, solution
 size = cube<span style="color: black;">&#91;</span>pos/<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#93;</span>
 <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span>:
  color = <span style="color: #ff4500;">1</span> <span style="color: #66cc66;">&amp;</span>lt<span style="color: #66cc66;">;&amp;</span>lt<span style="color: #66cc66;">;</span> i
  <span style="color: #ff7700;font-weight:bold;">if</span> test_color<span style="color: black;">&#40;</span>pos, solution, used_towers, color, size<span style="color: black;">&#41;</span>:
   used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span> = used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span> | color
   solution<span style="color: black;">&#91;</span>pos/<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#93;</span> = color
   <span style="color: #ff7700;font-weight:bold;">if</span> pos <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> best:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;#######&quot;</span>, pos + <span style="color: #ff4500;">1</span>, <span style="color: #483d8b;">&quot;towers placed&quot;</span>
    print_solution<span style="color: black;">&#40;</span>solution<span style="color: black;">&#41;</span>
    best = pos
   best, solution = solve<span style="color: black;">&#40;</span>pos+<span style="color: #ff4500;">1</span>, solution, used_towers, best<span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">if</span> best <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span>= <span style="color: #ff4500;">35</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> best, solution
   solution<span style="color: black;">&#91;</span>pos/<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#93;</span> = <span style="color: #008000;">False</span>
   used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span> = used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span> ^ color
 <span style="color: #ff7700;font-weight:bold;">return</span> best, solution
&nbsp;
solve<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, solution, used_towers, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

</div>
<p>My program quickly came up with a correct placement for 34 towers &#8211; but it failed to find the complete solution.</p>
<pre>[('P', 5), ('Y', 3), ('O', 2), ('B', 1), ('R', 4), ('G', 6)]
[('Y', 4), ('O', 1), ('P', 6), ('R', 2), ('G', 5), ('B', 3)]
[('O', 6), ('B', 5), ('R', 3), ('G', 4), ('P', 1), ('Y', 2)]
[('R', 1), ('G', 2), ('Y', 5), ('P', 3), ('B', 6), ('O', 4)]
[('B', 2), ('P', 4), ('G', 1), ('Y', 6), ('O', 3), ('R', 5)]
[('G', 3), ('R', 6), ('B', 4), ('O', 5), ('X', 2), ('X', 1)]</pre>
<p>Legend:<br />
P = Purple, Y = Yellow, O = Orange, B = Blue, R = Red, G = Green, X = Empty<br />
The number is the size of the tower.<br />
As you can see, I didn&#8217;t waste much time on making the output pretty <img src='http://daniel.hepper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="attachment_129" class="wp-caption aligncenter" style="width: 310px"><a href="http://daniel.hepper.net/blog/wp-content/36cube_almost_solved.jpg"><img class="size-medium wp-image-129" title="36cube almost solved" src="http://daniel.hepper.net/blog/wp-content/36cube_almost_solved-300x225.jpg" alt="36cube almost solved" width="300" height="225" /></a><p class="wp-caption-text">So close and yet so far</p></div>
<p>After spending lots of time verifying that my program was working correctly, I became impatient and googled for help. I found an answer, but it revealed to much, taking all the fun.</p>
<p>Therefore, I split my solution into multiple hints. If you are stuck, reveal just one of them at a time and try to figure it out by yourself. It is way more rewarding!</p>
<p>Hint #1 <a onclick="document.getElementById('hint1').style.display='inline';" href="javascript:void(0)">(show)</a>: <span id="hint1" style="display: none;">Your assumptions are probably wrong.<br />
Now go back and try to solve it. I&#8217;m waiting here.</span></p>
<p>Hint #2 <a onclick="document.getElementById('hint2').style.display='inline';" href="javascript:void(0)">(show)</a>: <span id="hint2" style="display: none;">The assumption that all towers of the same size only differ in color is wrong.</span></p>
<p>Hint #3 <a onclick="document.getElementById('hint3').style.display='inline';" href="javascript:void(0)">(show)</a>: <span id="hint3" style="display: none;">There are two towers which do fit on slots where the other towers of the same size do not fit.</span></p>
<p>Hint #4 <a onclick="document.getElementById('hint4').style.display='inline';" href="javascript:void(0)">(show)</a>: <span id="hint4" style="display: none;">The two special towers are the yellow one of heigh 5 and the orange one of height 6.</span></p>
<p>Hint #5 <a onclick="document.getElementById('hint5').style.display='inline';" href="javascript:void(0)">(show)</a>: <span id="hint5" style="display: none;">The yellow tower of height 5 has to go to position (1,2) and the orange tower of height 6 to (3,2) in my coordinate system.</span></p>
<p>Even if you uncovered all hints, the puzzle is still far from solved. You can still tinker with it forever.</p>
<p>Spoiler alert: Don&#8217;t uncover the solution, unless your are really desperate!</p>
<p><strong><a onclick="document.getElementById('solution').style.display='inline';" href="javascript:void(0)">Click to show the 36cube solution.</a></strong></p>
<div id="solution" style="display: none;">After I had found the two culprits, I adjusted my program by changing the array and inserting two special conditions. Within seconds I had a complete solution of the 36 Cube:</p>
<pre>[('P', 5), ('Y', 3), ('B', 2), ('O', 1), ('R', 4), ('G', 6)]
[('B', 4), ('P', 1), ('Y', 5), ('G', 2), ('O', 5), ('R', 3)]
[('R', 6), ('G', 5), ('P', 3), ('Y', 4), ('B', 1), ('O', 2)]
[('G', 1), ('R', 2), ('O', 6), ('B', 3), ('Y', 6), ('P', 4)]
[('Y', 2), ('O', 4), ('R', 1), ('P', 6), ('G', 3), ('B', 5)]
[('O', 3), ('B', 6), ('G', 4), ('R', 5), ('P', 2), ('Y', 1)]</pre>
<div id="attachment_130" class="wp-caption aligncenter" style="width: 310px"><a href="http://daniel.hepper.net/blog/wp-content/36cube_complete_solution.jpg"><img class="size-medium wp-image-130" title="36cube complete solution" src="http://daniel.hepper.net/blog/wp-content/36cube_complete_solution-300x225.jpg" alt="" width="300" height="225" /></a><p class="wp-caption-text">Finally solved</p></div>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
COLORS = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span><span style="color: #008000;">zip</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> <span style="color: #66cc66;">&amp;</span>lt<span style="color: #66cc66;">;&amp;</span>lt<span style="color: #66cc66;">;</span> i <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span><span style="color: #483d8b;">'P'</span>,<span style="color: #483d8b;">'Y'</span>,<span style="color: #483d8b;">'O'</span>,<span style="color: #483d8b;">'B'</span>,<span style="color: #483d8b;">'R'</span>,<span style="color: #483d8b;">'G'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
COLORS<span style="color: black;">&#91;</span><span style="color: #008000;">False</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'X'</span>
&nbsp;
used_towers = <span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># definition with (1,2) and (3,2) switched</span>
cube = <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>,
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
solution = <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #008000;">False</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
used = <span style="color: #008000;">tuple</span><span style="color: black;">&#40;</span><span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> test_color<span style="color: black;">&#40;</span>pos, solution, used_towers, color, size<span style="color: black;">&#41;</span>:
 <span style="color: #808080; font-style: italic;">#check if tower of this size and color has already been used</span>
 <span style="color: #ff7700;font-weight:bold;">if</span> color <span style="color: #66cc66;">&amp;</span>amp<span style="color: #66cc66;">;</span> used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span>:
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
 <span style="color: #808080; font-style: italic;">#check if tower has already been used in row or column:</span>
 <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">if</span> color == solution<span style="color: black;">&#91;</span>pos/<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> color == solution<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#93;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
 <span style="color: #808080; font-style: italic;"># special conditions for the two special towers</span>
 <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>pos/<span style="color: #ff4500;">6</span>, pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#41;</span> == <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> color <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">2</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
 <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>pos/<span style="color: #ff4500;">6</span>, pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#41;</span> == <span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> color <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">4</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
 <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> print_solution<span style="color: black;">&#40;</span>solution<span style="color: black;">&#41;</span>:
 <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">zip</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>COLORS<span style="color: black;">&#91;</span>c<span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> c <span style="color: #ff7700;font-weight:bold;">in</span> solution<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span> - s <span style="color: #ff7700;font-weight:bold;">for</span> s <span style="color: #ff7700;font-weight:bold;">in</span> cube<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> solve<span style="color: black;">&#40;</span>pos, solution, used_towers, best<span style="color: black;">&#41;</span>:
 <span style="color: #ff7700;font-weight:bold;">if</span> pos == <span style="color: #ff4500;">36</span>: <span style="color: #ff7700;font-weight:bold;">return</span> best, solution
 size = cube<span style="color: black;">&#91;</span>pos/<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#93;</span>
 <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span>:
  color = <span style="color: #ff4500;">1</span> <span style="color: #66cc66;">&amp;</span>lt<span style="color: #66cc66;">;&amp;</span>lt<span style="color: #66cc66;">;</span> i
  <span style="color: #ff7700;font-weight:bold;">if</span> test_color<span style="color: black;">&#40;</span>pos, solution, used_towers, color, size<span style="color: black;">&#41;</span>:
   used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span> = used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span> | color
   solution<span style="color: black;">&#91;</span>pos/<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#93;</span> = color
   <span style="color: #ff7700;font-weight:bold;">if</span> pos <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> best:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;#######&quot;</span>, pos + <span style="color: #ff4500;">1</span>, <span style="color: #483d8b;">&quot;towers placed&quot;</span>
    print_solution<span style="color: black;">&#40;</span>solution<span style="color: black;">&#41;</span>
    best = pos
   best, solution = solve<span style="color: black;">&#40;</span>pos+<span style="color: #ff4500;">1</span>, solution, used_towers, best<span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">if</span> best <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span>= <span style="color: #ff4500;">35</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> best, solution
   solution<span style="color: black;">&#91;</span>pos/<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos<span style="color: #66cc66;">%</span>6<span style="color: black;">&#93;</span> = <span style="color: #008000;">False</span>
   used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span> = used_towers<span style="color: black;">&#91;</span>size<span style="color: black;">&#93;</span> ^ color
 <span style="color: #ff7700;font-weight:bold;">return</span> best, solution
&nbsp;
solve<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, solution, used_towers, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

</div>
<p><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_3089d50b-fc20-4ced-af4c-acee3186a117"  WIDTH="600px" HEIGHT="200px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?rt=tf_cw&#038;ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fdanihepp-20%2F8010%2F3089d50b-fc20-4ced-af4c-acee3186a117&#038;Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?rt=tf_cw&#038;ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fdanihepp-20%2F8010%2F3089d50b-fc20-4ced-af4c-acee3186a117&#038;Operation=GetDisplayTemplate" id="Player_3089d50b-fc20-4ced-af4c-acee3186a117" quality="high" bgcolor="#ffffff" name="Player_3089d50b-fc20-4ced-af4c-acee3186a117" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="200px" width="600px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?rt=tf_cw&#038;ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fdanihepp-20%2F8010%2F3089d50b-fc20-4ced-af4c-acee3186a117&#038;Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT></p>
]]></content:encoded>
			<wfw:commentRss>http://daniel.hepper.net/blog/2010/01/how-to-solve-the-36-cube-puzzle/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Automatic plugin update problem in WordPress 2.8.x</title>
		<link>http://daniel.hepper.net/blog/2009/09/automatic-plugin-update-problem-in-wordpress-2-8-x/</link>
		<comments>http://daniel.hepper.net/blog/2009/09/automatic-plugin-update-problem-in-wordpress-2-8-x/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 20:15:13 +0000</pubDate>
		<dc:creator>Daniel Hepper</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://daniel.hepper.net/blog/?p=115</guid>
		<description><![CDATA[After upgrading WordPress to the current version, I could no longer automatically update plugins. This is the error message I got: Downloading update from http://downloads.wordpress.org/plugin/xxx.zip. Unpacking the update. Warning: unlink(/&#8230;/wp-content/upgrade/xxx.zip) [function.unlink]: No such file or directory in /&#8230;/wp-admin/includes/class-wp-upgrader.php on line &#8230; <a href="http://daniel.hepper.net/blog/2009/09/automatic-plugin-update-problem-in-wordpress-2-8-x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After upgrading WordPress to the current version, I could no longer automatically update plugins. This is the error message I got:</p>
<blockquote><p>Downloading update from <span>http://downloads.wordpress.org/plugin/xxx.zip</span>.</p>
<p>Unpacking the update.<br />
<strong>Warning</strong>:  unlink(/&#8230;/wp-content/upgrade/xxx.zip) [function.unlink]: No such file or directory in <strong>/&#8230;/wp-admin/includes/class-wp-upgrader.php</strong> on line <strong>146</strong></p>
<p>Incompatible archive PCLZIP_ERR_MISSING_FILE (-4) : Missing archive file &#8216;/&#8230;/wp-content/upgrade/wp-syntax.0.9.8.zip&#8217;</p></blockquote>
<p>After digging through the forums I found a <a href="http://wordpress.org/support/topic/278788?replies=20#post-1133939">solution to the plugin autoupdate problem in the WordPress Support forum</a>.</p>
<p>Open the file wp-config.php in the root directory of your WordPress installation and remove the definition of the WP_TEMP_DIR variable, i.e. a line that looks like this</p>
<pre>define('WP_TEMP_DIR', ABSPATH . "wp-content/upgrade");</pre>
]]></content:encoded>
			<wfw:commentRss>http://daniel.hepper.net/blog/2009/09/automatic-plugin-update-problem-in-wordpress-2-8-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WLAN an der Uni Karlsruhe (DUKATH) mit Ubuntu 8.10</title>
		<link>http://daniel.hepper.net/blog/2008/12/wlan-an-der-uni-karlsruhe-mit-ubuntu/</link>
		<comments>http://daniel.hepper.net/blog/2008/12/wlan-an-der-uni-karlsruhe-mit-ubuntu/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 14:25:55 +0000</pubDate>
		<dc:creator>Daniel Hepper</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[uni]]></category>

		<guid isPermaLink="false">http://daniel.hepper.net/blog/?p=56</guid>
		<description><![CDATA[Ubuntu hat inzwischen eine ziemlich gute WLAN-Unterstützung. Lange Zeit konnte DUKATH nur[1] mit einem VPN-Client genutzt werden, inzwischen geht das auch per WPA. Laut Anleitung des Microbit [PDF] soll man ein Skript schreiben um den Zugang zu nutzen. Unter Ubuntu &#8230; <a href="http://daniel.hepper.net/blog/2008/12/wlan-an-der-uni-karlsruhe-mit-ubuntu/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ubuntu hat inzwischen eine ziemlich gute WLAN-Unterstützung. Lange Zeit konnte DUKATH nur[<a href="#footnote1"><span style="color: #888888;">1</span></a>] mit einem VPN-Client genutzt werden, inzwischen geht das auch per WPA. Laut <a href="http://www.rz.uni-karlsruhe.de/download/files/Flyer_05_1_DUKATH_Wireless.pdf">Anleitung des Microbit [PDF]</a> soll man ein Skript schreiben um den Zugang zu nutzen. Unter Ubuntu geht es aber auch etwas einfacher:</p>
<p>Auf das Symbol des Netzwerk-Manager-Applet klicken:</p>
<p>Das Netzwerk dukath-??x auswählen.</p>
<p>?? hängt vom Standort ab. Beim RZ gibt es eine <a href="http://www.rz.uni-karlsruhe.de/dienste/5692.php">Übersicht über die verwendeten SSIDs</a>.</p>
<div id="attachment_62" class="wp-caption aligncenter" style="width: 432px"><a href="http://daniel.hepper.net/blog/wp-content/wlan_dukath_auswahl.jpg"><img class="size-full wp-image-62" title="wlan_dukath_auswahl" src="http://daniel.hepper.net/blog/wp-content/wlan_dukath_auswahl.jpg" alt="Auswahl DUKATH-Accesspoint" width="422" height="654" /></a><p class="wp-caption-text">Auswahl DUKATH-Accesspoint</p></div>
<p>Im darauf folgenden Dialog die richtigen Werte eintragen:</p>
<div id="attachment_63" class="wp-caption aligncenter" style="width: 510px"><a href="http://daniel.hepper.net/blog/wp-content/wlan_dukath_ubuntu_dialog.jpg"><img class="size-full wp-image-63" title="wlan_dukath_ubuntu_dialog" src="http://daniel.hepper.net/blog/wp-content/wlan_dukath_ubuntu_dialog.jpg" alt="Einstellungen DUKATH" width="500" height="512" /></a><p class="wp-caption-text">Einstellungen DUKATH</p></div>
<p>Bei Zertifikat sollte das <a href="https://www.pki.dfn.de/fileadmin/PKI/zertifikate/deutsche-telekom-root-ca-2.pem">Deutsche Telekom Root CA 2 Zertifikat</a> ausgewählt werden.</p>
<p>Benutzername und Passwort entsprechen denen bei der Verwendung von VPN.</p>
<p>Fertig!</p>
<p><a href="http://daniel.hepper.net/blog/wp-content/wlan_dukath_dhcp.jpg"><img class="aligncenter size-full wp-image-64" title="wlan_dukath_dhcp" src="http://daniel.hepper.net/blog/wp-content/wlan_dukath_dhcp.jpg" alt="" width="292" height="87" /></a></p>
<p><a name="footnote1">[1]</a> Der Zugang über das <a href="https://dukath-www.rz.uni-karlsruhe.de/">DUKATH Web-Interface</a> sollte nur in Notfällen genutzt werden, da die Verbindung nicht verschlüsselt wird und deshalb einfach abgehört werden kann.</p>
]]></content:encoded>
			<wfw:commentRss>http://daniel.hepper.net/blog/2008/12/wlan-an-der-uni-karlsruhe-mit-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

