Thread overview
Advent of Code
Dec 01, 2015
Regan Heath
Dec 01, 2015
Ali Çehreli
Dec 02, 2015
Charles
Dec 02, 2015
Ali Çehreli
Dec 02, 2015
drug
Dec 02, 2015
Adrian Matoga
Dec 09, 2015
Sean Campbell
Dec 09, 2015
w0rp
December 01, 2015
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

December 01, 2015
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

December 02, 2015
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);
December 02, 2015
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

December 02, 2015
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 ")".
December 02, 2015
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;

December 09, 2015
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.
December 09, 2015
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(')'));
December 09, 2015
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);
}