comp.lang.ada
 help / color / mirror / Atom feed
* advent of code day 10
@ 2020-12-11  3:39 Stephen Leake
  2020-12-11  5:40 ` Jared Summers
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Stephen Leake @ 2020-12-11  3:39 UTC (permalink / raw)


This was a more interesting puzzle. It is almost "sort, find consecutive
skips, multiply by n choose k", but not quite.

I cheated; the final total is larger than 64 bits, so I just printed out
the factors and used Emacs built-in bignums to compute it. I assume
there is an Ada bignums package out there, and the compiler has one that
full Ada 2020 will expose, but I'm trying to catch up, so did not look.

-- 
-- Stephe

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

* Re: advent of code day 10
  2020-12-11  3:39 advent of code day 10 Stephen Leake
@ 2020-12-11  5:40 ` Jared Summers
  2020-12-11 17:04   ` Stephen Leake
  2020-12-11  7:22 ` gautier...@hotmail.com
  2020-12-11 14:14 ` gautier...@hotmail.com
  2 siblings, 1 reply; 7+ messages in thread
From: Jared Summers @ 2020-12-11  5:40 UTC (permalink / raw)


On Thursday, December 10, 2020 at 8:39:36 PM UTC-7, Stephen Leake wrote:
> I cheated; the final total is larger than 64 bits, so I just printed out 
> the factors and used Emacs built-in bignums to compute it. I assume 
> there is an Ada bignums package out there, and the compiler has one that 
> full Ada 2020 will expose, but I'm trying to catch up, so did not look. 

My answer was able to fit in a Long_Long_Integer on my machine. But, due to a bug, I did play with the Big_Integers package. It worked well, and I'd recommend taking a look at it for upcoming problems. Based on past years it'll be useful to have on hand.

--
Jared

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

* Re: advent of code day 10
  2020-12-11  3:39 advent of code day 10 Stephen Leake
  2020-12-11  5:40 ` Jared Summers
@ 2020-12-11  7:22 ` gautier...@hotmail.com
  2020-12-11 14:14 ` gautier...@hotmail.com
  2 siblings, 0 replies; 7+ messages in thread
From: gautier...@hotmail.com @ 2020-12-11  7:22 UTC (permalink / raw)


On Friday, December 11, 2020 at 4:39:36 AM UTC+1, Stephen Leake wrote:
> I cheated; the final total is larger than 64 bits, so I just printed out 
> the factors and used Emacs built-in bignums to compute it. I assume 
> there is an Ada bignums package out there, and the compiler has one that 
> full Ada 2020 will expose, but I'm trying to catch up, so did not look. 

It's surprising how different in scale the answers are, depending on the input data.
Mine was "only" around 37 trillion.

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

* Re: advent of code day 10
  2020-12-11  3:39 advent of code day 10 Stephen Leake
  2020-12-11  5:40 ` Jared Summers
  2020-12-11  7:22 ` gautier...@hotmail.com
@ 2020-12-11 14:14 ` gautier...@hotmail.com
  2020-12-12 20:17   ` Stephen Leake
  2 siblings, 1 reply; 7+ messages in thread
From: gautier...@hotmail.com @ 2020-12-11 14:14 UTC (permalink / raw)


On Friday, December 11, 2020 at 4:39:36 AM UTC+1, Stephen Leake wrote:
> the final total is larger than 64 bits
The total for your data is 3022415986688, it holds in 42 bits...

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

* Re: advent of code day 10
  2020-12-11  5:40 ` Jared Summers
@ 2020-12-11 17:04   ` Stephen Leake
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Leake @ 2020-12-11 17:04 UTC (permalink / raw)


Jared Summers <jtsummers@gmail.com> writes:

> On Thursday, December 10, 2020 at 8:39:36 PM UTC-7, Stephen Leake wrote:
>> I cheated; the final total is larger than 64 bits, so I just printed out 
>> the factors and used Emacs built-in bignums to compute it. I assume 
>> there is an Ada bignums package out there, and the compiler has one that 
>> full Ada 2020 will expose, but I'm trying to catch up, so did not look. 
>
> My answer was able to fit in a Long_Long_Integer on my machine. But,
> due to a bug, I did play with the Big_Integers package. It worked
> well, and I'd recommend taking a look at it for upcoming problems.

Yes; GNAT Community 2020 with -gnat2020 and -gnatX supports
Ada.Numerics.Big_Integer. I updated my solution to use that.

-- 
-- Stephe

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

* Re: advent of code day 10
  2020-12-11 14:14 ` gautier...@hotmail.com
@ 2020-12-12 20:17   ` Stephen Leake
  2020-12-12 22:25     ` Jeffrey R. Carter
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Leake @ 2020-12-12 20:17 UTC (permalink / raw)


"gautier...@hotmail.com" <gautier_niouzes@hotmail.com> writes:

> On Friday, December 11, 2020 at 4:39:36 AM UTC+1, Stephen Leake wrote:
>> the final total is larger than 64 bits
> The total for your data is 3022415986688, it holds in 42 bits...

hmm. I got constraint error when I used Long_Integer; maybe that's not
64 bits? Using Ada.Big_Numbers.Big_Integers was a good exercise anyway.

-- 
-- Stephe

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

* Re: advent of code day 10
  2020-12-12 20:17   ` Stephen Leake
@ 2020-12-12 22:25     ` Jeffrey R. Carter
  0 siblings, 0 replies; 7+ messages in thread
From: Jeffrey R. Carter @ 2020-12-12 22:25 UTC (permalink / raw)


On 12/12/20 9:17 PM, Stephen Leake wrote:
> "gautier...@hotmail.com" <gautier_niouzes@hotmail.com> writes:
> 
>> On Friday, December 11, 2020 at 4:39:36 AM UTC+1, Stephen Leake wrote:
>>> the final total is larger than 64 bits
>> The total for your data is 3022415986688, it holds in 42 bits...
> 
> hmm. I got constraint error when I used Long_Integer; maybe that's not
> 64 bits? Using Ada.Big_Numbers.Big_Integers was a good exercise anyway.

That sounds like C thinking. If you need 64 bits, say so, don't hope that 
optional language-defined types will be big enough.

type S is range -(2 ** 63) + 1 .. 2 ** 63 - 1;
type U is mod 2 ** 64;

I used

type U is mod System.Max_Binary_Modulus;

-- 
Jeff Carter
"Frankie Wolf, wanted by Federal authorities for
dancing with a mailman."
Take the Money and Run
143

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

end of thread, other threads:[~2020-12-12 22:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11  3:39 advent of code day 10 Stephen Leake
2020-12-11  5:40 ` Jared Summers
2020-12-11 17:04   ` Stephen Leake
2020-12-11  7:22 ` gautier...@hotmail.com
2020-12-11 14:14 ` gautier...@hotmail.com
2020-12-12 20:17   ` Stephen Leake
2020-12-12 22:25     ` Jeffrey R. Carter

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