Random Post
Recent Posts
- Enigma 769: Magic square
- BrainTwister #19: Angular arrangements
- Enigma 767: Safety in numbers
- BrainTwister #18: The arithmetical two-step
- Enigma 774: Sting in the tail
- BrainTwister #17: Semi-one numbers
- Enigma 773: Duodecimal
- BrainTwister #16: Order, order!
- Enigma 772: Have you seen the trailer?
- BrainTwister #15: Domino strips
Recent Comments
Archives
Categories
- article (11)
- braintwister (19)
- enigma (1,718)
- enigma-book-1982 (70)
- headscratchers-book-2023 (70)
- microteasers-book-1986 (11)
- misc (7)
- project euler (2)
- puzzle (90)
- puzzle# (249)
- site news (83)
- sphinx (4)
- tantalizer (254)
- tantalizer-book-1970 (40)
- teaser (7)
- today (1)
Site Stats
- 347,477 hits
A slightly modified version of my recursive solver for Enigma 1750 solves this in 84ms.
Solution: The numbers in the shaded regions are 307 and 41.
Isn’t zero an even digit?
Yes, zero is an even digit. But it only appears once in the solution grid, so that’s OK.
I took the phrase “no even digit appears more than once anywhere” to mean “there cannot be more than one occurrence of any particular even digit in the solution grid; there may multiple even digits in the solution grid (but each of them will have to be a different digit)”, rather than “there cannot be more than one even digit in the solution grid”.
There are no solutions if the latter interpretation is used.
I wrote a generic cross-figure solver (the code for which is given in my solution for Enigma 1760). Here’s a solution to this problem using that code. It runs in 70ms.
The execution time of the algorithm above on my machine is about 15 miliseconds, I guess that is really fast..
This one is rather long but it is quite fast:
Hi Brian, what is the execution time of it?
If I replace lines 1 to 7 with
so that Jim’s enigma can be used, I then get PyPy 2.0.2 timings for Jim’s, your’s and mine of 1040, 980 and 30 milliseconds respectively (this is on a 1.8GHz i7 laptop). On CPython 3.3 I get 250, 240 and 31 milliseconds respectively.
These are timings using Python’s CProfile module. My experience is that timings vary wildly between machines and Python versions so the different versions have to be run on the same machine using the saame timing approach to be meaningful. Even then I am not very convinced about the results.
I see, frankly when ı get the 15 ms on my machine which is 2.6 ghz laptop, I dont need to optimize more, however your codes execution time on my machine is 45 ms
Hi Ahmet,
Jim timed his own version, your version and mine and got yours and his similar and mine aboutr twice the speed. I have timed them and I have also asked two colleagues to do so and all the results are reasonably close to those that Jim has reported.
But you are suggesting that my version takes three times as long on your machine as your version – 45 ms compared with 15 ms. So something that others find to be about twice as fast, you are measuring as three times slower – a factor of six different!
Since this seems very unlikely, it suggests that there may be something wrong with the way you are measuring running times.
Ok, then I am going to post the output, that is impossible that my code’s execution time is 90ms, it is working just 15 ms on my machine, and yours is about 45 ms, and one thing, if the execution time is not so important, then no need to talk about it, this is just python, and a child play for me, the point is to construct a good algortihm, and I believe that I am succesfull at construcing good one, in my opinion, then no need to talk about the execution times, because nobody can prove their execution time, and it is really dependent on the processors speed, I know that mine is working on my machine in 15 ms, I dont know and can not know the rest 🙂
It is not the algorithm that I am seeking to explain. I am seeking to understand how a program that seems to be about twice as fast for a number of people is three times slower for you! I suspect that this is a problem with timing but it could be something else. Either way it would be useful to know why this is as it may tell us something.
I am timing in the following way. I have a batch file called ‘profile.bat’ in the same directory as my Python files. It contains the two lines:
@echo off
“c:\program files\python33\python” -mcProfile -scumulative %1
I then run a command prompt (a DOS window) in this directory and enter the command:
profile ns1755.py
where ns1755.py is the name of the program being timed.
How are you producing your timing results?
What I am trying to understand is the same as you did tell me the differences of the execution times between two different machines, on my machine my code’s execution time is about 15 ms, how is it possible to be 90 ms on other machine, this is 6 times slower, that is unbelievable. I guess if I do not misunderstand that your code, you have a prime a list given on the top of the code, you have not coded a function of primarility test,
As to my timing issue, I run the code on the Python editor, as I showed you before, and although there is overhead because of the editor itself, when I use the time function on my code, it gives me a 15ms on my machine,now the point is this, how is it possible for it to be working on a diiferent machine with the 6 times slower execution time than mine
For comparison I ran the same timing tests that I run for my own code on this one and it comes out at 92ms. So the running times are very similar.
As I noted in my solution for Enigma 1740 you can write a faster program for solving this kind of problem, but I find the more general algorithm to be more interesting to program.
Personally I’m happy with any code that runs in under 100ms, as that’s pretty much instantaneous.
Hi Jim, which one do you mean, mine or Brian s?
@Ahmet: I’m referring to the code you posted above (28 June 2013 at 1:19 pm).
I do not know, my execution time is 15 ms on my machine, I can post the image of the output if you wish, and also I can speed up mine, if you have noted that, I did not use some constraints like the prime numbers end wirh the 1 3 7 9 and some other stuff, anyway, i dont know how yo do test the codes
I don’t doubt the times you report. I was just running your code under the same environment to give a comparable figure. The code Brian published (with a little tweak to use the [[
Primes
]] class from enigma.py) came in at 44ms.As noted on the Notes page I time all phases of the command execution, so it’s quite hard to get a runtime reported of less than around 30ms.
But for me the challenge is not about coming up with the fastest executing program, or the shortest program, but a program that is easy to understand and that runs fast enough and doesn’t take too long to write. For this puzzle I just adapted a program I’d written for a previous puzzle, so it only took me a few minutes to come up with a viable program, and it ran in less than 100ms, so I was happy with it.
I agree with you, the previous puzzle is so similar to this, I did code this first, after, İ did code the previous one in a few minutes, and I agree with you about the point is algorithm, and sure execution time, the code might be longer but the execution time does matter
You can view my output with the execution time above the link.
Erm, if those numbers are measuring seconds then the three examples you post are:
0.172s = 172ms, 0.156s = 156ms and 0.156s = 156ms.
This one’s execution time on my machine is about 260ms,what about on yours?
That would come out as 97ms on my machine.
I wouldn’t get too hung up on comparing runtimes though, as they will vary depending on the hardware, operating system, Python version and what else is running on the machine at the time. I only report them as a rough guide to the amount of computation involved in determining the solution.
Python has its own
timeit
module for doing more detailed calculation of the runtimes of code fragments, but I like using the shell’stime
command as it gives me a reasonable basis for comparison between programs written in different languages. (I used to do Enigma problems in Perl).I changed the path array, I have been moving on the diagonals first, and this one’s execution time on my machine is about 15ms…
This one is java version with the same algorithm and it is a simulation of the depth first search,
For the animation in the applet, I did use threads for paralell processing
This enigma is different to Enigma 1740, in that it does not state that all primes are to be different.
In fact, prime number 31 appears twice and this time (!) I get the published single answer for this Enigma.
I had to use a new ‘ at_most’ predicate in MiniZinc to allow for the condition that no even digit appears more than once anywhere:
Usage:
% predicate at_most (int: n, array [int] of var int: x, int: v)
% Requires at most n variables in x to take the value v.
Even digits 0, 4, and 6 appear once and digits 2 and 8 are absent from the grid in the answer.