tag:blogger.com,1999:blog-6324825125217268911.post514184801595684591..comments2018-05-28T18:05:05.936+01:00Comments on Hackensplat Industries: Computers are fast!Bill P. Godfreyhttp://www.blogger.com/profile/15666992178755985254noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-6324825125217268911.post-11572052178056503852010-10-16T06:58:06.765+01:002010-10-16T06:58:06.765+01:00I'm the one that wrote "Fast is relative&...I'm the one that wrote "Fast is relative" and I'm back. You said you wanted something fast and easy to do. OK, I get that you knew there were better ways and accepted your way is "easy".<br />Nope, not easy. Lazy thinking is more like it. You ended up doing a lot more work than you needed to do.<br />The algorithm:Give the number and the number of positions. OK, so now I'm tied to your computer program to get my crib sheet. I've also got to write a user interface to supply those numbers and return those answers. (A windows app?)<br />I'm thinking Hmmm, if we put the numbers in excel, it has great filters just give it all the possible solutions and all the number of positions that can do the solution.<br />Sorry, I didn't read your original post of giving up to 9 positions. 9 is ridiculous, there is only one answer and its the same as giving no clues in that sheet. 8 is almost as bad since there are 8 possible numbers and only one solution possible. It gives you one answer on the sheet from 1 to 9 if the number is 44, the answer is 1 and if the number is 36, the answer is 9. I'm not going to fix my algorithm to go up to 8 because I don't do killer suduko. (KenKen, yes. Regular suduko, yes.)<br />You have a lot of checking to do when you get up to 6 numbers. The first number can't be equal to the other five, second to the other four, etc. That doesn't remove duplicates. (1,2,3,4,5,6) isn't the same as (5,1,2,3,4,6) but your routine would produce both and I don't want to see both, I want a distinct list of numbers. <br />OK, I fall into the trap of making things complex when it can be simple as well. I'm thinking, set up a two dimensional 5X37 array of arraylists, build and store arrays, then I can list the results in numerical order and by the number of the solution and positions, when it hits me. DUMMY! Excel is pretty good at sorting, let it do it for you.<br />Well, I'm not that good at VB.NET, I'll use that. Loop the first number from 1 to 8. Loop the second number from the prior number plus 1 to 9. Repeat the second loop's process 4 more times. This is going to produce about 32K results (Wrong, 456 results.) and I don't know if “For i6 = 12 To 9” won't loop, loop once and quit or be “real helpful” and implicitly add “by -1” to it, I'll add if tests to make sure.<br />I'll add stats so I know how many milliseconds this takes and a loop counter. I wrote and tested the console app in about half an hour. While debugging, the code ran in about 3/10 of a second. When I executed it on a command line and redirected output to a file it ran in 8 milliseconds. I'm betting the majority of that time was for IO. Hmmm, one number in 6 positions in 2 seconds or all possible numbers for 2 to 6 positions in 0.008 seconds.<br /><br />Here is the last loop<br />For i6 = i5 + 1 To 9<br /> Console.WriteLine("{0},6,{1},{2},{3},{4},{5},{6}", i1 + i2 + i3 + i4 + i5 + i6, i1, i2, i3, i4, i5, i6)<br /> lp += 1<br />Next i6<br /><br />Note that “,6,” is changed in each loop so they are 2 through 5.<br />After the first loop finished I executed<br />i1 = (DateTime.Now.Ticks - dts.Ticks) / 10000<br />Console.WriteLine("{0},milliseconds,{1},loop,{2},{3}", i1, lp, dts.Millisecond, DateTime.Now.Millisecond)<br /><br />I put in the last two fields to verify what I thought the number of ticks in a millisecond was.<br />Before the loops started I executed<br />Dim dts As DateTime = DateTime.Now<br />Dim lp As Integer = 0<br />Console.WriteLine("total,NumItms,Num1,Num2,Num3,Num4,Num5,Num6")Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-89562437417646254442010-10-14T22:34:02.691+01:002010-10-14T22:34:02.691+01:00Dude that is the funniest thing I've read all ...Dude that is the funniest thing I've read all day, thanks for writing it!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-42112338824006952562010-10-14T03:42:16.519+01:002010-10-14T03:42:16.519+01:00Fast is relative. A calculation with 100% CPU usag...Fast is relative. A calculation with 100% CPU usage taking 2 seconds on a server taking in thousands of requests a second would get you fired if you spent 2 seconds per...<br />Especially if they reviewed the code after it reached production. (It doesn't matter that reviews should have caught it long ago.)<br />I'm sure the author was amazed at how fast today's computer was vs. the 80's. I wasn't impressed with these "PC" thingies since I worked on mainframes and was saddled with supporting the office's first PC. Today's PC can almost do all the work one mainframe can do now.<br />Fast is relative. If you could build logic that would just increment the numbers without the overhead of loops and looking at the numbers to see if they are giving the right answer, a 1GH machine should give an answer in less than 1 thousandth of a second.<br />I built a simlar puzzle solver that calculates a solution from under a second to a few minutes depending on what numbers are being solved, but if I used the same method of calculating the time and the same method of calculating the solution, a 4GH machine should get the answer in 10 to the 30'th power years from now.<br />Make the machine a billion times faster than that. Now it's only 10 to the 21'st years. Uhh, I don't think I'll wait up for it.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-84696051927011501122010-10-13T00:12:27.760+01:002010-10-13T00:12:27.760+01:00*Main> [ ((a,b,c),(d,e)) | a <- [1..7], b &l...*Main> [ ((a,b,c),(d,e)) | a <- [1..7], b <- [2..8], c <- [3..9], d <- [1..8], e <- [2..9], a < b, b < c, d < e, List.intersect [d,e] [a,b,c] == [], a+b+c == 23, d+e == 10 ]<br />[((6,8,9),(3,7))]Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-9790469122349032452010-10-12T21:07:57.751+01:002010-10-12T21:07:57.751+01:00Reminds me of the quote usually attributed to Ken ...Reminds me of the quote usually attributed to Ken Thompson: When in doubt, use brute force.Ivonoreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-67045440447251248852010-10-12T21:07:56.600+01:002010-10-12T21:07:56.600+01:00comprooters r fast. oh. i did not no thatcomprooters r fast. oh. i did not no thatAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-30560038615854941102010-10-12T21:02:25.647+01:002010-10-12T21:02:25.647+01:00There are only a little over one half million 6 di...There are only a little over one half million 6 digit sequences of the values 1..9, and really, there are only 84 ways of choosing 6 items, all orderings being the same, and a little over 60k of allowing permutations.<br /><br />A good article for generating sets with/without permutations is: http://www.thelowlyprogrammer.com/2010/04/indexing-and-enumerating-subsets-of.html . Code for C#, Java, and Python is available.Josiah Carlsonhttps://www.blogger.com/profile/16662314724540946069noreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-41035498313707466992010-10-12T20:47:02.147+01:002010-10-12T20:47:02.147+01:00You could optimize the thing if you started with s...You could optimize the thing if you started with something like (1,2,3) then (1,2,4), ..., (1,2,9), (1,3,4), (1,3,5)... you get the idea. This way you exclude permutations of the same combinations.<br /><br />I think, you could do 10^7-10^8 operations in 5-10 seconds on a modern processor, so this could come in handy for n>=8.Marknoreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-79351695408359926712010-10-12T19:35:48.919+01:002010-10-12T19:35:48.919+01:00In the time it takes light from the monitor to rea...In the time it takes light from the monitor to reach your eyes, the computer has processed about a dozen instructions.ctdnoreply@blogger.comtag:blogger.com,1999:blog-6324825125217268911.post-53897087920034542902009-11-29T23:32:06.124+00:002009-11-29T23:32:06.124+00:00These are my favorite type of puzzle. Interesting...These are my favorite type of puzzle. Interesting insight you have. Thanks!Anonymousnoreply@blogger.com