comp.lang.ada
 help / color / mirror / Atom feed
* Advent of Code day 2
@ 2020-12-02 22:47 Stephen Leake
  2020-12-02 23:45 ` John Perry
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Leake @ 2020-12-02 22:47 UTC (permalink / raw)


This is an example of the customer problem spec not being complete; in
the example, all the letter positions are single digit, so my first
draft assumed that, which made finding the values trivial. But then the
real input has 1 or 2 digit numbers.

Handling that took me a while; first I had to actually understand the
semantics of Ada.Strings.Index (Source, Set, Test); "the smallest index
satisfying the test" does _not_ produce a span of characters matching
the test; I should have used Gnatcoll.regexp.

Then I found an indent bug in the development version of emacs ada-mode,
which I took a detour to fix. Which is one reason to do this contest;
writing Ada code is a good way to find bugs in ada-mode. (just out of
curiosity; what development environments are you all using?)

Then for the second puzzle, the fact that Ada String slices _don't_ have
first index 1 confused things; I ended up writing a Slide function to
keep the logic simpler.

Finally got it right.

I was hoping to use 'Reduce in the sled rental count, but GNAT Community
2020 -gnat2020 -gnatX doesn't support that. I did use @, which I like a
lot.

-- 
-- Stephe

Written from unceded ancestral homelands of the Huichiun, an Ohlone
people,for which I pay Shuumi Land Tax

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Advent of Code day 2
  2020-12-02 22:47 Advent of Code day 2 Stephen Leake
@ 2020-12-02 23:45 ` John Perry
  2020-12-03 11:52   ` Stephen Leake
  0 siblings, 1 reply; 3+ messages in thread
From: John Perry @ 2020-12-02 23:45 UTC (permalink / raw)


On Wednesday, December 2, 2020 at 4:47:34 PM UTC-6, Stephen Leake wrote:
> This is an example of the customer problem spec not being complete; in 
> the example, all the letter positions are single digit, so my first 
> draft assumed that, which made finding the values trivial. But then the 
> real input has 1 or 2 digit numbers. 

I scanned the file and noticed the positions had up to two digits. But I also used Integer_IO's Get, so I don't think it mattered.

> ...I should have used Gnatcoll.regexp. 

I was wondering if there was a pattern matching library I could use, and had wanted to ask that, but forgot.

> (just out of curiosity; what development environments are you all using?) 

GPS, and learning about it as I go, which unfortunately is a bit odd on MacOS Catalina. It has some strange behaviors (e.g., dialogs pop up as full screen tabs), and since AdaCore won't support GPS on MacOS anymore, I should look at something else. I like IntelliJ's Idea a lot, but my vague recollection is that its Ada plugins are primitive.

> I was hoping to use 'Reduce in the sled rental count, but GNAT Community 
> 2020 -gnat2020 -gnatX doesn't support that.

May I ask what you mean by, "Reduce in the sled rental count"? I'm starting to wonder if we're talking about puzzles from different years.

john perry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Advent of Code day 2
  2020-12-02 23:45 ` John Perry
@ 2020-12-03 11:52   ` Stephen Leake
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Leake @ 2020-12-03 11:52 UTC (permalink / raw)


John Perry <john.perry@usm.edu> writes:

> On Wednesday, December 2, 2020 at 4:47:34 PM UTC-6, Stephen Leake wrote:
>> This is an example of the customer problem spec not being complete; in 
>> the example, all the letter positions are single digit, so my first 
>> draft assumed that, which made finding the values trivial. But then the 
>> real input has 1 or 2 digit numbers. 
>
> I scanned the file and noticed the positions had up to two digits. But
> I also used Integer_IO's Get, so I don't think it mattered.
>
>> ...I should have used Gnatcoll.regexp. 
>
> I was wondering if there was a pattern matching library I could use,
> and had wanted to ask that, but forgot.
>
>> (just out of curiosity; what development environments are you all using?) 
>
> GPS, and learning about it as I go, which unfortunately is a bit odd
> on MacOS Catalina. It has some strange behaviors (e.g., dialogs pop up
> as full screen tabs), and since AdaCore won't support GPS on MacOS
> anymore, I should look at something else. I like IntelliJ's Idea a
> lot, but my vague recollection is that its Ada plugins are primitive.
>
>> I was hoping to use 'Reduce in the sled rental count, but GNAT Community 
>> 2020 -gnat2020 -gnatX doesn't support that.
>
> May I ask what you mean by, "Reduce in the sled rental count"? 

'Reduce is a new Ada 2020 attribute
(www.ada-auth.org/standards/2xrm/html/RM-4-5-10.html); it can sum an
array.

The first puzzle in day 2 involved the password policy of the sled
rental shop; that required counting the number matching letters in the
password.

-- 
-- Stephe

Written from unceded ancestral homelands of the Huichiun, an Ohlone
people,for which I pay Shuumi Land Tax

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-03 11:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 22:47 Advent of Code day 2 Stephen Leake
2020-12-02 23:45 ` John Perry
2020-12-03 11:52   ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox