Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Era Scarecrow
On Tuesday, 14 August 2012 at 22:31:16 UTC, bearophile wrote: http://www.reddit.com/r/cpp/comments/y6gwk/norvigs_python_sudoku_solver_ported_to_c11/ http://nonchalantlytyped.net/blog/2012/08/13/sudoku-solver-in-c11/ His C++11 port is 316 lines long: https://gist.github.com/3345676 How many

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Ed McCardell
On 08/15/2012 03:01 AM, Era Scarecrow wrote: Not Golfed? I don't recognize that term. I don't see the python source off hand, but I don't understand python anyways. It refers to code golf, where you try to solve a problem with the smallest program possible (one-letter variable names, no

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Chris Nicholson-Sauls
On Tuesday, 14 August 2012 at 22:31:16 UTC, bearophile wrote: http://www.reddit.com/r/cpp/comments/y6gwk/norvigs_python_sudoku_solver_ported_to_c11/ http://nonchalantlytyped.net/blog/2012/08/13/sudoku-solver-in-c11/ His C++11 port is 316 lines long: https://gist.github.com/3345676 How many

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread bearophile
Era Scarecrow: I don't see the python source off hand, The original Python code: http://norvig.com/sudopy.shtml Bye, bearophile

Global variables read at compile time?

2012-08-15 Thread Stefan
Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = a; string b = a; void main() { writeln(b); } DMD spits out the error test.d(4): Error: variable a cannot be read at compile time. Is there any way to tell the compiler I want b evaluated at

Re: Global variables read at compile time?

2012-08-15 Thread RommelVR
On Wednesday, 15 August 2012 at 13:36:26 UTC, Stefan wrote: Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = a; string b = a; void main() { writeln(b); } DMD spits out the error test.d(4): Error: variable a cannot be read at compile time.

Re: Global variables read at compile time?

2012-08-15 Thread d_follower
On Wednesday, 15 August 2012 at 13:36:26 UTC, Stefan wrote: Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = a; string b = a;// line 4 void main() { writeln(b); // line 8 } DMD spits out the error test.d(4): Error: variable a

Re: Global variables read at compile time?

2012-08-15 Thread Jesse Phillips
On Wednesday, 15 August 2012 at 13:36:26 UTC, Stefan wrote: Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = a; string b = a; void main() { writeln(b); } DMD spits out the error test.d(4): Error: variable a cannot be read at compile time.

Re: Global variables read at compile time?

2012-08-15 Thread Andrej Mitrovic
On 8/15/12, d_follower d_follo...@fakemail.com wrote: I don't really know why, but it seems that you can only initialize globals with constants. That's what the static constructor is for: http://dlang.org/class.html#StaticConstructor http://dlang.org/class.html#SharedStaticConstructor

Re: Reading a csv file

2012-08-15 Thread Andrew
On Tue, 14 Aug 2012 06:27:19 +0200, Jesse Phillips wrote: On Monday, 13 August 2012 at 18:49:55 UTC, Nathan M. Swan wrote: Without the -property switch, you can use non-@property functions as if they were @property. This is supposed to eventually be deprecated, so I try to not do this. To

Re: Optional extra return value? Multiple return values with auto?

2012-08-15 Thread ReneSac
On Wednesday, 15 August 2012 at 01:22:41 UTC, Era Scarecrow wrote: On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote: And my last question of my first post: I can't use auto for the out values right? An enhancement proposal like this would be compatible with D? I would say No.

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread ixid
Could you supply your code? Which one are you using as the hardest? If you're solving the 1400 second one in 12 seconds that's very impressive, I can't get it below 240 seconds.

Re: Global variables read at compile time?

2012-08-15 Thread Justin Whear
On Wed, 15 Aug 2012 15:36:24 +0200, Stefan wrote: Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = a; string b = a; void main() { writeln(b); } DMD spits out the error test.d(4): Error: variable a cannot be read at compile

Re: Global variables read at compile time?

2012-08-15 Thread Ali Çehreli
On 08/15/2012 06:55 AM, d_follower wrote: On Wednesday, 15 August 2012 at 13:41:10 UTC, RommelVR wrote: Make a an enum, const or otherwise immutable. I don't think you understood the question. I thought RommelVR did understand the question. Try this: import std.stdio; enum a = a; string b

Re: where is parameterNames?

2012-08-15 Thread David Nadlinger
On Tuesday, 14 August 2012 at 16:06:33 UTC, Jacob Carlborg wrote: https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L29 Related: https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L510 David

Re: Global variables read at compile time?

2012-08-15 Thread Leandro Motta Barros
Another option is to use module constructors, as shown below. (But somehow this all looks a bit fishy for me...) LMB import std.stdio; string a = a; string b; static this() { b = a; } void main() { writeln(b); } On Wed, Aug 15, 2012 at 11:03 AM, d_follower

Question on Octal

2012-08-15 Thread Michael
Hi all, I have just read Walter's article about octals on Dr. Dobb's. As a newbie, I tried to create one myself. template octal(int n) { int toOct(int x) {...} enum octal = toOct(n); } void main() { import std.stdio : writeln; writeln(octal!10); } I

Re: Question on Octal

2012-08-15 Thread Jonathan M Davis
On Wednesday, August 15, 2012 19:49:53 Michael wrote: Hi all, I have just read Walter's article about octals on Dr. Dobb's. As a newbie, I tried to create one myself. template octal(int n) { int toOct(int x) {...} enum octal = toOct(n); } void main() { import std.stdio : writeln;

Re: Reading a csv file

2012-08-15 Thread Jesse Phillips
On Wednesday, 15 August 2012 at 15:13:09 UTC, Andrew wrote: Ah, understood. My thanks. I'll probably start using the -property switch just to avoid accidentally getting in the habit of using a deprecated feature. Note, another form discussion has pointed out that -property is horribly

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Era Scarecrow
On Wednesday, 15 August 2012 at 15:39:26 UTC, ixid wrote: Could you supply your code? Which one are you using as the hardest? If you're solving the 1400 second one in 12 seconds that's very impressive, I can't get it below 240 seconds. 1400 seconds? Well my CPU is a quad-core 3.2Ghz, but

Re: where is parameterNames?

2012-08-15 Thread Philippe Sigaud
On Wed, Aug 15, 2012 at 6:46 PM, David Nadlinger s...@klickverbot.at wrote: On Tuesday, 14 August 2012 at 16:06:33 UTC, Jacob Carlborg wrote: https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L29 Related:

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Era Scarecrow
On Wednesday, 15 August 2012 at 15:39:26 UTC, ixid wrote: Could you supply your code? Which one are you using as the hardest? If you're solving the 1400 second one in 12 seconds that's very impressive, I can't get it below 240 seconds. Expanded to 225 lines after comments and refactoring for

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Jonathan M Davis
On Wednesday, August 15, 2012 21:14:07 Era Scarecrow wrote: I have made a C version a while back that solves any sudoku puzzle in 1/8th of a second. The code for that though was considerably longer and involved several forms of pattern matching and detecting how to solve the puzzle before it

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Era Scarecrow
On Wednesday, 15 August 2012 at 20:28:19 UTC, Jonathan M Davis wrote: Brute force is so fast that there's no really any point in trying to solve it any other way except for the challenge of doing so. I answered a question on this using D at codegolf.stackexchange.com a while back:

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread ixid
On Wednesday, 15 August 2012 at 20:13:10 UTC, Era Scarecrow wrote: On Wednesday, 15 August 2012 at 15:39:26 UTC, ixid wrote: Could you supply your code? Which one are you using as the hardest? If you're solving the 1400 second one in 12 seconds that's very impressive, I can't get it below 240

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread bearophile
Jonathan M Davis: and the code is lightning fast. It would probably have to be tweaked to match whatever Bearophile's code does though as far is input goes (I haven't looked at the code that he linked to). It also makes no attempt at being compact (e.g. it actually checks the command line

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread bearophile
Jonathan M Davis: It would probably have to be tweaked to match whatever Bearophile's code does though as far is input goes (I haven't looked at the code that he linked to). And the original Python code is not mine, it's from the AI researcher Peter Norvig :-) Bye, bearophile

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Timon Gehr
On 08/15/2012 12:31 AM, bearophile wrote: http://www.reddit.com/r/cpp/comments/y6gwk/norvigs_python_sudoku_solver_ported_to_c11/ http://nonchalantlytyped.net/blog/2012/08/13/sudoku-solver-in-c11/ His C++11 port is 316 lines long: https://gist.github.com/3345676 How many lines for a (not

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Era Scarecrow
On Wednesday, 15 August 2012 at 22:38:58 UTC, ixid wrote: How many solutions do you find for that one? Don't know, it actually just stops after finding the first one. Modifying it to give all possible outputs wouldn't be too hard... So far having it running it's found over 23k+ combinations

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread Era Scarecrow
On Thursday, 16 August 2012 at 01:05:20 UTC, Era Scarecrow wrote: So far having it running it's found over 23k+ combinations after about 3 minutes. Unless I introduced a bug... Now I'll have to speed it up to make sure and won't take an afternoon to calculate.

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread ixid
This is my attempt at a D solver, it's a pretty direct translation of a C++ version I wrote but it's a lot slower in D, around 1/4 the speed sadly, 2x because of the compiler I think and 2x because in C++ I can use proper bitfields which seem to give another 2x speed up (halving the size of

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread ixid
Hmm, sorry odd things have happened to the formatting. Visual D's spacing doesn't seem to work very well outside of itself.

Re: Sudoku Py / C++11 / D?

2012-08-15 Thread maarten van damme
solving sudoku's well too : http://dpaste.dzfl.pl/903e34b5 I have one question though, how can you make it find all possible solutions? 2012/8/16, Era Scarecrow rtcv...@yahoo.com: On Thursday, 16 August 2012 at 01:05:20 UTC, Era Scarecrow wrote: So far having it running it's found over 23k+

Re: Question on Octal

2012-08-15 Thread Simen Kjaeraas
On Wed, 15 Aug 2012 20:07:59 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: 1) The specification is clear that the if the template has only one member and the member has the same name with the template's, the member is implicitly referred to in the instantiation. The template octal has

Re: Question on Octal

2012-08-15 Thread Jonathan M Davis
On Thursday, August 16, 2012 06:14:23 Simen Kjaeraas wrote: On Wed, 15 Aug 2012 20:07:59 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: 1) The specification is clear that the if the template has only one member and the member has the same name with the template's, the member is