641 karma · joined October 21, 2009
Perhaps I should have mentioned that, though.
Looking at the complete picture makes a language with local type inference (like C++11) more or less as verbose as one with complete type inference.
The C-style cast is shorter, but less safe, so you should not use it: http://stackoverflow.com/questions/1609163/what-is-the-diffe...
Yeah, I couldn't quite decide if I should include const refs. On the one hand, it is idiomatic, but on the other hand I didn't want to clutter the code with something that is just an optimization on paper.
The program is I/O-bound, so the only speed improvement comes from not having to start up the Python interpreter.
If the task was CPU bound, you would get a great performance boost (sometimes 100x over CPython), but that is well known.
There can be other reasons than performance for writing in C++. Used well, the strong static type system can catch many bugs. I suspect (but I cannot prove) that it could be almost as good as Haskell.
I use Python for most things, though, so I don't really advocating switching to C++ for every little scripting task.
Having written it, though, I thought I might share it. For most people, like me, the timing has to be right to try something new. You have to have the time and the motivation and everything else. By sharing it, I hope to hit some people with the right timing (and based on some comments, upvotes, etc, I know I did).
I must have seen 20 Haskell advocacy posts before I actually tried writing something in it. Same with you for some new technologies?
Besides that it is trendy to pick on Google, I think that the problem people have had with customer support is mostly with ads.
The code is ugly and undocumented. I think the same could be accomplished in less than 10 lines of Haskell :). http://pastebin.com/MfXK9fwS
An implementation detail is that my branches are actually "jar1" "jar2" and "stepforward". To use a jar many times, you do jar1, jar1, stepforward.
a) a known fail percentage - 40% of the time the Jar fails and produces nothing. Maximize expected win.
b) an unknown fail percentage, evenly distributed between 0 and 100%. Find a strategy that maximizes expected win over many runs (each run has new fail probabilities), by perfectly balancing between exploration of jars and exploitation. If you can find an optimal (and practical) strategy for this one I applaud you!
Also, I solved your example with a simple Python brute-forcer with < 1s run time. I don't know if I care enough to write a parser of your file format just to mail it in ;).
If it cannot be solved analytically, it seems something like a GA should solve it well.
Is there a standard method for solving substitution cryptos?
A serious try with GA would require abandoning Python for a faster fitness function in C, that does not copy dozens of lists back and forth. I estimate that just about anyone could make it more than 100 times as fast. The slow implementation will have to suffice for now.
The interesting part is of course not the absolute times, but if the complexity scales differently. If a real Sudoku solver takes about 50 times as long to solve that problem, I will consider it a victory if the GA does the same.