# Advent of Code 2023

**URL:** <https://fortran-lang.discourse.group/t/advent-of-code-2023/6885>\
**Category:** Humor\
**Created:** [November 30, 2023, 10:57pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885 "2023-11-30T22:57:14Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 2, 2023, 4:26pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/22 "2023-12-02T16:26:21Z")

</div>

> [@certik](#):
>
> They ask not to use AI, so I am not going to submit it.

It is interesting to consider that such tools can impact not only education but also this kind of competitions.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [December 2, 2023, 4:37pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/23 "2023-12-02T16:37:47Z")

</div>

> [@vmagnin](#):
>
> > [@Beliavsky](#):
> >
> > ChatGPT is asked to code each task multiple times, because sometimes it produces code that fails to compile or gives wrong answers.
> 
> Can you tell us more about what kind of codes you can achieve? And in how many iterations?
> 
> I guess the next step could be to use TDD: you write the tests first, then the script asks ChatGPT to write the main code, then verifies if the tests are passed, asking ChatGPT to improve the results, etc.
> 
> It would be partially similar to evolutionary optimisation (genetic algorithms). The fitness function could be the number of passed tests.

I have not experimented much. Some `*.txt` files in the [repo](https://github.com/Beliavsky/ChatGPT-Fortran-generator) show output for simulating pi using Monte Carlo and estimating Euler’s number using a Taylor series. ChatGPT can generate codes that don’t compile, give correct results, or give wrong results. The last case is the most problematic.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 2, 2023, 4:44pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/24 "2023-12-02T16:44:33Z")

</div>

> [@Beliavsky](#):
>
> Some `*.txt` files in the [repo](https://github.com/Beliavsky/ChatGPT-Fortran-generator) show output for simulating pi using Monte Carlo and estimating Euler’s number using a Taylor series.

Thanks, I did not see. It seems those small problems need typically 4 attempts which is reasonable.

> [@Beliavsky](#):
>
> or give wrong results. The last case is the most problematic.

Yes, TDD would be necessary for such cases.

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [December 2, 2023, 4:55pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/25 "2023-12-02T16:55:53Z")

</div>

No wonder someone wanted to bite the bullet and write a program to automate the tedious process to make AI work after several tries. However, quite often AI will only give you a code snippet and you are supposed to fill the details (which is ok, but I wonder how a python program will cope with that.)  
In addition, AI may never find a correct solution. I’m sure I am not the only one who saw it failing several times in a row, then falling down the rabbit hole (the infinite loop I mentioned earlier - exact same answer, presented as a new one.)

Programs like that prove we are just playing some form of the “imitation game reversed” here. We know in advance the one we are “talking” with is not a human, it’s not intelligent no matter how we stress the term. And we know it probably won’t make it by itself. The problem is then shifted from “using AI to accelerate some actual work” to “find a good way to hold AI’s hand step by step so it can finally walk”.

As a search engine, AI can be quite useful. As far translation is concerned, a specialized AI is actually quite decent (but again, not to be trusted, you can’t just copy/paste its translation.) However as far programming is concerned, it is far away from being even that.

Have you ever tried a chess program that has “characters” available? It gives you the option to choose the playing style of your opponent. You can pick an offensive opponent, a defensive opponent, a queen hunter, a Sicilian Defense advocate, whatever. While playing, it gives you the impression you are dealing with an intelligent opponent who also has some character. But it’s all fake, it’s just pre-programmed to play a specific way. All it does is comparisons, and it does it quickly. No intelligence involved.  
Same thing here. We have an advanced parser able to (usually) “understand” what we ask and compose a readable answer. But it’s all fake, it understood nothing because it has no intelligence to understand anything, and the answer is not to be trusted.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 2, 2023, 5:37pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/26 "2023-12-02T17:37:20Z")

</div>

> [@Pap](#):
>
> But it’s all fake

That is the good news, it won’t decide by itself (as it has no _self_) to register to the Advent of Code 2023 and ruin your pleasure!

Finally _we_ can play the imitation game, and we like it although we are sadly playing alone. We have not yet found an E.T., so maybe we are looking for an A.I.

---

<div class="post-metadata">

**Author:** ![Carltoffel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/carltoffel/32/1680_2.png) [@Carltoffel](https://fortran-lang.discourse.group/u/Carltoffel)\
**Post date:** [December 2, 2023, 6:23pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/27 "2023-12-02T18:23:58Z")

</div>

Because some of you were curious what the capabilities of ChatGPT4 are.  
I asked the GPT to write tests and the main program for task one of day one:

[https://chat.openai.com/share/269d5bfb-9924-4b32-a7f7-f517dee93bee](https://chat.openai.com/share/269d5bfb-9924-4b32-a7f7-f517dee93bee)

BTW, in Python it can run its own code and directly verify it.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 2, 2023, 8:09pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/28 "2023-12-02T20:09:37Z")

</div>

> [@Carltoffel](#):
>
> Because some of you were curious what the capabilities of ChatGPT4 are.  
> I asked the GPT to write tests and the main program for task one of day one:

It is impressive that it could work well on that subject that sounds rather original (therefore probably not present in the learning process like could be something about prime numbers for example).

And it does not seem perturbed (and not even “interested”) by the Elves story. All information useless seems to have been automatically filtered.

Advent of Code participants now look like Kasparov… for this 1st problem at least.

---

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [December 2, 2023, 8:16pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/29 "2023-12-02T20:16:18Z")

</div>

I’ve used AI to generate an image of what I will look like around day 20… seems pretty accurate!!

 ![_57c5cc08-5068-4099-9391-8dd84df3a3b8](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/2/24064ae16c9e854003c2654785fe755915a1c34d.jpeg)

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [December 2, 2023, 8:26pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/30 "2023-12-02T20:26:10Z")

</div>

@jacobwilliams Great image, except it got the Fortran logo wrong!

---

<div class="post-metadata">

**Author:** ![jeff.irwin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jeff.irwin/32/3673_2.png) [@jeff.irwin](https://fortran-lang.discourse.group/u/jeff.irwin)\
**Post date:** [December 2, 2023, 8:27pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/31 "2023-12-02T20:27:12Z")

</div>

That was day 19 for me last year. And I still don’t know dynamic programming 🤦‍♂️

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [December 2, 2023, 8:34pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/32 "2023-12-02T20:34:26Z")

</div>

> [@Pap](#):
>
> Precisely. The question is, can it really accelerate your work, when the work to guide it takes more time?

The answer is most definitely yes for me. It took less than 2 minutes to get a working solution in Python. I couldn’t have written it in such a short time frame, and I am good at Python. The Fortran solution took maybe 3 minutes, as I had to workaround some simple bugs. I would not be able to get it done in Fortran in 3 minutes either. It would probably take me 10 to 20 minutes. So for me, for this task, I got at least 4x speedup (possibly more).

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [December 2, 2023, 8:42pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/33 "2023-12-02T20:42:35Z")

</div>

> [@vmagnin](#):
>
> It is interesting to consider that such tools can impact not only education but also this kind of competitions.

In some ways chatGPT is kind of like reviewing PRs for me: I am still responsible for the final outcome, but it does most of the real work, I only check the solution and focus on figuring out proper ways to fix it if the approach is incorrect. For Day 1 it was a big help. I am sure for some of the more complicated problems it will fail miserably and I might need to actually do them myself.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 2, 2023, 8:43pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/34 "2023-12-02T20:43:30Z")

</div>

> [@certik](#):
>
> @jacobwilliams Great image, except it got the Fortran logo wrong!

Definitely “inspired” by this logo found in Bing:

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/7/75667aa9914079dfca4a50efc9066b62b7dd1b18.png)

Be careful with copyright! 😄 Although the [fortran-tech.com](http://fortran-tech.com) site seems not online anymore.  
I think using such a tool to generate your own company logo would be dangerous…

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [December 2, 2023, 9:00pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/35 "2023-12-02T21:00:10Z")

</div>

> [@certik](#):
>
> So for me, for this task, I got at least 4x speedup (possibly more).

Either the task was really simple, or you are using a much better AI than the one I have access to (I’ll definitely never pay for such a thing.)

But imagine it wasn’t @certik but a student who is just learning Fortran. They would need way more time and effort to write the program by themselves than your 10-20 minutes. But they will _learn_ something in the process. If the AI can do it for them, they will learn _absolutely nothing_ (unless of course they opt not to use it, which I doubt.) And they need to learn a lot of things.

It makes perfect sense for you to use the AI in this case. You won’t learn anything if you write the program yourself, because _for you_ it’s just a simple task, you did something similar countless of times already. So it makes sense to just say “this is boring, write the program for me”. What about the student I mentioned though?

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 2, 2023, 9:15pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/36 "2023-12-02T21:15:47Z")

</div>

> [@Pap](#):
>
> It makes perfect sense for you to use the AI in this case. You won’t learn anything if you write the program yourself, because _for you_ it’s just a simple task, you did something similar countless of times already. So it makes sense to just say “this is boring, write the program for me”. What about the student I mentioned though?

As She said:

> Its province is to assist us in making available what we are already acquainted with.

To be acquainted with or not to be acquainted with, that is the question…

How to teach students to use such meta tools, as they don’t even master the basics? At which level? How to prevent them to use such tools to avoid learning the basics? (classroom teaching is needed more than ever but the tendency to reduce public spending is reducing face-to-face)

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [December 2, 2023, 9:36pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/37 "2023-12-02T21:36:01Z")

</div>

> [@vmagnin](#):
>
> How to prevent them to use such tools to avoid learning the basics?

If you find a way to do that for more than a tiny minority of them, let me know. Because I see no way to achieve this. I think it’s just human nature. If they have something that will save them a few steps, they will use it without a second thought. Even though they do need to take those steps themselves, without help.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [December 2, 2023, 10:04pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/38 "2023-12-02T22:04:24Z")

</div>

> [@Pap](#):
>
> What about the student I mentioned though?

That’s a different (but important) question, how to teach students. We should probably start a separate thread for that.

Chess engines are better than humans for the past 20 years. If you want to learn chess, you have to learn how to play yourself, not let chess engines play for you. But you can use chess engines to help you get better. Isn’t this similar? If you want to learn programming, do it yourself. But you can use AI to help you get better. And if students don’t want to learn programming, then maybe they should do something else?

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [December 2, 2023, 10:23pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/39 "2023-12-02T22:23:41Z")

</div>

I see your point, I might have something to say but my verbosity will make in just another long sheet of text, which won’t even be the first today. And like you said this is stuff for another thread.

Let me just say that I realized I liked Mathematics more than Physics (which, technically, was what I was studying) when I had that big moment of “wow, I actually proved that theorem concerning cubic splines all by myself”. I could have an excuse to use an AI instead (after all, I was studying Physics, right? why should I care about proving a theorem, I just need to use it). I could very well use that AI, if I had it handy, losing that “big moment” forever, and never realizing Numerical Analysis is actually my thing, not Physics.

---

<div class="post-metadata">

**Author:** ![tyranids](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tyranids](https://fortran-lang.discourse.group/u/tyranids)\
**Post date:** [December 2, 2023, 11:39pm UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/40 "2023-12-02T23:39:05Z")

</div>

day 2 completed: [GitHub - dacarnazzola/Advent-of-Code-2023: advent of code 2023: https://adventofcode.com/2023](https://github.com/dacarnazzola/Advent-of-Code-2023)

If they keep on with this string parsing for every question, I will probably end up making some little string parsing module with nice utility functions rather than rewriting custom parsing for each day.

This one runs in 1-2ms, interesting 1/10th the input still takes 1/3 the time as day 1 for me. It’s probably a little less efficient to build up the `character(len=5) :: string` rather than just keeping a `first` and `last` index, but doing that approach would require more toggling logic. In the beginning I was close to creating a “split on delimiter” function to return a derived-type array of strings, since then it’s an easy pattern of every other element being number or color.

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [December 3, 2023, 12:37am UTC](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885/41 "2023-12-03T00:37:53Z")

</div>

I don’t worry about speed unless it becomes a real problem. Typically my Fortran solutions for these puzzles are fast enough. I enjoy stretching myself and seeing which “modern” Fortran features I can make use of. The early days are fairly easy, but they get harder during the month and often require knowledge of some advanced mathematics thing I don’t know, so I end up going to the discussion board for a hint.

I also don’t strive to get them done as early in the day as possible for max points.

I’m visiting my mom for the next week, so don’t know how many of these I will be able to do, but I am taking my laptop. I use Intel Fortran for this, and now use IFX exclusively - it will be interesting to see if I encounter any bugs.

[Previous page](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885.md?page=1)

[Next page](https://fortran-lang.discourse.group/t/advent-of-code-2023/6885.md?page=3)
