AdventOfCode2022/04/README.md

36 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2022-12-05 14:24:14 +01:00
# [Day 4](https://adventofcode.com/2022/day/4)
:gift::gift::gift::gift:
2023-12-09 13:46:15 +01:00
Today's language: **x86-64 Assembly**
Lines of code: **241**
Execution time: **0,010 s**
<!-- ChatGPT tought me Assembly -->
2022-12-05 14:39:31 +01:00
2022-12-10 23:58:27 +01:00
Today I wanted to use ChatGPT to solve the tasks using *gnu* **x86-64 assembly**, which I have never used before
2022-12-05 14:24:14 +01:00
(I did some small things in [6502-asssembly](https://github.com/MatthiasQuintern/6502), so it wasn't all new).
2022-12-08 01:46:35 +01:00
The prompt can be seen in `prompt.md`, the original file in `day4-by-ai.s`.
2022-12-05 14:39:31 +01:00
It did a lot of things right, however it also did a lot of things wrong:
2022-12-05 14:24:14 +01:00
- It did generate x86 (32-bit) code because I did not specify x86-64. So I changed the `int $0x80` system calls to use `syscall` (which also meant I had to change all the registers and [syscall numbers](https://filippo.io/linux-syscall-table/))
2022-12-05 14:39:31 +01:00
- It did get the argument order for `sscanf` wrong, even when I specifically asked, it told me that the buffer to read comes last
- It did not correctly implement the logic to test for containment of the two ranges
- It sometimes gave me wrong syscall numbers (they were just wrong, not even x86)
- It told me the `read` syscall can read until a newline by passing `\n` as last arg
2022-12-05 14:24:14 +01:00
So I had to fix all that. I tried to exclusively use the AI to get answers to my questions, however I did sometimes revert to the internet.
2022-12-05 16:26:58 +01:00
It was still a good starting point and provided lots of help.
2022-12-05 14:39:31 +01:00
At the end of the ~~evening~~ next morning I had successfully coded the task in x86-64 assembly! :smiley:
2022-12-05 14:24:14 +01:00
2022-12-05 14:39:31 +01:00
I also gave it the exact same prompt again but said I wanted it in **C**.
2022-12-08 01:46:35 +01:00
It instantly produced compile-able c `day4-by-ai.c` code that gave the right answer...
2022-12-05 14:24:14 +01:00
```shell
2022-12-05 14:39:31 +01:00
# for the assembly program
2022-12-05 14:24:14 +01:00
make asm
./day4
# for the c promgram
make c
2022-12-05 14:39:31 +01:00
./day4 "section-pairs.txt"
2022-12-05 14:24:14 +01:00
```