<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-9193160645817040317.post472101952133955419..comments</id><updated>2009-07-12T13:03:08.255+05:30</updated><title type='text'>Comments on Twisters - The new age Java Quiz: Puzzle 40 - Divide and optimize (Optimization Seri...</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://twisters.quiz4j.com/feeds/472101952133955419/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html'/><author><name>Saifuddin.Merchant</name><uri>http://www.blogger.com/profile/09008041357659535766</uri><email>saifuddin.merchant@gmail.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-3285240865385854476</id><published>2009-07-12T02:23:52.693+05:30</published><updated>2009-07-12T02:23:52.693+05:30</updated><title type='text'>do {

            va = true; //Assume that i is a ...</title><content type='html'>do {&lt;br /&gt;&lt;br /&gt;            va = true; //Assume that i is a valid answer to the puzzle&lt;br /&gt;&lt;br /&gt;            for (int d=20;d&amp;gt;=11&amp;amp;&amp;amp;va;d--) {&lt;br /&gt;                if (!isDivisble(i, d)) { //Yikes my assumption was wrong!&lt;br /&gt;&lt;br /&gt;                    va = false;&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            i++;&lt;br /&gt;&lt;br /&gt;        } while (!va);</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/3285240865385854476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/3285240865385854476'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247345632693#c3285240865385854476' title=''/><author><name>SlimMo</name><uri>http://www.blogger.com/profile/13802280639197311708</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-5630424192944403151</id><published>2009-07-10T02:11:28.062+05:30</published><updated>2009-07-10T02:11:28.062+05:30</updated><title type='text'>You should understand that this number must be div...</title><content type='html'>You should understand that this number must be divided without reminder to all prime numbers at range [1..20] and it is worthless to make step smaller than 1*2*3*5*7*11*13*17*19 = 9699690&lt;br /&gt;&lt;br /&gt;So you shold replace:&lt;br /&gt;&lt;br /&gt;&amp;quot;i=1&amp;quot; to &amp;quot;i=9699690&amp;quot; : 8 actions&lt;br /&gt;&amp;quot;i++&amp;quot; to &amp;quot;i+=9699690&amp;quot;: 8 actions&lt;br /&gt;&lt;br /&gt;Sum: 8+8 = 16 actions. Fits!&lt;br /&gt;&lt;br /&gt;Just for bonus, not to be puzzled with incorrect output as answer, you shold replace&lt;br /&gt;&amp;quot;System.out.println(i)&amp;quot; to &amp;quot;System.out.println(i-9699690&amp;quot;);&lt;br /&gt;&lt;br /&gt;My optimization:&lt;br /&gt;&lt;br /&gt;232792560&lt;br /&gt;Not optimized: 110.33363&lt;br /&gt;Optimized: 0.008186197&lt;br /&gt;Saved: 0.99992585% of time</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/5630424192944403151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/5630424192944403151'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247172088062#c5630424192944403151' title=''/><author><name>TheMalkolm</name><uri>http://www.blogger.com/profile/11358745568436186926</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-4736101928206261573</id><published>2009-07-09T21:11:51.968+05:30</published><updated>2009-07-09T21:11:51.968+05:30</updated><title type='text'>The best I could come up with is this:
        int...</title><content type='html'>The best I could come up with is this:&lt;br /&gt;        int d,i = 1;&lt;br /&gt;        d=1;&lt;br /&gt;        do{&lt;br /&gt;          for (int s=d;!isDivisble(d, i);d+=s){&lt;br /&gt;          }&lt;br /&gt;        } while (++i != 21);&lt;br /&gt;&lt;br /&gt;        System.out.println(d);&lt;br /&gt;&lt;br /&gt;I don&amp;#39;t know if 18 changes is enough to get to this snippet, even if the cut/paste rule is used extensively, but I fear not. However if it does, this tiny snippet runs in less than 1.25 microseconds (thats like 0.000001s) and is quite an optimization, I would say. To be fair it uses a different algorithm, although at first glance it seems structurally similar.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/4736101928206261573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/4736101928206261573'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247154111968#c4736101928206261573' title=''/><author><name>Sebastian</name><uri>http://www.yworks.com</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-2273592679001471443</id><published>2009-07-09T20:30:44.140+05:30</published><updated>2009-07-09T20:30:44.140+05:30</updated><title type='text'>Here is my approach, it takes about 0.3 seconds
We...</title><content type='html'>Here is my approach, it takes about 0.3 seconds&lt;br /&gt;We add a step variable (s) that increments i in steps of 20 and we start at 20 (because the number should be divisible by 20, this makes total sense)&lt;br /&gt;Also we break the check early if it fails and we invert the check to start with the greatest number (going 20,19,18....) it is less likely that a number is not divisible by a greater number.&lt;br /&gt;Note that my program outputs the correct solution (the original code outputs i+1) so the output differs (but is more correct).&lt;br /&gt;If I count correctly this makes exactly 18 changes, but using the copy paste rule it could be a lot less and perform even slightly better (cuttung the &amp;#39;=&amp;#39; sign and using it as the assignment for s, e.g. or moving the&amp;#39;20&amp;#39; to get the initial assignment and then compare against s, etc.etc.).&lt;br /&gt;&lt;br /&gt;          int s,i = 20;&lt;br /&gt;          s=i;&lt;br /&gt;          boolean va = true;&lt;br /&gt;&lt;br /&gt;          /* Start looping though all the numbers and see if we can find one divisible by all numbers  from 1 to 20.&lt;br /&gt;            */&lt;br /&gt;          do {&lt;br /&gt;            va = true;  //Assume that i is a valid answer to the puzzle&lt;br /&gt;            for (int d = 1; d &amp;lt;= 20; d++) {&lt;br /&gt;              if (!isDivisble(i,21-d)) {  //Yikes my assumption was wrong!&lt;br /&gt;                va = false;&lt;br /&gt;                d=s;&lt;br /&gt;              }&lt;br /&gt;            }&lt;br /&gt;            i+=s;&lt;br /&gt;          } while (!va);&lt;br /&gt;          System.out.println(i-s);&lt;br /&gt;&lt;br /&gt;removing the &amp;#39;21-&amp;#39; change (and saving 3 changes) will increase the runtime to almost 1 second, so if you want less changes, use this variant ;-)</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/2273592679001471443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/2273592679001471443'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247151644140#c2273592679001471443' title=''/><author><name>Sebastian</name><uri>http://www.yworks.com</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-3467803838100604015</id><published>2009-07-09T17:40:27.523+05:30</published><updated>2009-07-09T17:40:27.523+05:30</updated><title type='text'>Line 28, 11 changes
for(int d=20;d&gt;0;d--){

Line 3...</title><content type='html'>Line 28, 11 changes&lt;br /&gt;for(int d=20;d&amp;gt;0;d--){&lt;br /&gt;&lt;br /&gt;Line 30, 4 changes&lt;br /&gt;va = false;d=0;&lt;br /&gt;&lt;br /&gt;After this we&amp;#39;ll got 15 changes and ~7 seconds. Looks like solved.&lt;br /&gt;&lt;br /&gt;But, If we&amp;#39;ll forget about 18 changes and will move ahead :) than following can be introduces (only even numbers should be checked):&lt;br /&gt;Line 25 (2 changes)&lt;br /&gt;int i = 2;&lt;br /&gt;&lt;br /&gt;Line 33 (3 changes)&lt;br /&gt;i=i+2;&lt;br /&gt;&lt;br /&gt;This will bring us to ~3.5 seconds</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/3467803838100604015'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/3467803838100604015'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247141427523#c3467803838100604015' title=''/><author><name>Yauheni</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-5833086622107990562</id><published>2009-07-09T14:02:05.284+05:30</published><updated>2009-07-09T14:02:05.284+05:30</updated><title type='text'>Here's my offering:
http://www.blogtrog.com/code.a...</title><content type='html'>Here&amp;#39;s my offering:&lt;br /&gt;http://www.blogtrog.com/code.aspx?id=8674f155-ca52-4803-9329-99d2085fad53&lt;br /&gt;&lt;br /&gt;I should have only made 10 character changes and on running through 5x had an average running time of 5.4 seconds.&lt;br /&gt;&lt;br /&gt;You can also eek a bit more out by doing things like replacing the isDivisible call but this does takes you over the 18 characters</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/5833086622107990562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/5833086622107990562'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247128325284#c5833086622107990562' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-5652311056186200217</id><published>2009-07-09T13:32:49.729+05:30</published><updated>2009-07-09T13:32:49.729+05:30</updated><title type='text'>1. Add break; statement on line 30 (+6 characters)...</title><content type='html'>1. Add break; statement on line 30 (+6 characters)&lt;br /&gt;&lt;br /&gt;2. Cut-paste line 33 (i++;) right after line 26.&lt;br /&gt;&lt;br /&gt;3. Change it to i+=20; (+8 characters)&lt;br /&gt;&lt;br /&gt;4. Change line 25 to int i = 20; (+3 characters)&lt;br /&gt;&lt;br /&gt;5. Total changed: 17 characters,  profit!!!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/5652311056186200217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/5652311056186200217'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247126569729#c5652311056186200217' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-3806316778884690098</id><published>2009-07-09T02:56:21.951+05:30</published><updated>2009-07-09T02:56:21.951+05:30</updated><title type='text'>In 18 moves:

int i = 2;
do{
    va = true; //Assu...</title><content type='html'>In 18 moves:&lt;br /&gt;&lt;br /&gt;int i = 2;&lt;br /&gt;do{&lt;br /&gt;    va = true; //Assume that i is a valid answer to the puzzle&lt;br /&gt;    for(int d=20;d&amp;gt;=1&amp;amp;&amp;amp;va;d--){&lt;br /&gt;        if (!isDivisble(i, d)){ //Yikes my assumption was wrong!&lt;br /&gt;            va = false;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    i+=2;&lt;br /&gt;}while(!va);</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/3806316778884690098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/3806316778884690098'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247088381951#c3806316778884690098' title=''/><author><name>Makkhdyn</name><uri>http://www.blogger.com/profile/16225036210991551541</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-9193160645817040317.post-1617372538745283892</id><published>2009-07-09T01:16:09.136+05:30</published><updated>2009-07-09T01:16:09.136+05:30</updated><title type='text'>Diagonalization FTW!!

do{
   va = true; //Assume ...</title><content type='html'>Diagonalization FTW!!&lt;br /&gt;&lt;br /&gt;do{&lt;br /&gt;   va = true; //Assume that i is a valid answer to the puzzle&lt;br /&gt;   for(int d=1;d&amp;lt;=20;d++){&lt;br /&gt;      if (!isDivisble(i, d)){ //Yikes my assumption was wrong!&lt;br /&gt;         va = false;&lt;br /&gt;  i++;&lt;br /&gt;  continue;&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;}while(!va);</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/1617372538745283892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9193160645817040317/472101952133955419/comments/default/1617372538745283892'/><link rel='alternate' type='text/html' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html?showComment=1247082369136#c1617372538745283892' title=''/><author><name>Daniel Creão</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://twisters.quiz4j.com/2009/07/puzzle-40-divide-and-optimize.html' ref='tag:blogger.com,1999:blog-9193160645817040317.post-472101952133955419' source='http://www.blogger.com/feeds/9193160645817040317/posts/default/472101952133955419' type='text/html'/></entry></feed>