* Advent of Code Day 4
@ 2020-12-04 16:16 John Perry
2020-12-04 18:25 ` Jeffrey R. Carter
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: John Perry @ 2020-12-04 16:16 UTC (permalink / raw)
I found this one tougher, in part because I've never done much text file processing, but also because the directions were very scant on the format of the entries, and I wasn't about to comb carefully through hundreds of entries to see what all the variations might be.
I'll be very interested to see how different people read the file.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 16:16 Advent of Code Day 4 John Perry
@ 2020-12-04 18:25 ` Jeffrey R. Carter
2020-12-04 19:33 ` gautier...@hotmail.com
2020-12-04 22:55 ` Stephen Leake
2 siblings, 0 replies; 13+ messages in thread
From: Jeffrey R. Carter @ 2020-12-04 18:25 UTC (permalink / raw)
On 12/4/20 5:16 PM, John Perry wrote:
> I found this one tougher, in part because I've never done much text file processing, but also because the directions were very scant on the format of the entries, and I wasn't about to comb carefully through hundreds of entries to see what all the variations might be.
>
> I'll be very interested to see how different people read the file.
Enumeration types are your friend.
--
Jeff Carter
"[O]ne can look forward to a rapid and widespread
improvement in programming practice, both from
those who use the language [Ada] and from those
who study its concepts and structures."
C. A. R. Hoare
181
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 16:16 Advent of Code Day 4 John Perry
2020-12-04 18:25 ` Jeffrey R. Carter
@ 2020-12-04 19:33 ` gautier...@hotmail.com
2020-12-04 20:20 ` Maxim Reznik
2020-12-04 22:55 ` Stephen Leake
2 siblings, 1 reply; 13+ messages in thread
From: gautier...@hotmail.com @ 2020-12-04 19:33 UTC (permalink / raw)
> I'll be very interested to see how different people read the file.
https://github.com/zertovitch/hac/tree/master/exm/aoc/2020
Part Two has two solutions: one, aoc_2020_04_b.adb, using HAC (with its current limitations) and one which is "full Ada", aoc_2020_04_b_full_ada.adb.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 19:33 ` gautier...@hotmail.com
@ 2020-12-04 20:20 ` Maxim Reznik
2020-12-04 21:27 ` gautier...@hotmail.com
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Maxim Reznik @ 2020-12-04 20:20 UTC (permalink / raw)
Day 4 task is dull :)
https://github.com/reznikmm/ada-howto/blob/advent-2020/md/04/04.md
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 20:20 ` Maxim Reznik
@ 2020-12-04 21:27 ` gautier...@hotmail.com
2020-12-05 3:56 ` Simon Beàn
2020-12-05 15:11 ` John Perry
2 siblings, 0 replies; 13+ messages in thread
From: gautier...@hotmail.com @ 2020-12-04 21:27 UTC (permalink / raw)
> https://github.com/reznikmm/ada-howto/blob/advent-2020/md/04/04.md
Nice one!
Index ("amb blu brn gry grn hzl oth", Text) > 0;
Oh, was 172 also considered correct for part two?!
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 16:16 Advent of Code Day 4 John Perry
2020-12-04 18:25 ` Jeffrey R. Carter
2020-12-04 19:33 ` gautier...@hotmail.com
@ 2020-12-04 22:55 ` Stephen Leake
2020-12-04 23:49 ` Jeffrey R. Carter
2020-12-05 2:06 ` Advent of Code Day 4 Stephen Leake
2 siblings, 2 replies; 13+ messages in thread
From: Stephen Leake @ 2020-12-04 22:55 UTC (permalink / raw)
John Perry <john.perry@usm.edu> writes:
> I found this one tougher, in part because I've never done much text
> file processing, but also because the directions were very scant on
> the format of the entries, and I wasn't about to comb carefully
> through hundreds of entries to see what all the variations might be.
>
> I'll be very interested to see how different people read the file.
I used gnat.Regpat:
Field : constant Pattern_Matcher := Compile ("([a-z][a-z][a-z]):([^ ]+)");
Height : constant Pattern_Matcher := Compile ("([0-9]+)(cm|in)");
Hair_Color : constant Pattern_Matcher := Compile ("#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]");
Eye_Color : constant Pattern_Matcher := Compile ("amb|blu|brn|gry|grn|hzl|oth");
ID : constant Pattern_Matcher := Compile ("[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
But apparently I've done something wrong; I counted 225 valid passports
for part 2, which the website claims is too high. My code parsed the
example valid/invalid passports correctly. I started going thru the full
input manually to check, but that's much too tedious. If we were doing
this for real, we'd have a test file with each entry labeled
valid/invalid.
I'm assuming we each get different data files? maybe not? mine has 1169
lines, first passport entry is:
iyr:2015 cid:189 ecl:oth byr:1947 hcl:#6c4ab1 eyr:2026
hgt:174cm
pid:526744288
--
-- Stephe
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 22:55 ` Stephen Leake
@ 2020-12-04 23:49 ` Jeffrey R. Carter
2020-12-05 0:11 ` recantation Bill Findlay
2020-12-05 2:06 ` Advent of Code Day 4 Stephen Leake
1 sibling, 1 reply; 13+ messages in thread
From: Jeffrey R. Carter @ 2020-12-04 23:49 UTC (permalink / raw)
On 12/4/20 11:55 PM, Stephen Leake wrote:
>
> I'm assuming we each get different data files? maybe not? mine has 1169
> lines, first passport entry is:
>
> iyr:2015 cid:189 ecl:oth byr:1947 hcl:#6c4ab1 eyr:2026
> hgt:174cm
> pid:526744288
Mine starts
ecl:amb
pid:690616023
byr:1994 iyr:2014 hgt:172cm hcl:#c0946f eyr:2022
and has 953 lines.
--
Jeff Carter
"[O]ne can look forward to a rapid and widespread
improvement in programming practice, both from
those who use the language [Ada] and from those
who study its concepts and structures."
C. A. R. Hoare
181
^ permalink raw reply [flat|nested] 13+ messages in thread
* recantation
2020-12-04 23:49 ` Jeffrey R. Carter
@ 2020-12-05 0:11 ` Bill Findlay
0 siblings, 0 replies; 13+ messages in thread
From: Bill Findlay @ 2020-12-05 0:11 UTC (permalink / raw)
On 4 Dec 2020, Jeffrey R. Carter wrote (in
article<rqehuk$9pr$1@dont-email.me>):
> "[O]ne can look forward to a rapid and widespread improvement in programming
> practice, both from those who use the language [Ada] and from those who study
> its concepts and structures."
> C. A. R. Hoare
I have great *personal* appreciation of that declaration!
--
Bill Findlay
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 22:55 ` Stephen Leake
2020-12-04 23:49 ` Jeffrey R. Carter
@ 2020-12-05 2:06 ` Stephen Leake
2020-12-05 11:56 ` Jeffrey R. Carter
1 sibling, 1 reply; 13+ messages in thread
From: Stephen Leake @ 2020-12-05 2:06 UTC (permalink / raw)
Stephen Leake <stephen_leake@stephe-leake.org> writes:
> I used gnat.Regpat:
>
> Field : constant Pattern_Matcher := Compile ("([a-z][a-z][a-z]):([^ ]+)");
>
> Height : constant Pattern_Matcher := Compile ("([0-9]+)(cm|in)");
>
> Hair_Color : constant Pattern_Matcher := Compile
> ("#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]");
>
> Eye_Color : constant Pattern_Matcher := Compile ("amb|blu|brn|gry|grn|hzl|oth");
>
> ID : constant Pattern_Matcher := Compile
> ("[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
>
>
> But apparently I've done something wrong;
I downloaded the solution posted by Gautier de Montmollin, and used that
to debug my code. The problem is the pattern for ID above matches 9
digits followed by anything, and one of the bad passports has a 10 digit
ID. I added a check for length = 9 (gnat regpat doesn't have a pattern
representing "end of string") and got the right answer.
--
-- Stephe
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 20:20 ` Maxim Reznik
2020-12-04 21:27 ` gautier...@hotmail.com
@ 2020-12-05 3:56 ` Simon Beàn
2020-12-05 15:11 ` John Perry
2 siblings, 0 replies; 13+ messages in thread
From: Simon Beàn @ 2020-12-05 3:56 UTC (permalink / raw)
On Friday, December 4, 2020 at 3:20:06 PM UTC-5, Maxim Reznik wrote:
> Day 4 task is dull :)
>
> https://github.com/reznikmm/ada-howto/blob/advent-2020/md/04/04.md
TIL so much! Thank you!
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-05 2:06 ` Advent of Code Day 4 Stephen Leake
@ 2020-12-05 11:56 ` Jeffrey R. Carter
2020-12-05 14:00 ` Stephen Leake
0 siblings, 1 reply; 13+ messages in thread
From: Jeffrey R. Carter @ 2020-12-05 11:56 UTC (permalink / raw)
On 12/5/20 3:06 AM, Stephen Leake wrote:
>
> I downloaded the solution posted by Gautier de Montmollin, and used that
> to debug my code. The problem is the pattern for ID above matches 9
> digits followed by anything, and one of the bad passports has a 10 digit
> ID. I added a check for length = 9 (gnat regpat doesn't have a pattern
> representing "end of string") and got the right answer.
Right. Technically every field needs a check that it's followed by a space or
line end, and in production code there would be other checks I would make, but
as this is Q&D and the input is otherwise well formed, I left them out.
--
Jeff Carter
"Every sperm is sacred."
Monty Python's the Meaning of Life
55
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-05 11:56 ` Jeffrey R. Carter
@ 2020-12-05 14:00 ` Stephen Leake
0 siblings, 0 replies; 13+ messages in thread
From: Stephen Leake @ 2020-12-05 14:00 UTC (permalink / raw)
"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
> On 12/5/20 3:06 AM, Stephen Leake wrote:
>> I downloaded the solution posted by Gautier de Montmollin, and used
>> that
>> to debug my code. The problem is the pattern for ID above matches 9
>> digits followed by anything, and one of the bad passports has a 10 digit
>> ID. I added a check for length = 9 (gnat regpat doesn't have a pattern
>> representing "end of string") and got the right answer.
>
> Right. Technically every field needs a check that it's followed by a
> space or line end, and in production code there would be other checks
> I would make, but as this is Q&D and the input is otherwise well
> formed, I left them out.
One lesson here is we should not rely on the examples provided in the
puzzle to be a complete test; we should review them for completeness.
--
-- Stephe
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Advent of Code Day 4
2020-12-04 20:20 ` Maxim Reznik
2020-12-04 21:27 ` gautier...@hotmail.com
2020-12-05 3:56 ` Simon Beàn
@ 2020-12-05 15:11 ` John Perry
2 siblings, 0 replies; 13+ messages in thread
From: John Perry @ 2020-12-05 15:11 UTC (permalink / raw)
On Friday, December 4, 2020 at 2:20:06 PM UTC-6, Maxim Reznik wrote:
> Day 4 task is dull :)
>
> https://github.com/reznikmm/ada-howto/blob/advent-2020/md/04/04.md
Flourishes like this:
return Pasport (byr .. pid) = (byr .. pid => True);
illustrate idioms that I really want to learn, thanks for sharing.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2020-12-05 15:11 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-04 16:16 Advent of Code Day 4 John Perry
2020-12-04 18:25 ` Jeffrey R. Carter
2020-12-04 19:33 ` gautier...@hotmail.com
2020-12-04 20:20 ` Maxim Reznik
2020-12-04 21:27 ` gautier...@hotmail.com
2020-12-05 3:56 ` Simon Beàn
2020-12-05 15:11 ` John Perry
2020-12-04 22:55 ` Stephen Leake
2020-12-04 23:49 ` Jeffrey R. Carter
2020-12-05 0:11 ` recantation Bill Findlay
2020-12-05 2:06 ` Advent of Code Day 4 Stephen Leake
2020-12-05 11:56 ` Jeffrey R. Carter
2020-12-05 14:00 ` Stephen Leake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox