digitalmars.D - Look and think good things about D
- bearophile (6/6) Nov 14 2013 I have created two interesting D entries for this Rosettacode
- Rob T (3/11) Nov 14 2013 Timings for short functional version vs fast would be nice.
- bearophile (8/10) Nov 14 2013 OK. On the other hand regarding speed the fast version is in
- bearophile (4/7) Nov 14 2013 The first program doesn't even compile with ldc2 v.2.063.2, and
- Kai Nacke (5/6) Nov 15 2013 Does it compile with dmd 2.063.2? (Is it a D version problem or a
- bearophile (5/9) Nov 15 2013 If I find a ldc2 bug I show it in the right newsgroup, so don't
- bearophile (4/5) Nov 14 2013 Below the two I have added a note to compare the run-times.
- Martin Nowak (2/3) Nov 14 2013 len.uninitializedArray ? Isn't this too much UFCS?
- Meta (4/10) Nov 14 2013 I didn't look that closely at the imperative code, but it seems
- bearophile (4/7) Nov 14 2013 Yes, it's longer because it's optimized.
- qznc (5/9) Nov 14 2013 The fast version is nearly functional, too. Since memory
- bearophile (7/12) Nov 15 2013 In a system that allows you a more fine-graded management of
- Jacob Carlborg (4/8) Nov 14 2013 What does this show, that ranges is slow in D?
- bearophile (6/7) Nov 15 2013 It shows that D is awesome. Do you know other languages that
- Ary Borenszweig (27/34) Nov 15 2013 Probably Crystal.
- bearophile (15/40) Nov 15 2013 This program is much longer in number of tokens to the first D
- Chris (13/58) Nov 15 2013 Slightly OT: Why do languages like Ruby (and now Crystal) have to
- Jacob Carlborg (10/18) Nov 15 2013 You can do this as well in Ruby:
- Ary Borenszweig (8/73) Nov 15 2013 Absolutely. You are a human and you spend a lot of time reading code.
- Chris (22/109) Nov 15 2013 Well, that was exactly my point. As a human being you don't need
- Ary Borenszweig (6/17) Nov 15 2013 No need to do that. You can, if you want to. I would have done:
- Chris (24/53) Nov 15 2013 I prefer the C style syntax:
- Ary Borenszweig (18/61) Nov 15 2013 No. I just counted the tokens and D has more tokens:
- bearophile (28/34) Nov 15 2013 If you use ranges badly you will get a slow program, if you use
- Ary Borenszweig (15/46) Nov 15 2013 Sure.
- bearophile (10/15) Nov 15 2013 Ary Borenszweig:
- bearophile (32/43) Nov 15 2013 This version is more than twice faster, because group() avoids
- SomeDude (3/5) Nov 17 2013 And so, what are the rules for not using ranges badly ? What
- bearophile (7/9) Nov 17 2013 A newsgroup post is not large enough to contain an answer to
- Marco Leise (5/13) Nov 15 2013 APL is awesome!
- SomeDude (11/17) Nov 17 2013 I have a task if you are interested, but I didn't bother to login
- bearophile (14/23) Nov 17 2013 It's better to discuss this in D.learn, where most of Rosettacode
- bearophile (14/18) Nov 17 2013 The Computer Shootout site uses this one:
I have created two interesting D entries for this Rosettacode Task, is someone willing to create a Reddit entry for this? They show very different kinds of code in D. http://rosettacode.org/wiki/Look-and-say_sequence#D Bye, bearophile
Nov 14 2013
On Friday, 15 November 2013 at 01:09:53 UTC, bearophile wrote:I have created two interesting D entries for this Rosettacode Task, is someone willing to create a Reddit entry for this? They show very different kinds of code in D. http://rosettacode.org/wiki/Look-and-say_sequence#D Bye, bearophileTimings for short functional version vs fast would be nice. --rtUsing the LDC2 compiler with n=70 the run-time is about 3.74 seconds.
Nov 14 2013
Rob T:Timings for short functional version vs fast would be nice.OK. On the other hand regarding speed the fast version is in another world. So the speed comparison will become a little silly. -------------- Martin Nowak:len.uninitializedArray ? Isn't this too much UFCS?I think it's just enough of UFCS. Bye, bearophile
Nov 14 2013
OK. On the other hand regarding speed the fast version is in another world. So the speed comparison will become a little silly.The first program doesn't even compile with ldc2 v.2.063.2, and the two programs are quite different in scope... Bye, bearophile
Nov 14 2013
On Friday, 15 November 2013 at 01:59:27 UTC, bearophile wrote:The first program doesn't even compile with ldc2 v.2.063.2, andDoes it compile with dmd 2.063.2? (Is it a D version problem or a LDC bug?) Regards, Kai
Nov 15 2013
Kai Nacke:Does it compile with dmd 2.063.2? (Is it a D version problem or a LDC bug?) Regards, KaiIf I find a ldc2 bug I show it in the right newsgroup, so don't worry. It's a matter of updates (purity) in a Phobos function. Bye, bearophile
Nov 15 2013
Rob T:Timings for short functional version vs fast would be nice.Below the two I have added a note to compare the run-times. Bye, bearophile
Nov 14 2013
On 11/15/2013 02:09 AM, bearophile wrote:I have created two interesting D entries for this Rosettacode Tasklen.uninitializedArray ? Isn't this too much UFCS?
Nov 14 2013
On Friday, 15 November 2013 at 01:09:53 UTC, bearophile wrote:I have created two interesting D entries for this Rosettacode Task, is someone willing to create a Reddit entry for this? They show very different kinds of code in D. http://rosettacode.org/wiki/Look-and-say_sequence#D Bye, bearophileI didn't look that closely at the imperative code, but it seems to be quite a bit longer than most of the other imperative examples. Is this because it's super-optimized?
Nov 14 2013
Meta:I didn't look that closely at the imperative code, but it seems to be quite a bit longer than most of the other imperative examples. Is this because it's super-optimized?Yes, it's longer because it's optimized. Bye, bearophile
Nov 14 2013
On Friday, 15 November 2013 at 01:09:53 UTC, bearophile wrote:I have created two interesting D entries for this Rosettacode Task, is someone willing to create a Reddit entry for this? They show very different kinds of code in D. http://rosettacode.org/wiki/Look-and-say_sequence#DThe fast version is nearly functional, too. Since memory management is not considered a side effect there is only the printfs. If the printfs are wrapped into "debug", the function is pure.
Nov 14 2013
qznc:In a system that allows you a more fine-graded management of effects through an algebra, memory allocation is an effect. It's easy to show D functions annotated with "pure" that aren't pure at all because of memory allocation. Bye, bearophilehttp://rosettacode.org/wiki/Look-and-say_sequence#DThe fast version is nearly functional, too. Since memory management is not considered a side effect there is only the printfs. If the printfs are wrapped into "debug", the function is pure.
Nov 15 2013
On 2013-11-15 02:09, bearophile wrote:I have created two interesting D entries for this Rosettacode Task, is someone willing to create a Reddit entry for this? They show very different kinds of code in D. http://rosettacode.org/wiki/Look-and-say_sequence#DWhat does this show, that ranges is slow in D? -- /Jacob Carlborg
Nov 14 2013
Jacob Carlborg:What does this show, that ranges is slow in D?It shows that D is awesome. Do you know other languages that allow you to write two programs to solve that problem as short/simple and as fast as those two? :-) Bye, bearophile
Nov 15 2013
On 11/15/13 7:54 AM, bearophile wrote:Jacob Carlborg:Probably Crystal. Here's what I was able to do in some minutes: --- if ARGV.length != 1 puts "missing argument: n" exit 1 end n = ARGV[0].to_i str = "1" buffer = String::Buffer.new(20) n.times do puts str.length str.each_chunk do |digit, count| buffer << '0' + count buffer << digit end str = buffer.to_s buffer.clear end --- With n=70 it takes about 4.89s. With n=45 it takes about 0.012s. And with Crystal you could do the second version as well, because you have access to low level stuff like pointers. And also, the language is pretty new so there's still a lot of optimizations to be done. I also thought ranges were pretty fast because of their nature. Why are they slow in this example?What does this show, that ranges is slow in D?It shows that D is awesome. Do you know other languages that allow you to write two programs to solve that problem as short/simple and as fast as those two? :-) Bye, bearophile
Nov 15 2013
Ary Borenszweig:Here's what I was able to do in some minutes: --- if ARGV.length != 1 puts "missing argument: n" exit 1 end n = ARGV[0].to_i str = "1" buffer = String::Buffer.new(20) n.times do puts str.length str.each_chunk do |digit, count| buffer << '0' + count buffer << digit end str = buffer.to_s buffer.clear end With n=70 it takes about 4.89s. With n=45 it takes about 0.012s.This program is much longer in number of tokens to the first D program. You can write a D program about as fast as this in about the same number of tokens. Perhaps I should add an intermediate third version that shows code that's not as extreme as the two versions there. Thank you for the implicit suggestion.And with Crystal you could do the second version as well, because you have access to low level stuff like pointers.In Crystal do you have final switches, gotos, etc too?And also, the language is pretty new so there's still a lot of optimizations to be done.And LDC2 will improve in the meantime.I also thought ranges were pretty fast because of their nature.It also matters a lot how you use them, this is normal in computer programming.Why are they slow in this example?Just because the first example is not written for speed, I didn't even add run-time timings for it at first. And it's not that slow. Bye, bearophile
Nov 15 2013
On Friday, 15 November 2013 at 12:47:21 UTC, bearophile wrote:Ary Borenszweig:Slightly OT: Why do languages like Ruby (and now Crystal) have to state the obvious in an awkward way? (2...max).each do Of course you _do_ _each one_ from 2 to max. Is it to make it more "human"? If anything, human languages and thinking get rid of the superfluous (i.e. the obvious). Just like x = x + 1 (Pythronizing) x++; (obvious, concise, all you need). Buy one, get one free. (= If you buy one (of these), you will get one (another one of these) for free.) Sorry that was just a rant-om comment :)Here's what I was able to do in some minutes: --- if ARGV.length != 1 puts "missing argument: n" exit 1 end n = ARGV[0].to_i str = "1" buffer = String::Buffer.new(20) n.times do puts str.length str.each_chunk do |digit, count| buffer << '0' + count buffer << digit end str = buffer.to_s buffer.clear end With n=70 it takes about 4.89s. With n=45 it takes about 0.012s.This program is much longer in number of tokens to the first D program. You can write a D program about as fast as this in about the same number of tokens. Perhaps I should add an intermediate third version that shows code that's not as extreme as the two versions there. Thank you for the implicit suggestion.And with Crystal you could do the second version as well, because you have access to low level stuff like pointers.In Crystal do you have final switches, gotos, etc too?And also, the language is pretty new so there's still a lot of optimizations to be done.And LDC2 will improve in the meantime.I also thought ranges were pretty fast because of their nature.It also matters a lot how you use them, this is normal in computer programming.Why are they slow in this example?Just because the first example is not written for speed, I didn't even add run-time timings for it at first. And it's not that slow. Bye, bearophile
Nov 15 2013
On 2013-11-15 14:07, Chris wrote:Slightly OT: Why do languages like Ruby (and now Crystal) have to state the obvious in an awkward way? (2...max).each doYou can do this as well in Ruby: for e in 2 ... max end But Ruby follows the philosophy that everything is an object. So you invoke the "each" method on the range object.Of course you _do_ _each one_ from 2 to max. Is it to make it more "human"? If anything, human languages and thinking get rid of the superfluous (i.e. the obvious). Just like x = x + 1 (Pythronizing) x++; (obvious, concise, all you need).This middle ground is possible in Ruby: x += 1 -- /Jacob Carlborg
Nov 15 2013
On 11/15/13 10:07 AM, Chris wrote:On Friday, 15 November 2013 at 12:47:21 UTC, bearophile wrote:Absolutely. You are a human and you spend a lot of time reading code. The more human the code looks to you, the better, I think, as long as it doesn't become too long or too annoying to read, like: for every number between 2 and max do ... end :-PAry Borenszweig:Slightly OT: Why do languages like Ruby (and now Crystal) have to state the obvious in an awkward way? (2...max).each do Of course you _do_ _each one_ from 2 to max. Is it to make it more "human"?Here's what I was able to do in some minutes: --- if ARGV.length != 1 puts "missing argument: n" exit 1 end n = ARGV[0].to_i str = "1" buffer = String::Buffer.new(20) n.times do puts str.length str.each_chunk do |digit, count| buffer << '0' + count buffer << digit end str = buffer.to_s buffer.clear end With n=70 it takes about 4.89s. With n=45 it takes about 0.012s.This program is much longer in number of tokens to the first D program. You can write a D program about as fast as this in about the same number of tokens. Perhaps I should add an intermediate third version that shows code that's not as extreme as the two versions there. Thank you for the implicit suggestion.And with Crystal you could do the second version as well, because you have access to low level stuff like pointers.In Crystal do you have final switches, gotos, etc too?And also, the language is pretty new so there's still a lot of optimizations to be done.And LDC2 will improve in the meantime.I also thought ranges were pretty fast because of their nature.It also matters a lot how you use them, this is normal in computer programming.Why are they slow in this example?Just because the first example is not written for speed, I didn't even add run-time timings for it at first. And it's not that slow. Bye, bearophile
Nov 15 2013
On Friday, 15 November 2013 at 13:13:51 UTC, Ary Borenszweig wrote:On 11/15/13 10:07 AM, Chris wrote:Well, that was exactly my point. As a human being you don't need the patronizing (and highly annoying) "for every number ...". This is what you say when you explain it to a newbie. But there is no need to spell this out in the syntax. Syntax of programming languages is (or should be) like road signs, or any other signs. Concise and expressive. Else, what's the point? I know that languages like Lua have the philosophy that non-programmers should be able to use it. But every human being is capable of abstracting things. There is no need for this terrible syntax (2..max).each do: end It doesn't add anything to the code except for useless characters. Humans have used signs and acronyms for ages. We can cope with it. I once saw the most beautiful encrypted message in Arabic, which when read properly unfolds into an array of characters and meaning. We humans can deal with it. I still don't see why x++; is a problem and has to be spelled out as x = x + 1, or even x += 1 (slightly better). If Ruby programmers had invented spelling, you would "Double U Ar I Tee ee" like this. Ha ha ha! :-)On Friday, 15 November 2013 at 12:47:21 UTC, bearophile wrote:Absolutely. You are a human and you spend a lot of time reading code. The more human the code looks to you, the better, I think, as long as it doesn't become too long or too annoying to read, like: for every number between 2 and max do ... end :-PAry Borenszweig:Slightly OT: Why do languages like Ruby (and now Crystal) have to state the obvious in an awkward way? (2...max).each do Of course you _do_ _each one_ from 2 to max. Is it to make it more "human"?Here's what I was able to do in some minutes: --- if ARGV.length != 1 puts "missing argument: n" exit 1 end n = ARGV[0].to_i str = "1" buffer = String::Buffer.new(20) n.times do puts str.length str.each_chunk do |digit, count| buffer << '0' + count buffer << digit end str = buffer.to_s buffer.clear end With n=70 it takes about 4.89s. With n=45 it takes about 0.012s.This program is much longer in number of tokens to the first D program. You can write a D program about as fast as this in about the same number of tokens. Perhaps I should add an intermediate third version that shows code that's not as extreme as the two versions there. Thank you for the implicit suggestion.And with Crystal you could do the second version as well, because you have access to low level stuff like pointers.In Crystal do you have final switches, gotos, etc too?And also, the language is pretty new so there's still a lot of optimizations to be done.And LDC2 will improve in the meantime.I also thought ranges were pretty fast because of their nature.It also matters a lot how you use them, this is normal in computer programming.Why are they slow in this example?Just because the first example is not written for speed, I didn't even add run-time timings for it at first. And it's not that slow. Bye, bearophile
Nov 15 2013
On 11/15/13 11:39 AM, Chris wrote:Well, that was exactly my point. As a human being you don't need the patronizing (and highly annoying) "for every number ...". This is what you say when you explain it to a newbie. But there is no need to spell this out in the syntax. Syntax of programming languages is (or should be) like road signs, or any other signs. Concise and expressive. Else, what's the point? I know that languages like Lua have the philosophy that non-programmers should be able to use it. But every human being is capable of abstracting things. There is no need for this terrible syntax (2..max).each do: endNo need to do that. You can, if you want to. I would have done: 2.upto(max) do ... endIt doesn't add anything to the code except for useless characters.What do you mean by useless characters? How do you do it in D?
Nov 15 2013
On Friday, 15 November 2013 at 15:20:20 UTC, Ary Borenszweig wrote:On 11/15/13 11:39 AM, Chris wrote:I prefer the C style syntax: foreach (whatever) { // ... } // closes block All this "end" stuff is superfluous, but at least it closes blocks. My pet hate as far as syntax is concerned is Python. The indentation (t)error. Change, copy paste > run: Indentation error on line ... WTF?! In C style it doesn't matter if you have if (a > b) { return; } if (a > b) { return; } if (a > b) { return; } or in loops foreach (i; array) { if (i == "Hello!") { break; } } Cleaning up indentation is the programmer's business not the language's.Well, that was exactly my point. As a human being you don't need the patronizing (and highly annoying) "for every number ...". This is what you say when you explain it to a newbie. But there is no need to spell this out in the syntax. Syntax of programming languages is (or should be) like road signs, or any other signs. Concise and expressive. Else, what's the point? I know that languages like Lua have the philosophy that non-programmers should be able to use it. But every human being is capable of abstracting things. There is no need for this terrible syntax (2..max).each do: endNo need to do that. You can, if you want to. I would have done: 2.upto(max) do ... endIt doesn't add anything to the code except for useless characters.What do you mean by useless characters? How do you do it in D?
Nov 15 2013
On 11/15/13 9:47 AM, bearophile wrote:Ary Borenszweig:No. I just counted the tokens and D has more tokens: http://pastebin.com/XZFf8dsj It's even longer if I keep all the programs arguments checking (ARGV). If I remove that, the program has 45 tokens. The D version has 81 tokens. And without the imports, D still has 68 tokens. (well, I didn't count newlines as tokens, so maybe that's unfair because newlines in Crystal are significant) Yes, it's not as functional as D. But only because the language is still young.Here's what I was able to do in some minutes: --- if ARGV.length != 1 puts "missing argument: n" exit 1 end n = ARGV[0].to_i str = "1" buffer = String::Buffer.new(20) n.times do puts str.length str.each_chunk do |digit, count| buffer << '0' + count buffer << digit end str = buffer.to_s buffer.clear end With n=70 it takes about 4.89s. With n=45 it takes about 0.012s.This program is much longer in number of tokens to the first D program. You can write a D program about as fast as this in about the same number of tokens.Perhaps I should add an intermediate third version that shows code that's not as extreme as the two versions there. Thank you for the implicit suggestion.No. In this D will always be better, if you really want your program to have gotos.And with Crystal you could do the second version as well, because you have access to low level stuff like pointers.In Crystal do you have final switches, gotos, etc too?And so LLVM, which is what Crystal uses as a backend.And also, the language is pretty new so there's still a lot of optimizations to be done.And LDC2 will improve in the meantime.But I thought ranges were meant to be fast. No allocations and all of that. In fact, I was kind of sad that Crystal doesn't have a similar concept so it could never get as fast as D ranges. But if D ranges are not fast, what's the point of having them and making everyone use them?I also thought ranges were pretty fast because of their nature.It also matters a lot how you use them, this is normal in computer programming.Ah, I thought you did. So I misunderstood your timings. Sorry.Why are they slow in this example?Just because the first example is not written for speed, I didn't even add run-time timings for it at first. And it's not that slow.Bye, bearophile
Nov 15 2013
Ary Borenszweig:And so LLVM, which is what Crystal uses as a backend.LDC2 uses the same back end :-)But I thought ranges were meant to be fast. No allocations and all of that. In fact, I was kind of sad that Crystal doesn't have a similar concept so it could never get as fast as D ranges. But if D ranges are not fast, what's the point of having them and making everyone use them?If you use ranges badly you will get a slow program, if you use them well with a good back-end, you will have a fast program. I have written a third intermediate program, it's longer than yours, and it seems much slower than your code: void main(in string[] args) { import std.stdio, std.conv, std.algorithm, std.array; immutable n = (args.length == 2) ? args[1].to!uint : 10; if (n == 0) return; auto seq = "1"; writefln("%2d: n. digits: %d", 1, seq.length); foreach (immutable i; 2 .. n + 1) { Appender!string result; foreach (immutable digit, immutable count; seq.group) { result ~= "123"[count - 1]; result ~= digit; } seq = result.data; writefln("%2d: n. digits: %d", i, seq.length); } } On my system it runs in 0.34 seconds for n=50. Could you compare some of the timings of the various D/Crystal versions on your system (using ldc2 for D)? Bye, bearophile
Nov 15 2013
On 11/15/13 10:33 AM, bearophile wrote:Ary Borenszweig:Sure. This last version you wrote, compiling it with "-enable-inlining -release -O3", takes 0.054s (please tell me if I'm missing some flags, in Crystal I just used --release). The Crystal version takes 0.031s. I also tried with n=70. In D: 9.265s. In Crystal: 4.863s. I couldn't compile the first version written in D because I get: Error: pure function '__lambda1' cannot call impure function 'join' (I think you mentioned this in another post in this thread) The super-optimized D version, with n=70, takes 1.052s. This is the fastest. However, I'm starting to think that all those immutable, final switches and gotos are useless if they don't give a performance benefit (well, final switches do give you more safety). Maybe it's just that D/ldc doesn't use the immutability information and everything else to do aggressive optimizations?And so LLVM, which is what Crystal uses as a backend.LDC2 uses the same back end :-)But I thought ranges were meant to be fast. No allocations and all of that. In fact, I was kind of sad that Crystal doesn't have a similar concept so it could never get as fast as D ranges. But if D ranges are not fast, what's the point of having them and making everyone use them?If you use ranges badly you will get a slow program, if you use them well with a good back-end, you will have a fast program. I have written a third intermediate program, it's longer than yours, and it seems much slower than your code: void main(in string[] args) { import std.stdio, std.conv, std.algorithm, std.array; immutable n = (args.length == 2) ? args[1].to!uint : 10; if (n == 0) return; auto seq = "1"; writefln("%2d: n. digits: %d", 1, seq.length); foreach (immutable i; 2 .. n + 1) { Appender!string result; foreach (immutable digit, immutable count; seq.group) { result ~= "123"[count - 1]; result ~= digit; } seq = result.data; writefln("%2d: n. digits: %d", i, seq.length); } } On my system it runs in 0.34 seconds for n=50. Could you compare some of the timings of the various D/Crystal versions on your system (using ldc2 for D)?
Nov 15 2013
Ary Borenszweig: Your timings are good enough for me, I have updated the rosettacode page with the third D version.However, I'm starting to think that all those immutable, final switches and gotos are useless if they don't give a performance benefit (well, final switches do give you more safety).In the second D program if you compile with ldc2 the final switch gives a significant performance increase :-)Maybe it's just that D/ldc doesn't use the immutability information and everything else to do aggressive optimizations?This was discussed some time ago. Probably there are ways for ldc2 to use a little better the static information of well annotated D code. Bye, bearophile
Nov 15 2013
Ary Borenszweig:This last version you wrote, compiling it with "-enable-inlining -release -O3", takes 0.054s (please tell me if I'm missing some flags, in Crystal I just used --release). The Crystal version takes 0.031s. I also tried with n=70. In D: 9.265s. In Crystal: 4.863s.This version is more than twice faster, because group() avoids decoding UTF: void main(in string[] args) { import std.stdio, std.conv, std.algorithm, std.array, std.string; immutable n = (args.length == 2) ? args[1].to!uint : 10; if (n == 0) return; auto seq = ['1']; writefln("%2d: n. digits: %d", 1, seq.length); foreach (immutable i; 2 .. n + 1) { Appender!(typeof(seq)) result; foreach (const digit, const count; seq.representation.group) { result ~= "123"[count - 1]; result ~= digit; } seq = result.data; writefln("%2d: n. digits: %d", i, seq.length); } }I couldn't compile the first version written in D because I get: Error: pure function '__lambda1' cannot call impure function 'join'Just remove the "pure" for ldc2.However, I'm starting to think that all those immutable, final switches and gotos are useless if they don't give a performance benefitAdding immutable to variables sometimes helps catch some troubles in your code. In a modern language variables should be immutable on default, and functions should be pure on default, because the default choice should be the faster (if it's equally safe) and because when you read code it's simpler to reason on things that have less capabilities (like the capability to mutate for a value). Bye, bearophile
Nov 15 2013
On Friday, 15 November 2013 at 13:33:33 UTC, bearophile wrote:If you use ranges badly you will get a slow program, if you use them well with a good back-end, you will have a fast program.And so, what are the rules for not using ranges badly ? What should be avoided ?
Nov 17 2013
SomeDude:And so, what are the rules for not using ranges badly ? What should be avoided ?A newsgroup post is not large enough to contain an answer to this, that requires one or two articles to be written. In general writing quick code is partially an art, with the help of the profiler. Bye, bearophile
Nov 17 2013
Am Fri, 15 Nov 2013 02:09:52 +0100 schrieb "bearophile" <bearophileHUGS lycos.com>:I have created two interesting D entries for this Rosettacode Task, is someone willing to create a Reddit entry for this? They show very different kinds of code in D. http://rosettacode.org/wiki/Look-and-say_sequence#D Bye, bearophileAPL is awesome! -- Marco
Nov 15 2013
On Friday, 15 November 2013 at 01:09:53 UTC, bearophile wrote:I have created two interesting D entries for this Rosettacode Task, is someone willing to create a Reddit entry for this? They show very different kinds of code in D. http://rosettacode.org/wiki/Look-and-say_sequence#D Bye, bearophileI have a task if you are interested, but I didn't bother to login to create it. So if you like, you can create the page... Here it is: In a sequence of a million random integers, return the length and the indexes of the longest duplicate sequence (display indexes counting from one, not zero). In order for everybody to start with the same random sequence, it may be useful to specify a simple implementation for the generating function.
Nov 17 2013
SomeDude:I have a task if you are interested, but I didn't bother to login to create it. So if you like, you can create the page...It's better to discuss this in D.learn, where most of Rosettacode matters are discussed. I opened this in the main newsgroup to see if someone was willing to post it to Reddit.In a sequence of a million random integers, return the length and the indexes of the longest duplicate sequence (display indexes counting from one, not zero).If you write a first version of D solution I can post task description and its D solution in the Rosettacode site. I will later make improvements in your code, to make it more uniform with the other entries, etc.In order for everybody to start with the same random sequence, it may be useful to specify a simple implementation for the generating function.What function do you suggest? (It should be possible to implement on 32-64bit systems, in Haskell, in languages with only multi-precision integers, in languages like Ada that give errors on overflows, and in Java without unsigned integers). Bye, bearophile
Nov 17 2013
What function do you suggest? (It should be possible to implement on 32-64bit systems, in Haskell, in languages with only multi-precision integers, in languages like Ada that give errors on overflows, and in Java without unsigned integers).The Computer Shootout site uses this one: int nextRandom() nothrow { enum int IM = 139968, IA = 3877, IC = 29573; __gshared static int last = 42; return last = (last * IA + IC) % IM; } void main() { import std.stdio; foreach (i; 0 .. 100) { nextRandom.writeln; } } Bye, bearophile
Nov 17 2013