<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: A Mind Teaser &#8211; good one..!</title>
	<atom:link href="http://blogs.digitss.com/programming/a-mind-teaser-good-one/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/</link>
	<description>DiGiTSS Team&#039;s Programming experience with PHP, MySQL, Ajax, Javascript, jQuery, C# and Microsoft technologies</description>
	<lastBuildDate>Tue, 06 Sep 2011 19:30:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Craig Francis</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7904</link>
		<dc:creator>Craig Francis</dc:creator>
		<pubDate>Sat, 17 Jan 2009 15:16:50 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7904</guid>
		<description>@Kurt 
 
Yes, if you look at the for loops that I provided, they do just that. 
 
Hence why in my examples I re-use variables within the loop, that have just been used to start the loop (e.g. $e). 
 
Going though the loops: 
 
$a) Starts the main loop, but is then used as a countdown to zero, to limit the number of subtractions (done by the second loop). 
 
$b) The divisor, needs to always be available, so the subtraction can be performed on each loop. 
 
$c) Monitors the number of times that the main loop has been run... as this provides the answer to $d, when the second loop cannot be run any more ($a &lt;= 0). 
 
$d) Is first used to perform the subtraction (the temporary variable), but after its done that, it stores the result for when the main loop finishes... I suspect out of all the variables, this is the one to remove. 
 
$e) I used first to calculate ($b - $a) without changing $a (as the loop runs many times - to create the fake &quot;if&quot; condition), and when its completed, $a is updated with the new value from $e. </description>
		<content:encoded><![CDATA[<p>@Kurt </p>
<p>Yes, if you look at the for loops that I provided, they do just that. </p>
<p>Hence why in my examples I re-use variables within the loop, that have just been used to start the loop (e.g. $e). </p>
<p>Going though the loops: </p>
<p>$a) Starts the main loop, but is then used as a countdown to zero, to limit the number of subtractions (done by the second loop). </p>
<p>$b) The divisor, needs to always be available, so the subtraction can be performed on each loop. </p>
<p>$c) Monitors the number of times that the main loop has been run&#8230; as this provides the answer to $d, when the second loop cannot be run any more ($a &lt;= 0). </p>
<p>$d) Is first used to perform the subtraction (the temporary variable), but after its done that, it stores the result for when the main loop finishes&#8230; I suspect out of all the variables, this is the one to remove. </p>
<p>$e) I used first to calculate ($b &#8211; $a) without changing $a (as the loop runs many times &#8211; to create the fake &quot;if&quot; condition), and when its completed, $a is updated with the new value from $e.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Francis</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7903</link>
		<dc:creator>Craig Francis</dc:creator>
		<pubDate>Sat, 17 Jan 2009 15:16:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7903</guid>
		<description>@Ben 
 
Your right about it sounding like a hack, but that does seem to be the only way to get this effect. 
 
I like your examples, but they do use more than the 4 variable target (e.g. in the division, there are 4 variables in that function, but more are used by calling the other functions). 
 
Which is why I removed the use of functions (something that isn&#039;t in the list of allowed constructs), and tried to reduce the number of variables even further (getting it down to 5). 
 
Oh, and as to having only &quot;two&quot; loops in the division... if you look at the code flow, there is actually 5 (2 in main body, 2 from the SUB&#039;s, and 1 from the DEC)... mine on the other hand only uses 4 loops. </description>
		<content:encoded><![CDATA[<p>@Ben </p>
<p>Your right about it sounding like a hack, but that does seem to be the only way to get this effect. </p>
<p>I like your examples, but they do use more than the 4 variable target (e.g. in the division, there are 4 variables in that function, but more are used by calling the other functions). </p>
<p>Which is why I removed the use of functions (something that isn&#039;t in the list of allowed constructs), and tried to reduce the number of variables even further (getting it down to 5). </p>
<p>Oh, and as to having only &quot;two&quot; loops in the division&#8230; if you look at the code flow, there is actually 5 (2 in main body, 2 from the SUB&#039;s, and 1 from the DEC)&#8230; mine on the other hand only uses 4 loops.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt Zoglmann</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7862</link>
		<dc:creator>Kurt Zoglmann</dc:creator>
		<pubDate>Fri, 16 Jan 2009 02:07:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7862</guid>
		<description>@Craig 
Remember that &quot;loop&quot;, as defined in the problem statement, allows one to redefine its value without changing the number of iterations. Thus in something like &quot;loop(v1) { v1 = 0}&quot;, it would still loop 5 times if v1 was set to 5 before hitting the loop. My macro of dec works because v1 is always one behind the value of temp. </description>
		<content:encoded><![CDATA[<p>@Craig</p>
<p>Remember that &quot;loop&quot;, as defined in the problem statement, allows one to redefine its value without changing the number of iterations. Thus in something like &quot;loop(v1) { v1 = 0}&quot;, it would still loop 5 times if v1 was set to 5 before hitting the loop. My macro of dec works because v1 is always one behind the value of temp.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7816</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Tue, 13 Jan 2009 21:37:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7816</guid>
		<description>my attempt can be found here: &lt;a href=&quot;http://regenmytoolkit.blogspot.com/2009/01/computational-mind-teaser.html/dontfollow&quot;&gt;http://regenmytoolkit.blogspot.com/2009/01/comput...&lt;/a&gt; 
 
I like the DIV with only two loops but I feel like the use of c to reduce the looped increment to a single increment is a hack. </description>
		<content:encoded><![CDATA[<p>my attempt can be found here: <a href="http://regenmytoolkit.blogspot.com/2009/01/computational-mind-teaser.html" rel="nofollow">http://regenmytoolkit.blogspot.com/2009/01/comput&#8230;</a> </p>
<p>I like the DIV with only two loops but I feel like the use of c to reduce the looped increment to a single increment is a hack.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Francis</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7810</link>
		<dc:creator>Craig Francis</dc:creator>
		<pubDate>Tue, 13 Jan 2009 16:58:33 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7810</guid>
		<description>For anyone who is interested in a description with my solution to problem 3, the first loop is just to get it to loop as many times as possible (i.e. I would like to say, keep dividing until $a is zero, but this is good enough)... the second loop is like an if statement, although it will run many times, it will keep doing the same thing, unless of course a is zero (not run at all)... the fourth (note, not third) loop does the minus one, while the third repeats that minus one $b times. 
 
@ronen cohen: 
 
Aww, that&#039;s cheating... not only does it use 5 variables (a, b, c, k and m), it also goes out to a function (no if statements or anything like that) which presumably uses more variables... and you have an &quot;m = 1&quot;, and a &quot;subtract(a, 1)&quot;... where you can only set a variable to 0. 
 
And later on, I don&#039;t understand why you have a c++, when it doesn&#039;t seem to be used... did you copy the right version over? 
 
So, the question remains, can it be done in less than or equal to 4 variables? 
 
@kurt zoglmann: 
 
I&#039;ve already got stuck on your &quot;dec&quot; function (copy below)... as temp = 0, how would the loop(temp) run to increment v1? 
 
I am presuming that the inc() function just increments the value by 1 (e.g. v1++). 
 
macro dec (v1, temp) { 
temp = 0 
loop(v1) { 
v1 = 0 
loop(temp) { 
inc(v1) 
} 
inc(temp) 
} 
} </description>
		<content:encoded><![CDATA[<p>For anyone who is interested in a description with my solution to problem 3, the first loop is just to get it to loop as many times as possible (i.e. I would like to say, keep dividing until $a is zero, but this is good enough)&#8230; the second loop is like an if statement, although it will run many times, it will keep doing the same thing, unless of course a is zero (not run at all)&#8230; the fourth (note, not third) loop does the minus one, while the third repeats that minus one $b times. </p>
<p>@ronen cohen: </p>
<p>Aww, that&#039;s cheating&#8230; not only does it use 5 variables (a, b, c, k and m), it also goes out to a function (no if statements or anything like that) which presumably uses more variables&#8230; and you have an &quot;m = 1&quot;, and a &quot;subtract(a, 1)&quot;&#8230; where you can only set a variable to 0. </p>
<p>And later on, I don&#039;t understand why you have a c++, when it doesn&#039;t seem to be used&#8230; did you copy the right version over? </p>
<p>So, the question remains, can it be done in less than or equal to 4 variables? </p>
<p>@kurt zoglmann: </p>
<p>I&#039;ve already got stuck on your &quot;dec&quot; function (copy below)&#8230; as temp = 0, how would the loop(temp) run to increment v1? </p>
<p>I am presuming that the inc() function just increments the value by 1 (e.g. v1++). </p>
<p>macro dec (v1, temp) {<br />
temp = 0<br />
loop(v1) {<br />
v1 = 0<br />
loop(temp) {<br />
inc(v1)<br />
}<br />
inc(temp)<br />
}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Clapper</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7799</link>
		<dc:creator>Brian Clapper</dc:creator>
		<pubDate>Tue, 13 Jan 2009 07:02:38 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7799</guid>
		<description>Highly fun. Had everyone in the office going. Thanks! </description>
		<content:encoded><![CDATA[<p>Highly fun. Had everyone in the office going. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt Zoglmann</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7794</link>
		<dc:creator>Kurt Zoglmann</dc:creator>
		<pubDate>Tue, 13 Jan 2009 02:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7794</guid>
		<description>hmm.. i guess i&#039;ll post my answer. i didn&#039;t realize there were some posts already. 
this is pseudo code. 
 
//decided to make it more challenging by not allowing post increment :) 
// when v1 is 0 returns 0 
macro dec (v1, temp) { 
  temp = 0 
  loop(v1) { 
    v1 = 0 
    loop(temp) { 
      inc(v1) 
    } 
    inc(temp) 
  } 
} 
 
//equivalent to x = x - y or x-= y 
//when y &gt; x in x - y, then x = 0 
macro subtract-equal(v1, v2, temp) { 
  loop(v2) { 
    dec(v1,temp) 
  } 
} 
 
//equivalent to x = x / y or x /= y 
//throws away remainder 
//infinite loop when given 0 for v2 and v1 &gt;= 1 
//when 0 / 0 it equals 0 instead of error or infinite loop 
macro divide-equal(v1, v2, temp, div-temp) { 
  div-temp = 0 
  loop(v1) { 
    subtract-equal(v1,v2,temp) 
 
    loop(v1) { 
      inc(div-temp) 
    } 
    dec(v1,temp) 
    loop(v1) { 
      dec(div-temp) 
    } 
    inc(v1) 
  } 
 
  v1 = div-temp 
} 
 
hopefully i didn&#039;t make a mistake. i didn&#039;t test this except by hand. </description>
		<content:encoded><![CDATA[<p>hmm.. i guess i&#039;ll post my answer. i didn&#039;t realize there were some posts already.</p>
<p>this is pseudo code.</p>
<p>//decided to make it more challenging by not allowing post increment <img src='http://blogs.digitss.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>// when v1 is 0 returns 0</p>
<p>macro dec (v1, temp) {</p>
<p>  temp = 0</p>
<p>  loop(v1) {</p>
<p>    v1 = 0</p>
<p>    loop(temp) {</p>
<p>      inc(v1)</p>
<p>    }</p>
<p>    inc(temp)</p>
<p>  }</p>
<p>}</p>
<p>//equivalent to x = x &#8211; y or x-= y</p>
<p>//when y &gt; x in x &#8211; y, then x = 0</p>
<p>macro subtract-equal(v1, v2, temp) {</p>
<p>  loop(v2) {</p>
<p>    dec(v1,temp)</p>
<p>  }</p>
<p>}</p>
<p>//equivalent to x = x / y or x /= y</p>
<p>//throws away remainder</p>
<p>//infinite loop when given 0 for v2 and v1 &gt;= 1</p>
<p>//when 0 / 0 it equals 0 instead of error or infinite loop</p>
<p>macro divide-equal(v1, v2, temp, div-temp) {</p>
<p>  div-temp = 0</p>
<p>  loop(v1) {</p>
<p>    subtract-equal(v1,v2,temp)</p>
<p>    loop(v1) {</p>
<p>      inc(div-temp)</p>
<p>    }</p>
<p>    dec(v1,temp)</p>
<p>    loop(v1) {</p>
<p>      dec(div-temp)</p>
<p>    }</p>
<p>    inc(v1)</p>
<p>  }</p>
<p>  v1 = div-temp</p>
<p>}</p>
<p>hopefully i didn&#039;t make a mistake. i didn&#039;t test this except by hand.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ronen cohen</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7793</link>
		<dc:creator>ronen cohen</dc:creator>
		<pubDate>Tue, 13 Jan 2009 02:47:59 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7793</guid>
		<description>Sorry, that was wrong: 
 
a = 10 
b = 2 
c = 0 
 
loop (a) 
{ 
k = b 
loop (a) 
{ 
m = 1 
loop (k) 
{ 
loop (m) 
{ 
c++ 
m = 0 
} 
a = subtract(a, 1) 
k = 0 
} 
} 
} 
 
// outputs 5 
print c </description>
		<content:encoded><![CDATA[<p>Sorry, that was wrong:</p>
<p>a = 10</p>
<p>b = 2</p>
<p>c = 0</p>
<p>loop (a)</p>
<p>{</p>
<p>k = b</p>
<p>loop (a)</p>
<p>{</p>
<p>m = 1</p>
<p>loop (k)</p>
<p>{</p>
<p>loop (m)</p>
<p>{</p>
<p>c++</p>
<p>m = 0</p>
<p>}</p>
<p>a = subtract(a, 1)</p>
<p>k = 0</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>// outputs 5</p>
<p>print c</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt Zoglmann</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7792</link>
		<dc:creator>Kurt Zoglmann</dc:creator>
		<pubDate>Tue, 13 Jan 2009 02:35:16 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7792</guid>
		<description>This was quite the bugger of a problem. I was able to complete the entire thing by myself in 3 hours. I allowed the subtract macro to overwrite the first argument, so it was like saying x = x-y or x -= y. I also assumed that it was okay to say that 5 -10 = 0 since there are no negative numbers. I am tempted to post the answer here just for proof. This was ridiculously hard. I hope you don&#039;t do these kind of problems every week or you probably don&#039;t get much done. </description>
		<content:encoded><![CDATA[<p>This was quite the bugger of a problem. I was able to complete the entire thing by myself in 3 hours. I allowed the subtract macro to overwrite the first argument, so it was like saying x = x-y or x -= y. I also assumed that it was okay to say that 5 -10 = 0 since there are no negative numbers. I am tempted to post the answer here just for proof. This was ridiculously hard. I hope you don&#039;t do these kind of problems every week or you probably don&#039;t get much done.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ronen cohen</title>
		<link>http://blogs.digitss.com/programming/a-mind-teaser-good-one/comment-page-1/#comment-7791</link>
		<dc:creator>ronen cohen</dc:creator>
		<pubDate>Tue, 13 Jan 2009 02:01:54 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.digitss.com/?p=200#comment-7791</guid>
		<description>craig: My idea was similar to yours for 1 &amp; 2 but for 3 I did: 
 
a = 10 
b = 2 
c = 0 
 
loop (a) 
{ 
loop(a) 
{ 
a = subtract(a, b) 
c++; 
} 
} 
 
// outputs 5 
print c </description>
		<content:encoded><![CDATA[<p>craig: My idea was similar to yours for 1 &amp; 2 but for 3 I did:</p>
<p>a = 10</p>
<p>b = 2</p>
<p>c = 0</p>
<p>loop (a)</p>
<p>{</p>
<p>loop(a)</p>
<p>{</p>
<p>a = subtract(a, b)</p>
<p>c++;</p>
<p>}</p>
<p>}</p>
<p>// outputs 5</p>
<p>print c</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.363 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2011-09-11 10:49:58 -->

