Re: A Friendly Challenge for D

2018-10-16 Thread Jabari Zakiya via Digitalmars-d
On Tuesday, 16 October 2018 at 21:12:39 UTC, welkam wrote: On Tuesday, 16 October 2018 at 20:58:54 UTC, Jabari Zakiya wrote: And they could be modded to catch semantics like this and produce faster code. Its hard to prove that you will only write 1 or 0 in the array and even if you write such

Re: A Friendly Challenge for D

2018-10-16 Thread welkam via Digitalmars-d
On Tuesday, 16 October 2018 at 20:58:54 UTC, Jabari Zakiya wrote: And they could be modded to catch semantics like this and produce faster code. Its hard to prove that you will only write 1 or 0 in the array and even if you write such pass it wont fire very often. So slower compile times for

Re: A Friendly Challenge for D

2018-10-16 Thread Jabari Zakiya via Digitalmars-d
On Tuesday, 16 October 2018 at 20:38:24 UTC, welkam wrote: On Tuesday, 16 October 2018 at 17:57:23 UTC, Jabari Zakiya wrote: This is the exact same behavior I found with the Nim compiler too. Well Nim compiler is more like translator. It translates Nim code to c or c++. Since gcc was responsi

Re: A Friendly Challenge for D

2018-10-16 Thread welkam via Digitalmars-d
On Tuesday, 16 October 2018 at 17:57:23 UTC, Jabari Zakiya wrote: This is the exact same behavior I found with the Nim compiler too. Well Nim compiler is more like translator. It translates Nim code to c or c++. Since gcc was responsible for optimizations and instruction selection it would be

Re: A Friendly Challenge for D

2018-10-16 Thread Jabari Zakiya via Digitalmars-d
On Tuesday, 16 October 2018 at 07:09:05 UTC, Vijay Nayar wrote: On Monday, 15 October 2018 at 22:17:57 UTC, Jabari Zakiya wrote: $ dub build --compiler=ldc2 -b=release && echo "30" | ./twinprimes Enter integer number: threads = 8 each thread segment is [1 x 65536] bytes array twinprime

Re: A Friendly Challenge for D

2018-10-16 Thread Jabari Zakiya via Digitalmars-d
On Tuesday, 16 October 2018 at 16:57:12 UTC, welkam wrote: So I run profiler and 97% of time is spent in void twinsSieve function and hotspots are seg[k] = seg[k] | 1; lines. Since seg[k] can only be 1 or 0 I removed that or operation. And the results are. Queue the drum-roll... 5% slower. I

Re: A Friendly Challenge for D

2018-10-16 Thread Jon Degenhardt via Digitalmars-d
On Tuesday, 16 October 2018 at 07:09:05 UTC, Vijay Nayar wrote: D has multiple compilers, but for the speed of the finished binary, LDC2 is generally recommended. I used version 1.11.0. https://github.com/ldc-developers/ldc/releases/tag/v1.11.0 I was using DUB to manage the project, but to b

Re: A Friendly Challenge for D

2018-10-16 Thread welkam via Digitalmars-d
So I run profiler and 97% of time is spent in void twinsSieve function and hotspots are seg[k] = seg[k] | 1; lines. Since seg[k] can only be 1 or 0 I removed that or operation. And the results are. Queue the drum-roll... 5% slower. I thought that all of my studying was getting somewhere. That

Re: A Friendly Challenge for D

2018-10-16 Thread Vijay Nayar via Digitalmars-d
On Monday, 15 October 2018 at 22:17:57 UTC, Jabari Zakiya wrote: $ dub build --compiler=ldc2 -b=release && echo "30" | ./twinprimes Enter integer number: threads = 8 each thread segment is [1 x 65536] bytes array twinprime candidates = 175324676; resgroups = 1298702 each 135 threads has

Re: A Friendly Challenge for D

2018-10-15 Thread Jabari Zakiya via Digitalmars-d
$ dub build --compiler=ldc2 -b=release && echo "30" | ./twinprimes Enter integer number: threads = 8 each thread segment is [1 x 65536] bytes array twinprime candidates = 175324676; resgroups = 1298702 each 135 threads has nextp[2 x 5566] array setup time = 1 ms, 864 μs, and 7 hnsecs perf

Re: A Friendly Challenge for D

2018-10-15 Thread Jabari Zakiya via Digitalmars-d
I don't actually understand the underlying algorithm, but I at least understand the flow of the program and the structure. The algorithm utilized depends heavily on using shared memory access, which can be done in D, but I definitely wouldn't call it idiomatic. In D, message passing is prefer

Re: A Friendly Challenge for D

2018-10-15 Thread Vijay Nayar via Digitalmars-d
On Sunday, 14 October 2018 at 10:51:11 UTC, Vijay Nayar wrote: Once I get the bugs out, I'm curious to see if any performance differences crop up. There's the theory that says they should be the same, and then there's the practice. I don't actually understand the underlying algorithm, but I a

Re: A Friendly Challenge for D

2018-10-14 Thread Bastiaan Veelo via Digitalmars-d
On Sunday, 14 October 2018 at 10:51:11 UTC, Vijay Nayar wrote: But as previous posters have said, the code is not really very different between Nim and D. Most of it is array manipulation and arithmetic operations, and not many of the features of either D or Nim are very different. Both turn

Re: A Friendly Challenge for D

2018-10-14 Thread Vijay Nayar via Digitalmars-d
On Saturday, 13 October 2018 at 19:04:48 UTC, Jabari Zakiya wrote: On Saturday, 13 October 2018 at 18:31:57 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 18:14:20 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 18:05:45 UTC, Jabari Zakiya wrote: It may be also running into a

Re: A Friendly Challenge for D

2018-10-13 Thread Jabari Zakiya via Digitalmars-d
On Saturday, 13 October 2018 at 18:31:57 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 18:14:20 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 18:05:45 UTC, Jabari Zakiya wrote: It may be also running into a hard time limit imposed on compilation that Nim had/has that preve

Re: A Friendly Challenge for D

2018-10-13 Thread Vijay Nayar via Digitalmars-d
On Saturday, 13 October 2018 at 18:14:20 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 18:05:45 UTC, Jabari Zakiya wrote: It may be also running into a hard time limit imposed on compilation that Nim had/has that prevented my code from initially compiling. I'm generating a lot of PG

Re: A Friendly Challenge for D

2018-10-13 Thread Jabari Zakiya via Digitalmars-d
On Saturday, 13 October 2018 at 18:14:20 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 18:05:45 UTC, Jabari Zakiya wrote: It may be also running into a hard time limit imposed on compilation that Nim had/has that prevented my code from initially compiling. I'm generating a lot of PG

Re: A Friendly Challenge for D

2018-10-13 Thread Vijay Nayar via Digitalmars-d
On Saturday, 13 October 2018 at 18:05:45 UTC, Jabari Zakiya wrote: It may be also running into a hard time limit imposed on compilation that Nim had/has that prevented my code from initially compiling. I'm generating a lot of PG parameter constants at compile time, and it's doing a lot of num

Re: A Friendly Challenge for D

2018-10-13 Thread Jabari Zakiya via Digitalmars-d
On Saturday, 13 October 2018 at 17:36:33 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 15:50:06 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 15:19:07 UTC, Jabari Zakiya wrote: On Saturday, 13 October 2018 at 14:32:33 UTC, welkam wrote: On Saturday, 13 October 2018 at 09:22:

Re: A Friendly Challenge for D

2018-10-13 Thread Vijay Nayar via Digitalmars-d
On Saturday, 13 October 2018 at 15:50:06 UTC, Vijay Nayar wrote: On Saturday, 13 October 2018 at 15:19:07 UTC, Jabari Zakiya wrote: On Saturday, 13 October 2018 at 14:32:33 UTC, welkam wrote: On Saturday, 13 October 2018 at 09:22:16 UTC, Vijay Nayar wrote: [...] import algorithm thats all b

Re: A Friendly Challenge for D

2018-10-13 Thread Vijay Nayar via Digitalmars-d
On Saturday, 13 October 2018 at 15:19:07 UTC, Jabari Zakiya wrote: On Saturday, 13 October 2018 at 14:32:33 UTC, welkam wrote: On Saturday, 13 October 2018 at 09:22:16 UTC, Vijay Nayar wrote: [...] import algorithm thats all but then it spits out lib/nim/pure/algorithm.nim(144, 11) Error: i

Re: A Friendly Challenge for D

2018-10-13 Thread Jabari Zakiya via Digitalmars-d
On Saturday, 13 October 2018 at 14:32:33 UTC, welkam wrote: On Saturday, 13 October 2018 at 09:22:16 UTC, Vijay Nayar wrote: I downloaded the reference NIM implementation and got the latest nim compiler, but I received the following error: $ nim c --cc:gcc --d:release --threads:on twinprime

Re: A Friendly Challenge for D

2018-10-13 Thread Vijay Nayar via Digitalmars-d
On Saturday, 13 October 2018 at 14:32:33 UTC, welkam wrote: On Saturday, 13 October 2018 at 09:22:16 UTC, Vijay Nayar wrote: I downloaded the reference NIM implementation and got the latest nim compiler, but I received the following error: $ nim c --cc:gcc --d:release --threads:on twinprime

Re: A Friendly Challenge for D

2018-10-13 Thread welkam via Digitalmars-d
On Saturday, 13 October 2018 at 09:22:16 UTC, Vijay Nayar wrote: I downloaded the reference NIM implementation and got the latest nim compiler, but I received the following error: $ nim c --cc:gcc --d:release --threads:on twinprimes_ssoz.nim twinprimes_ssoz.nim(74, 11) Error: attempting to

Re: A Friendly Challenge for D

2018-10-13 Thread Vijay Nayar via Digitalmars-d
On Friday, 12 October 2018 at 21:08:03 UTC, Jabari Zakiya wrote: On Friday, 12 October 2018 at 20:05:29 UTC, welkam wrote: On Friday, 12 October 2018 at 16:19:59 UTC, Jabari Zakiya wrote: The real point of the challenge is too see what idiomatic code... There is no idiomatic D code. There is

Re: A Friendly Challenge for D

2018-10-12 Thread Jabari Zakiya via Digitalmars-d
On Friday, 12 October 2018 at 20:05:29 UTC, welkam wrote: On Friday, 12 October 2018 at 16:19:59 UTC, Jabari Zakiya wrote: The real point of the challenge is too see what idiomatic code... There is no idiomatic D code. There is only better implementations. D doesnt tell you how to write

Re: A Friendly Challenge for D

2018-10-12 Thread welkam via Digitalmars-d
On Friday, 12 October 2018 at 16:19:59 UTC, Jabari Zakiya wrote: The real point of the challenge is too see what idiomatic code... There is no idiomatic D code. There is only better implementations. D doesnt tell you how to write your code. It gives you many tools and you choose which

Re: A Friendly Challenge for D

2018-10-12 Thread welkam via Digitalmars-d
On Friday, 12 October 2018 at 16:19:59 UTC, Jabari Zakiya wrote: Hmm,I don't think what you're saying about similar output|performance with other languages is empirically correct, but it's really not the point of the challenge. Thats why godbolt exists. c++ and Rust https:

Re: A Friendly Challenge for D

2018-10-12 Thread Jabari Zakiya via Digitalmars-d
uages is empirically correct, but it's really not the point of the challenge. The real point of the challenge is too see what idiomatic code, written for performance, using the best resources that the language provides, will produce compared, to the Nim version. It's not to see what a lin

Re: A Friendly Challenge for D

2018-10-12 Thread welkam via Digitalmars-d
On Wednesday, 10 October 2018 at 16:15:56 UTC, Jabari Zakiya wrote: What I am requesting here is for a person(s) who is an "expert" (very good) to create a very fast D version, using whatever tricks it has to maximize performance. I would like to include in my paper a good comparison of vario

Re: A Friendly Challenge for D

2018-10-11 Thread Ali Çehreli via Digitalmars-d
On 10/11/2018 10:14 AM, Jabari Zakiya wrote: > Ok, hopefully this will work for everyone. Try this link: > > https://mega.nz/#!yJxUEQgK!MY9dwjiWheE8tACtEeS0szduIvdBjiyTn4O6mMD_aZw Thank you. That worked just fine. I clicked the Download link and the pdf was saved on my end. :) Ali

Re: A Friendly Challenge for D

2018-10-11 Thread Jabari Zakiya via Digitalmars-d
On Thursday, 11 October 2018 at 16:13:17 UTC, Jabari Zakiya wrote: On Thursday, 11 October 2018 at 14:49:54 UTC, Carl Sturtivant wrote: On Thursday, 11 October 2018 at 13:26:19 UTC, Jabari Zakiyth wrote: On Thursday, 11 October 2018 at 05:11:20 UTC, Ali Çehreli wrote: [...] What country are

Re: A Friendly Challenge for D

2018-10-11 Thread Jabari Zakiya via Digitalmars-d
On Thursday, 11 October 2018 at 14:49:54 UTC, Carl Sturtivant wrote: On Thursday, 11 October 2018 at 13:26:19 UTC, Jabari Zakiyth wrote: On Thursday, 11 October 2018 at 05:11:20 UTC, Ali Çehreli wrote: [...] What country are you trying to get access from, because I know people in the US have

Re: A Friendly Challenge for D

2018-10-11 Thread Carl Sturtivant via Digitalmars-d
On Thursday, 11 October 2018 at 13:26:19 UTC, Jabari Zakiyth wrote: On Thursday, 11 October 2018 at 05:11:20 UTC, Ali Çehreli wrote: [...] What country are you trying to get access from, because I know people in the US have gotten the papers from those link, for free and without an account.

Re: A Friendly Challenge for D

2018-10-11 Thread Jabari Zakiyth via Digitalmars-d
On Thursday, 11 October 2018 at 05:11:20 UTC, Ali Çehreli wrote: On 10/10/2018 07:52 PM, Jabari Zakiyth wrote: > On Wednesday, 10 October 2018 at 22:25:17 UTC, Neia Neutuladh wrote: >> On 10/10/2018 03:05 PM, Jabari Zakiya wrote: >>> https://www.scribd.com/doc/228155369/The-Segmented-Sieve-of-Za

Re: A Friendly Challenge for D

2018-10-10 Thread Ali Çehreli via Digitalmars-d
On 10/10/2018 07:52 PM, Jabari Zakiyth wrote: > On Wednesday, 10 October 2018 at 22:25:17 UTC, Neia Neutuladh wrote: >> On 10/10/2018 03:05 PM, Jabari Zakiya wrote: >>> https://www.scribd.com/doc/228155369/The-Segmented-Sieve-of-Zakiya-SSoZ >> >> It would be great if you could provide a link to a

Re: A Friendly Challenge for D

2018-10-10 Thread Jabari Zakiyth via Digitalmars-d
On Thursday, 11 October 2018 at 00:22:10 UTC, tide wrote: On Wednesday, 10 October 2018 at 16:15:56 UTC, Jabari Zakiya wrote: I would like to include in my paper a good comparison of various implementations in different compiled languages (C/C++, D, Nim, etc) to show how it performs with each.

Re: A Friendly Challenge for D

2018-10-10 Thread Jabari Zakiyth via Digitalmars-d
On Wednesday, 10 October 2018 at 22:25:17 UTC, Neia Neutuladh wrote: On 10/10/2018 03:05 PM, Jabari Zakiya wrote: https://www.scribd.com/doc/228155369/The-Segmented-Sieve-of-Zakiya-SSoZ It would be great if you could provide a link to a freely downloadable version of this. You can download

Re: A Friendly Challenge for D

2018-10-10 Thread tide via Digitalmars-d
On Wednesday, 10 October 2018 at 16:15:56 UTC, Jabari Zakiya wrote: I would like to include in my paper a good comparison of various implementations in different compiled languages (C/C++, D, Nim, etc) to show how it performs with each. If you want help with your paper, possibly some kind of d

Re: A Friendly Challenge for D

2018-10-10 Thread Neia Neutuladh via Digitalmars-d
On 10/10/2018 03:05 PM, Jabari Zakiya wrote: https://www.scribd.com/doc/228155369/The-Segmented-Sieve-of-Zakiya-SSoZ It would be great if you could provide a link to a freely downloadable version of this.

Re: A Friendly Challenge for D

2018-10-10 Thread Jabari Zakiya via Digitalmars-d
On Wednesday, 10 October 2018 at 20:43:01 UTC, Kagamin wrote: On Wednesday, 10 October 2018 at 16:15:56 UTC, Jabari Zakiya wrote: https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e As i understand, main thread preallocates global memory and tracks it, and other threads don't tra

Re: A Friendly Challenge for D

2018-10-10 Thread Kagamin via Digitalmars-d
On Wednesday, 10 October 2018 at 16:15:56 UTC, Jabari Zakiya wrote: https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e As i understand, main thread preallocates global memory and tracks it, and other threads don't track it?

Re: A Friendly Challenge for D

2018-10-10 Thread SrMordred via Digitalmars-d
On Wednesday, 10 October 2018 at 16:15:56 UTC, Jabari Zakiya wrote: [...] Looking forward to this :)

A Friendly Challenge for D

2018-10-10 Thread Jabari Zakiya via Digitalmars-d
Hi. I hope this is the right place to request this, if not please tell me a better one. I had looked at D, and played with it some circa 2010~2012, but time and life took my priorities away. But I'm still interested in learning different languages, but there are so many more now it's hard t

Re: Knowing the approach to solve a D challenge

2018-02-16 Thread Jesse Phillips via Digitalmars-d
On Friday, 16 February 2018 at 09:44:27 UTC, aberba wrote: D has tone of features and library solutions. When you encounter a problem, how do you approach solving it in code? 1. Do you first write it in idiomatic D style or a more general approach before porting to idiomatic D? Like always,

Re: Knowing the approach to solve a D challenge

2018-02-16 Thread Dukc via Digitalmars-d
On Friday, 16 February 2018 at 09:44:27 UTC, aberba wrote: 1. Do you first write it in idiomatic D style or a more general approach before porting to idiomatic D? In micro-level, it's usually fairly idiomatic from get-go. Usually no heap allocations at inner loops, for-looping, static variabl

Re: Knowing the approach to solve a D challenge

2018-02-16 Thread Chris via Digitalmars-d
On Friday, 16 February 2018 at 09:44:27 UTC, aberba wrote: D has tone of features and library solutions. When you encounter a problem, how do you approach solving it in code? 1. Do you first write it in idiomatic D style or a more general approach before porting to idiomatic D? As idiomatic

Re: Knowing the approach to solve a D challenge

2018-02-16 Thread Joakim via Digitalmars-d
I don't write much D code, but here are my answers for _any_ language. On Friday, 16 February 2018 at 09:44:27 UTC, aberba wrote: D has tone of features and library solutions. When you encounter a problem, how do you approach solving it in code? 1. Do you first write it in idiomatic D style o

Re: Knowing the approach to solve a D challenge

2018-02-16 Thread rikki cattermole via Digitalmars-d
On 16/02/2018 9:44 AM, aberba wrote: D has tone of features and library solutions. When you encounter a problem, how do you approach solving it in code? 1. Do you first write it in idiomatic D style or a more general approach before porting to idiomatic D? 2. Do you find yourself mostly roll

Knowing the approach to solve a D challenge

2018-02-16 Thread aberba via Digitalmars-d
D has tone of features and library solutions. When you encounter a problem, how do you approach solving it in code? 1. Do you first write it in idiomatic D style or a more general approach before porting to idiomatic D? 2. Do you find yourself mostly rolling out your own implementation first

Challenge on Russian Stack Overflow

2016-11-11 Thread Jack Applegame via Digitalmars-d
I found funny (from my point of view) challenge in Russian Stack Overflow. Any language accepted. You need to make the loop for (int x=0; x<3; ++x) {} endless. Rules: - you can't modify the loop's code itself; - you can't modify the loop's variable inside the body of

Re: Challenge

2016-10-05 Thread Manu via Digitalmars-d
On 6 October 2016 at 01:07, Jonathan M Davis via Digitalmars-d wrote: > On Thursday, October 06, 2016 00:38:54 Manu via Digitalmars-d wrote: >> I thought there was a distinction between typetuple and alias? Some >> expression can be captured by a typetuple, but not by alias? >> There must be a rea

Re: Challenge

2016-10-05 Thread Jonathan M Davis via Digitalmars-d
On Thursday, October 06, 2016 00:38:54 Manu via Digitalmars-d wrote: > I thought there was a distinction between typetuple and alias? Some > expression can be captured by a typetuple, but not by alias? > There must be a reason for that horrible and prolific pattern "(T...) > if(T.length == 1) { ...

Re: Challenge

2016-10-05 Thread Manu via Digitalmars-d
On 5 October 2016 at 19:45, Jonathan M Davis via Digitalmars-d wrote: > On Wednesday, October 05, 2016 09:24:56 John Colvin via Digitalmars-d wrote: >> > It _is_ however recommended to use __traits(getMember, T, >> > member) over manually building it with strings with something >> > like T.stringo

Re: Challenge

2016-10-05 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, October 05, 2016 09:24:56 John Colvin via Digitalmars-d wrote: > > It _is_ however recommended to use __traits(getMember, T, > > member) over manually building it with strings with something > > like T.stringof ~ "." ~ member, because the string manipulation > > falls about in corner

Re: Challenge

2016-10-05 Thread John Colvin via Digitalmars-d
On Wednesday, 5 October 2016 at 02:15:13 UTC, Jonathan M Davis wrote: On Wednesday, October 05, 2016 11:20:44 Manu via Digitalmars-d wrote: > While you're at it, might I suggest also adding > std.traits.isProperty? > > Something like: > template isProperty(T, string member) > { > > import st

Re: Challenge

2016-10-05 Thread Daniel N via Digitalmars-d
On Wednesday, 5 October 2016 at 02:15:13 UTC, Jonathan M Davis wrote: The AliasSeq muck is there because for some reason you can't alias the result of __traits, so doing something like alias sym = __traits(getMember, T, member); isn't legal. So, this has nothing to do with a recommendation of

Re: Challenge

2016-10-04 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, October 05, 2016 11:20:44 Manu via Digitalmars-d wrote: > > While you're at it, might I suggest also adding std.traits.isProperty? > > > > Something like: > > template isProperty(T, string member) > > { > > > > import std.meta : AliasSeq; > > import std.traits : FunctionTypeOf; >

Re: Challenge

2016-10-04 Thread Manu via Digitalmars-d
On 4 October 2016 at 22:48, Manu wrote: > On 4 October 2016 at 14:40, Jonathan M Davis via Digitalmars-d > wrote: >> On Tuesday, October 04, 2016 14:24:59 Manu via Digitalmars-d wrote: >>> On 4 October 2016 at 12:30, Jonathan M Davis via Digitalmars-d >>> >>> wrote: >>> > On Tuesday, October 04,

Re: Challenge

2016-10-04 Thread Manu via Digitalmars-d
On 4 October 2016 at 14:40, Jonathan M Davis via Digitalmars-d wrote: > On Tuesday, October 04, 2016 14:24:59 Manu via Digitalmars-d wrote: >> On 4 October 2016 at 12:30, Jonathan M Davis via Digitalmars-d >> >> wrote: >> > On Tuesday, October 04, 2016 11:13:36 Manu via Digitalmars-d wrote: >> >>

Re: Challenge

2016-10-03 Thread Manu via Digitalmars-d
On 4 October 2016 at 14:40, Jonathan M Davis via Digitalmars-d wrote: > [...] > For that matter, even testing whether something is a variable is > surprisingly difficult. True story! I've written that one before... I spent ages trying to get it right! When people say D is highly complex, these ar

Re: Challenge

2016-10-03 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, October 04, 2016 14:24:59 Manu via Digitalmars-d wrote: > On 4 October 2016 at 12:30, Jonathan M Davis via Digitalmars-d > > wrote: > > On Tuesday, October 04, 2016 11:13:36 Manu via Digitalmars-d wrote: > >> I'm feeling John's solution is a little bit simpler. But nice work, > >> than

Re: Challenge

2016-10-03 Thread Manu via Digitalmars-d
On 4 October 2016 at 12:30, Jonathan M Davis via Digitalmars-d wrote: > On Tuesday, October 04, 2016 11:13:36 Manu via Digitalmars-d wrote: >> I'm feeling John's solution is a little bit simpler. But nice work, thanks! > > So, it is. LOL. I'd actually glanced over that post while I was in the > mi

Re: Challenge

2016-10-03 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, October 04, 2016 11:13:36 Manu via Digitalmars-d wrote: > I'm feeling John's solution is a little bit simpler. But nice work, thanks! So, it is. LOL. I'd actually glanced over that post while I was in the middle of getting my version to work, and I read it too quickly, because I unders

Re: Challenge

2016-10-03 Thread Manu via Digitalmars-d
On 4 October 2016 at 05:01, Jonathan M Davis via Digitalmars-d wrote: > On Monday, October 03, 2016 11:13:52 Jonathan M Davis via Digitalmars-d wrote: >> template isStaticMember(T, string member) >> { >> static if (!__traits(hasMember, T, member)) >> enum bool isStaticMember = false; >

Re: Challenge

2016-10-03 Thread Manu via Digitalmars-d
On 4 October 2016 at 00:25, John Colvin via Digitalmars-d wrote: > On Monday, 3 October 2016 at 13:19:19 UTC, Manu wrote: >> >> Fill in the blank... >> I'm having a really hard time with this. I've made it work with a >> mountain of code, and I want to see what others come up with... > > > templat

Re: Challenge

2016-10-03 Thread Jonathan M Davis via Digitalmars-d
On Monday, October 03, 2016 11:13:52 Jonathan M Davis via Digitalmars-d wrote: > template isStaticMember(T, string member) > { > static if (!__traits(hasMember, T, member)) > enum bool isStaticMember = false; > else > { > import std.meta : AliasSeq; > import std.

Re: Challenge

2016-10-03 Thread Ali Çehreli via Digitalmars-d
On 10/03/2016 07:41 AM, Seb wrote: On Monday, 3 October 2016 at 13:19:19 UTC, Manu wrote: Fill in the blank... I'm having a really hard time with this. I've made it work with a mountain of code, and I want to see what others come up with... If you succeed, put it in std.traits! Recommend, use

Re: Challenge

2016-10-03 Thread Jonathan M Davis via Digitalmars-d
On Monday, October 03, 2016 08:38:22 Jonathan M Davis via Digitalmars-d wrote: > On Monday, October 03, 2016 23:19:19 Manu via Digitalmars-d wrote: > > Fill in the blank... > > I'm having a really hard time with this. I've made it work with a > > mountain of code, and I want to see what others come

Re: Challenge

2016-10-03 Thread Jonathan M Davis via Digitalmars-d
On Monday, October 03, 2016 23:19:19 Manu via Digitalmars-d wrote: > Fill in the blank... > I'm having a really hard time with this. I've made it work with a > mountain of code, and I want to see what others come up with... It's certainly possible that this misses something, but it passes all of y

Re: Challenge

2016-10-03 Thread Jonathan M Davis via Digitalmars-d
On Monday, October 03, 2016 23:19:19 Manu via Digitalmars-d wrote: > Fill in the blank... > I'm having a really hard time with this. I've made it work with a > mountain of code, and I want to see what others come up with... > > If you succeed, put it in std.traits! > > Recommend, use latest DMD nig

Re: Challenge

2016-10-03 Thread Seb via Digitalmars-d
On Monday, 3 October 2016 at 13:19:19 UTC, Manu wrote: Fill in the blank... I'm having a really hard time with this. I've made it work with a mountain of code, and I want to see what others come up with... If you succeed, put it in std.traits! Recommend, use latest DMD nightly. I find differe

Re: Challenge

2016-10-03 Thread Manu via Digitalmars-d
On 3 October 2016 at 23:48, Manu wrote: > On 3 October 2016 at 23:41, Manu wrote: >> I'm finding this rather annoying: >> >> struct S >> { >> static @property int p() { return 10; } >> } >> >> pragma(msg, typeof(&S.p)); // prints: int function() @property >> pragma(msg, is(typeof(&S.p) == funct

Re: Challenge

2016-10-03 Thread John Colvin via Digitalmars-d
On Monday, 3 October 2016 at 13:19:19 UTC, Manu wrote: Fill in the blank... I'm having a really hard time with this. I've made it work with a mountain of code, and I want to see what others come up with... template isStaticMember(T, string member) { mixin(`alias mem = T.` ~ member ~ `;`);

Re: Challenge

2016-10-03 Thread Temtaime via Digitalmars-d
On Monday, 3 October 2016 at 13:19:19 UTC, Manu wrote: Fill in the blank... I'm having a really hard time with this. I've made it work with a mountain of code, and I want to see what others come up with... [...] Dere's a typo static assert( isStaticMember!(S, "iosm"), "!"); Should be iosf

Re: Challenge

2016-10-03 Thread Kagamin via Digitalmars-d
On Monday, 3 October 2016 at 13:41:13 UTC, Manu wrote: I'm finding this rather annoying: struct S { static @property int p() { return 10; } } pragma(msg, typeof(&S.p)); // prints: int function() @property pragma(msg, is(typeof(&S.p) == function)); // prints: false It looks like a function...

Re: Challenge

2016-10-03 Thread Manu via Digitalmars-d
On 3 October 2016 at 23:50, John Colvin via Digitalmars-d wrote: > On Monday, 3 October 2016 at 13:41:13 UTC, Manu wrote: >> >> I'm finding this rather annoying: >> >> struct S >> { >> static @property int p() { return 10; } >> } >> >> pragma(msg, typeof(&S.p)); // prints: int function() @proper

Re: Challenge

2016-10-03 Thread Dicebot via Digitalmars-d
On Monday, 3 October 2016 at 13:50:26 UTC, John Colvin wrote: The problem is that function pointers in "is" expressions don't match "function" or "delegate". static assert (is(void delegate() == delegate)); //passes static assert (is(void function() == function)); //fails static assert (is(void

Re: Challenge

2016-10-03 Thread Dicebot via Digitalmars-d
On Monday, 3 October 2016 at 13:41:13 UTC, Manu wrote: I'm finding this rather annoying: struct S { static @property int p() { return 10; } } pragma(msg, typeof(&S.p)); // prints: int function() @property pragma(msg, is(typeof(&S.p) == function)); // prints: false It looks like a function...

Re: Challenge

2016-10-03 Thread Manu via Digitalmars-d
On 3 October 2016 at 23:41, Manu wrote: > I'm finding this rather annoying: > > struct S > { > static @property int p() { return 10; } > } > > pragma(msg, typeof(&S.p)); // prints: int function() @property > pragma(msg, is(typeof(&S.p) == function)); // prints: false > > It looks like a function

Re: Challenge

2016-10-03 Thread John Colvin via Digitalmars-d
On Monday, 3 October 2016 at 13:41:13 UTC, Manu wrote: I'm finding this rather annoying: struct S { static @property int p() { return 10; } } pragma(msg, typeof(&S.p)); // prints: int function() @property pragma(msg, is(typeof(&S.p) == function)); // prints: false It looks like a function...

Re: Challenge

2016-10-03 Thread Andrea Fontana via Digitalmars-d
On Monday, 3 October 2016 at 13:19:19 UTC, Manu wrote: Fill in the blank... I'm having a really hard time with this. I've made it work with a mountain of code, and I want to see what others come up with... If you succeed, put it in std.traits! Pretty easy: template isStaticMember(T, string m

Re: Challenge

2016-10-03 Thread Manu via Digitalmars-d
I'm finding this rather annoying: struct S { static @property int p() { return 10; } } pragma(msg, typeof(&S.p)); // prints: int function() @property pragma(msg, is(typeof(&S.p) == function)); // prints: false It looks like a function... but I can't identify it as a function!

Challenge

2016-10-03 Thread Manu via Digitalmars-d
Fill in the blank... I'm having a really hard time with this. I've made it work with a mountain of code, and I want to see what others come up with... If you succeed, put it in std.traits! Recommend, use latest DMD nightly. I find differences with latest nightly vs release. -

Re: Challenge: fair partition function

2016-02-08 Thread Xinok via Digitalmars-d
would have if r were sorted. Also, r[0 .. x] contains stuff no greater than r[x] and r[x + 1 .. $] contains stuff no less than r[x]. The challenge is to implement such a function with fairness: if several elements are equal to r[pivot], return the index closest to r.length / 2. The fu

Challenge: fair partition function

2016-02-08 Thread Andrei Alexandrescu via Digitalmars-d
r than r[x] and r[x + 1 .. $] contains stuff no less than r[x]. The challenge is to implement such a function with fairness: if several elements are equal to r[pivot], return the index closest to r.length / 2. The function should be efficient, minimize calls to less and swap, etc. A variant t

Re: Challenge

2015-08-30 Thread anonymous via Digitalmars-d
On Sunday 30 August 2015 16:43, rsw0x wrote: > Is there any reason that closure in this particular example can't > be created on the stack? Seems a bit weird. It may be possible to store it on the stack somehow, or as part of the map struct. I don't know. The point is, that's not what happens.

Re: Challenge

2015-08-30 Thread rsw0x via Digitalmars-d
On Sunday, 30 August 2015 at 13:36:45 UTC, anonymous wrote: On Sunday 30 August 2015 12:21, rsw0x wrote: [...] I think this shouldn't compile and it only does so because of issue 14771. https://issues.dlang.org/show_bug.cgi?id=14771 The delegate in foo uses a local variable and it's retur

Re: Challenge

2015-08-30 Thread anonymous via Digitalmars-d
On Sunday 30 August 2015 12:21, rsw0x wrote: > import std.algorithm, std.range; > > auto foo(R)(R a, immutable int b) > { > return a.map!(x => x + b); > } > > @nogc @safe unittest > { > int[3] test = [1,2,3]; > > assert(test[].foo(3).equal(only(4,5,6))); > } > > does this count?

Re: Challenge

2015-08-30 Thread John Colvin via Digitalmars-d
On Sunday, 30 August 2015 at 11:21:34 UTC, Russel Winder wrote: On Sun, 2015-08-30 at 10:38 +, John Colvin via Digitalmars-d wrote: On Sunday, 30 August 2015 at 10:15:14 UTC, John Colvin wrote: > [...] Ok, so now I feel stupid. Not only was the unittest I gave above broken anyway, I realis

Re: Challenge

2015-08-30 Thread Russel Winder via Digitalmars-d
> > } > > > > unittest @nogc @safe > > { > > int[] test = [1,2,3]; > > > > assert(test.foo(3).equal(only(4,5,6))); > > } > > > > Challenge: reimplement `foo` such that above unittest will > > compile. No cheating with malloc

Re: Challenge

2015-08-30 Thread John Colvin via Digitalmars-d
On Sunday, 30 August 2015 at 10:15:14 UTC, John Colvin wrote: import std.algorithm, std.range; auto foo(R)(R a, immutable int b) { return a.map!(x => x + b); } unittest @nogc @safe { int[] test = [1,2,3]; assert(test.foo(3).equal(only(4,5,6))); } Challenge: reimplement `foo` s

Re: Challenge

2015-08-30 Thread rsw0x via Digitalmars-d
o(3).equal(only(4,5,6))); } Challenge: reimplement `foo` such that above unittest will compile. No cheating with malloc etc. Bonus points if you don't have to implement a modified version of std.algorithm.map import std.algorithm, std.range; auto foo(R)(R a, immutable int b) { return

Re: Challenge

2015-08-30 Thread rsw0x via Digitalmars-d
On Sunday, 30 August 2015 at 10:15:14 UTC, John Colvin wrote: import std.algorithm, std.range; auto foo(R)(R a, immutable int b) { return a.map!(x => x + b); } unittest @nogc @safe { int[] test = [1,2,3]; assert(test.foo(3).equal(only(4,5,6))); } Challenge: reimplement `foo` s

Challenge

2015-08-30 Thread John Colvin via Digitalmars-d
import std.algorithm, std.range; auto foo(R)(R a, immutable int b) { return a.map!(x => x + b); } unittest @nogc @safe { int[] test = [1,2,3]; assert(test.foo(3).equal(only(4,5,6))); } Challenge: reimplement `foo` such that above unittest will compile. No cheating with malloc

Re: Today's programming challenge - How's your Range-Fu ?

2015-04-21 Thread John Colvin via Digitalmars-d
On Tuesday, 21 April 2015 at 13:06:22 UTC, JohnnyK wrote: On Monday, 20 April 2015 at 19:24:01 UTC, Panke wrote: On Monday, 20 April 2015 at 18:03:50 UTC, John Colvin wrote: On Monday, 20 April 2015 at 17:48:17 UTC, Panke wrote: To measure the columns needed to print a string, you'll need the

Re: Today's programming challenge - How's your Range-Fu ?

2015-04-21 Thread JohnnyK via Digitalmars-d
On Monday, 20 April 2015 at 19:24:01 UTC, Panke wrote: On Monday, 20 April 2015 at 18:03:50 UTC, John Colvin wrote: On Monday, 20 April 2015 at 17:48:17 UTC, Panke wrote: To measure the columns needed to print a string, you'll need the number of graphemes. (d|)?string.length gives you the numb

Re: Today's programming challenge - How's your Range-Fu ?

2015-04-20 Thread rumbu via Digitalmars-d
On Monday, 20 April 2015 at 19:24:01 UTC, Panke wrote: On Monday, 20 April 2015 at 18:03:50 UTC, John Colvin wrote: On Monday, 20 April 2015 at 17:48:17 UTC, Panke wrote: To measure the columns needed to print a string, you'll need the number of graphemes. (d|)?string.length gives you the numb

Re: Today's programming challenge - How's your Range-Fu ?

2015-04-20 Thread Panke via Digitalmars-d
On Monday, 20 April 2015 at 18:03:50 UTC, John Colvin wrote: On Monday, 20 April 2015 at 17:48:17 UTC, Panke wrote: To measure the columns needed to print a string, you'll need the number of graphemes. (d|)?string.length gives you the number of code units. Even that's not really true. Why?

Re: Today's programming challenge - How's your Range-Fu ?

2015-04-20 Thread Chris via Digitalmars-d
On Monday, 20 April 2015 at 17:48:17 UTC, Panke wrote: This can lead to subtle bugs, cf. length of random and e_one. You have to convert everything to dstring to get the "expected" result. However, this is not always desirable. There are three things that you need to be aware of when handling

  1   2   3   4   5   6   >