Author Topic: Advent of code.  (Read 7224 times)

0 Members and 1 Guest are viewing this topic.

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Advent of code.
« Reply #25 on: December 15, 2023, 06:43:17 pm »
If you were a software engineer on my team.... I'd be requesting your retraining or reassignment right now.

If you were a software engineer on my team.... I'd be requesting your retraining or reassignment right now.

Can you run it properly with proper test data and less of an attitude and then prove it has a problem.

Seriously if it has a problem I'm curious to see a reproduction of it.

Prove to me it fails the requirements and produces an in correct answer?

Code: [Select]
$ printf onetwo > test-data.txt ; python x.py
Found one
Line Value: 11
Total: 11

Also, if you want a quick test don't use "onetwo", use "oneighten" and expect the answer 19.

So, why exactly should I avoid examples where your code fails if the goal supposedly is to demonstrate that your code fails?
 
The following users thanked this post: hans

Offline paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Advent of code.
« Reply #26 on: December 20, 2023, 11:22:22 am »
You obviously sat out the class on requirements.

Anyway.  What answer did you get?

Have you actually read the requirements?  Or are you just assuming things to troll?
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Advent of code.
« Reply #27 on: December 20, 2023, 12:56:02 pm »
You obviously sat out the class on requirements.

IC

Anyway.  What answer did you get?

Code: [Select]
$ printf onetwo > test-data.txt ; python x.py
Found one
Line Value: 11
Total: 11

Have you actually read the requirements?  Or are you just assuming things to troll?

So, where in the requirements does it say that the code should not recognize number names at the end of lines that don't have a line terminator?
 
The following users thanked this post: hans

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 392
  • Country: be
Re: Advent of code.
« Reply #28 on: December 20, 2023, 01:20:44 pm »
use "oneighten" and expect the answer 19.

Are you sure? I've tried out of curiosity, got this:

Code: [Select]
work> printf oneighten > test-data.txt ; python x.py
Found one
Found eight
Line Value: 18
Total: 18
 

Offline paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Advent of code.
« Reply #29 on: December 21, 2023, 11:06:32 am »
Look.  This isn't academia. Code which meets the requirements is correct.  Period.

I think what you are getting at is... if the last token on the last line is a match to a number the code will fail, unless you add a newline.  An "out by 1 error".

That's all very well, but the actual data file does NOT end with a token.  The data file is provided in advance.  It does not need to be careful with that corner case.  This is called "engineering".  Far too much time is wasted in software engineering by people making up requirements and trying to create their own death star.

So.  I will ask again. 

What answer did you get after you read the requirements of the original puzzle?

11 is wrong.

Look at it this way.  The site provides a unit test.  You take the data, run your code and provide the answer.  If that test passes ...   explain to me why you would spend someone else's money (usually) to modify it?
« Last Edit: December 21, 2023, 11:08:05 am by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Advent of code.
« Reply #30 on: December 21, 2023, 03:48:01 pm »
Look.  This isn't academia. Code which meets the requirements is correct.  Period.

I think what you are getting at is... if the last token on the last line is a match to a number the code will fail, unless you add a newline.  An "out by 1 error".

That's all very well, but the actual data file does NOT end with a token.  The data file is provided in advance.  It does not need to be careful with that corner case.  This is called "engineering".  Far too much time is wasted in software engineering by people making up requirements and trying to create their own death star.

So.  I will ask again. 

What answer did you get after you read the requirements of the original puzzle?

11 is wrong.

Look at it this way.  The site provides a unit test.  You take the data, run your code and provide the answer.  If that test passes ...   explain to me why you would spend someone else's money (usually) to modify it?

None of that is relevant to my observation that functional-style code tends to avoid such bugs, because you can't have off-by-one errors if you don't do manual index calculations.

Whether you think that bugs in code are fine isn't really something that I am interested in.
 

Offline paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Advent of code.
« Reply #31 on: December 22, 2023, 03:58:50 pm »
None of that is relevant to my observation that functional-style code tends to avoid such bugs, because you can't have off-by-one errors if you don't do manual index calculations.

So what is your functionally orientated solution?
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Advent of code.
« Reply #32 on: December 22, 2023, 06:21:34 pm »
So what is your functionally orientated solution?

I don't have one, but the PHP one someone pasted above looks like an approach I would have taken ... just maybe without the PHP ;-)

(And with a zero-width look-ahead added for dealing with overlapping words, I guess.)

It's clear and concise, easy to understand ... and that even though I haven't touched PHP in a long time.
 

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Advent of code.
« Reply #33 on: December 23, 2023, 05:01:52 am »
For the fun of it, a production-quality solution in Perl. If you squint really hard, you could even claim that it is functional style:

Code: [Select]
@x=qw(one two three four five six seven eight nine);
($",%x,$/)=('|',map(($_=>++$x),@x));
print(eval(<>=~s/(?=(@x))|[^\d\n]/$x{$1}/ger=~s/(?=(.)).*(.)/'$1$2'+/gr.0),"\n");
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf