AdventOfCode2022/4
2022-12-08 01:46:35 +01:00
..
.gitignore removed vimspector, fixed readme 2022-12-05 16:26:58 +01:00
day4-by-ai.s added ai c code 2022-12-08 01:46:35 +01:00
day4.c added ai c code 2022-12-08 01:46:35 +01:00
day4.s day 4 2022-12-05 14:24:14 +01:00
Makefile day 4 2022-12-05 14:24:14 +01:00
prompt.md newlines 2022-12-05 14:41:42 +01:00
README.md added ai c code 2022-12-08 01:46:35 +01:00
section-pairs.txt day 4 2022-12-05 14:24:14 +01:00

Day 4

🎁🎁🎁🎁

Today's language: gnu x86-64 (and alternatively C)

Today I wanted to use OpenAI to solve the tasks using gnu x86-64 assembly, which I have never used before (I did some small things in 6502-asssembly, so it wasn't all new). The prompt can be seen in prompt.md, the original file in day4-by-ai.s. It did a lot of things right, however it also did a lot of things wrong:

  • 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)
  • 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

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. It was still a good starting point and provided lots of help. At the end of the evening next morning I had successfully coded the task in x86-64 assembly! 😃

I also gave it the exact same prompt again but said I wanted it in C. It instantly produced compile-able c day4-by-ai.c code that gave the right answer...

# for the assembly program
make asm
./day4
# for the c promgram
make c
./day4 "section-pairs.txt"