www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Advent of Code

reply Regan Heath <regan netmail.co.nz> writes:
Hi all,

Long time since I read/posted here but I saw this and thought it 
might be good PR for D:
http://adventofcode.com/

Should also be fun.

Ciao,
Regan
Dec 01 2015
next sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/01/2015 08:08 AM, Regan Heath wrote:
 Hi all,

 Long time since I read/posted here but I saw this and thought it might
 be good PR for D:
 http://adventofcode.com/

 Should also be fun.

 Ciao,
 Regan
My visit was short due to this: To play, please identify yourself via one of these services: [github] [google] [twitter] [reddit] Ali
Dec 01 2015
parent reply Charles <csmith.ku2013 gmail.com> writes:
On Tuesday, 1 December 2015 at 22:57:38 UTC, Ali Çehreli wrote:
 My visit was short due to this:

  To play, please identify yourself via one of these services:

 [github] [google] [twitter] [reddit]

 Ali
I was the same way earlier, but reddit doesn't need personal information, so you can just make a throwaway account. Did the first question and it was painfully simple. !!!! SPOILERS (stop reading here if you want to do it) !!! auto input = "arbitrarily long string of '(' and ')'"; int floor; foreach(movement; input) floor += (movement == '(' ? 1 : -1); writeln(floor);
Dec 01 2015
next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/01/2015 07:50 PM, Charles wrote:
 On Tuesday, 1 December 2015 at 22:57:38 UTC, Ali Çehreli wrote:
 My visit was short due to this:

  To play, please identify yourself via one of these services:

 [github] [google] [twitter] [reddit]

 Ali
I was the same way earlier, but reddit doesn't need personal information, so you can just make a throwaway account.
I over-reacted. In fact, I have accounts on three of those, except twitter. Oh well... Ali
Dec 01 2015
prev sibling next sibling parent drug <drug2004 bk.ru> writes:
On 02.12.2015 06:50, Charles wrote:
 On Tuesday, 1 December 2015 at 22:57:38 UTC, Ali Çehreli wrote:
 My visit was short due to this:

  To play, please identify yourself via one of these services:

 [github] [google] [twitter] [reddit]

 Ali
I was the same way earlier, but reddit doesn't need personal information, so you can just make a throwaway account. Did the first question and it was painfully simple. !!!! SPOILERS (stop reading here if you want to do it) !!! auto input = "arbitrarily long string of '(' and ')'"; int floor; foreach(movement; input) floor += (movement == '(' ? 1 : -1); writeln(floor);
If you copy the input with spaces (like I did) the code above gives wrong result because the requirement is the input should contain only "(" and ")".
Dec 01 2015
prev sibling parent reply Adrian Matoga <epi atari8.info> writes:
On Wednesday, 2 December 2015 at 03:50:20 UTC, Charles wrote:
(..)
     auto input = "arbitrarily long string of '(' and ')'";

     int floor;
     foreach(movement; input)
         floor += (movement == '(' ? 1 : -1);

     writeln(floor);
Speak D to me, please. stdin.byLine.front.map!(a => a.predSwitch('(', 1, ')', -1, 0)).sum.writeln;
Dec 02 2015
parent reply Sean Campbell <sycam.inc gmail.com> writes:
On Wednesday, 2 December 2015 at 08:45:11 UTC, Adrian Matoga 
wrote:
 On Wednesday, 2 December 2015 at 03:50:20 UTC, Charles wrote:
 (..)
     auto input = "arbitrarily long string of '(' and ')'";

     int floor;
     foreach(movement; input)
         floor += (movement == '(' ? 1 : -1);

     writeln(floor);
Speak D to me, please. stdin.byLine.front.map!(a => a.predSwitch('(', 1, ')', -1, 0)).sum.writeln;
how is this D speek. it's far shorter and easier to read if you use writefln("floor %s",input.count('(') - input.count(')'));
Dec 08 2015
parent Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= writes:
On Wednesday, 9 December 2015 at 02:48:31 UTC, Sean Campbell 
wrote:
 how is this D speek. it's far shorter and easier to read if you 
 use
 writefln("floor %s",input.count('(') - input.count(')'));
Yes, I don't find chaining of methods all that easy to read either, but you can do less work by taking advantage of D already knowing the length of the input: import std.stdio; import std.algorithm; void main(){ immutable input = "(((())"; immutable long len = input.length - 2*input.count(')'); writeln(len); }
Dec 09 2015
prev sibling parent w0rp <devw0rp gmail.com> writes:
Thanks for suggesting this. This is fun! Although, I've taken on 
quite a different challenge myself. I'm computing all of the 
answers only by using my console in Firefox. I'm actually getting 
through these pretty quickly. (It helps to know some ES5 and 
ES6.) I can imagine the D code already, and they are actually 
pretty similar to the JavaScript I've been writing.
Dec 08 2015