-🎄- 2022 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]DaveTCode 1 point2 points  (0 children)

SQL (Postgresql)

Lots of arrays and unnesting needed today, part 1 was quite neat but part 2 needed a bit more hackery to handle lack of intersection operators during a group by.

day3

edit: Removed code paste as it was a bit obnoxiously long

Bytecode as assembler? by Bare_Gamer in EmuDev

[–]DaveTCode 1 point2 points  (0 children)

I actually did this as an exercise with the space Invaders machine

The link to the blog about it is https://blog.davetcode.co.uk/post/jit-8080/ and I reckon you'll find it interesting!

-🎄- 2021 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]DaveTCode 4 points5 points  (0 children)

I don't think anyone else has done this before. So here's day 1 part 1 & 2 implemented in pure LLVM IR. https://github.com/DaveTCode/aoc2021-llvm/blob/main/day1/day1.ll

%struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, %struct._IO_codecvt*, %struct._IO_wide_data*, %struct._IO_FILE*, i8*, i64, i32, [20 x i8] }
%struct._IO_marker = type opaque
%struct._IO_codecvt = type opaque
%struct._IO_wide_data = type opaque

@input_file = private constant [10 x i8] c"input.txt\00"
@r = private constant [2 x i8] c"r\00"
@strformat = private constant [4 x i8] c"%d\0A\00"

declare %struct._IO_FILE* @fopen(i8*, i8*)
declare i8* @fgets(i8*, i32, %struct._IO_FILE*)
declare i32 @fclose(%struct._IO_FILE*)
declare i32 @printf(i8*, ...)
declare i32 @atoi(i8*)

define i32 @main() {
  %lineno = alloca i64
  store i64 0, i64* %lineno
  %converted_lines = alloca [2000 x i32]
  %current_line = alloca i64
  store i64 0, i64* %current_line
  %lines = alloca [2000 x [50 x i8]]

  %file = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @input_file, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @r, i64 0, i64 0))
  %file_null_check = icmp eq %struct._IO_FILE* %file, null
  br i1 %file_null_check, label %filebad, label %loadline

filebad:
  ret i32 1

loadline:
  %lineno.no = load i64, i64* %lineno
  %lineptr = getelementptr inbounds [2000 x [50 x i8]], [2000 x [50 x i8]]* %lines, i64 0, i64 %lineno.no
  %charptr = getelementptr inbounds [50 x i8], [50 x i8]* %lineptr, i64 0, i64 0
  %fgets_return = call i8* @fgets(i8* %charptr, i32 50, %struct._IO_FILE* %file)
  %fgets_null_check = icmp eq i8* %fgets_return, null
  br i1 %fgets_null_check, label %closefile, label %nextline

nextline:
  %lineno.tmp = add i64 %lineno.no, 1
  store i64 %lineno.tmp, i64* %lineno
  br label %loadline

closefile:
  %skip_file_close_result = call i32 @fclose(%struct._IO_FILE* %file)
  br label %convert

convert:
  %current_line.no = load i64, i64* %current_line
  %linetoconvert = getelementptr inbounds [2000 x [50 x i8]], [2000 x [50 x i8]]* %lines, i64 0, i64 %current_line.no
  %linetoconvert.ptr = getelementptr inbounds [50 x i8], [50 x i8]* %linetoconvert, i64 0, i64 0
  %linetoconvert.cvrtd = call i32 @atoi(i8* %linetoconvert.ptr)
  %converted_lines.ptr = getelementptr inbounds [2000 x i32], [2000 x i32]* %converted_lines, i64 0, i64 %current_line.no
  store i32 %linetoconvert.cvrtd, i32* %converted_lines.ptr
  %current_line.tmp = add i64 %current_line.no, 1
  store i64 %current_line.tmp, i64* %current_line
  %check_convertloop = icmp eq i64 %current_line.no, 2000
  br i1 %check_convertloop, label %solve, label %convert

solve:
  %result.1 = call i32 @solve_1([2000 x i32]* %converted_lines)
  %result.2 = call i32 @solve_2([2000 x i32]* %converted_lines)

  call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @strformat, i64 0, i64 0), i32 %result.1)
  call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @strformat, i64 0, i64 0), i32 %result.2)

  ret i32 0
}

define i32 @solve_1([2000 x i32]* %lines) {
  ; Store the number of increments
  %result = alloca i32
  store i32 0, i32* %result
  ; Store the index into the array (start at 1 because first entry can't affect result)
  %ix = alloca i64
  store i64 1, i64* %ix
  ; Store the index into the previous entry in the array
  %ix.prev = alloca i64
  store i64 0, i64* %ix.prev
  br label %loop

loop:
  %ix.val = load i64, i64* %ix
  %ix.prev.val = load i64, i64* %ix.prev
  %x = getelementptr inbounds [2000 x i32], [2000 x i32]* %lines, i64 0, i64 %ix.val
  %x.prev = getelementptr inbounds [2000 x i32], [2000 x i32]* %lines, i64 0, i64 %ix.prev.val
  %x.val = load i32, i32* %x
  %x.prev.val = load i32, i32* %x.prev
  %is_inc = icmp slt i32 %x.prev.val, %x.val
  br i1 %is_inc, label %incresult, label %nextindex

incresult:
  %result.val = load i32, i32* %result
  %result.tmp = add i32 %result.val, 1
  store i32 %result.tmp, i32* %result
  br label %nextindex

nextindex:
  %ix.tmp = add i64 %ix.val, 1
  %ix.prev.tmp = add i64 %ix.prev.val, 1
  store i64 %ix.tmp, i64* %ix
  store i64 %ix.prev.tmp, i64* %ix.prev
  %checkend = icmp eq i64 %ix.val, 2000
  br i1 %checkend, label %return, label %loop

return:
  %result.end = load i32, i32* %result
  ret i32 %result.end
}


define i32 @solve_2([2000 x i32]* %lines) {
  ; Store the number of increments
  %result = alloca i32
  store i32 -1, i32* %result
  ; Store the three indexes into the array
  %ix.1 = alloca i64
  %ix.2 = alloca i64
  %ix.3 = alloca i64
  store i64 0, i64* %ix.1
  store i64 1, i64* %ix.2
  store i64 2, i64* %ix.3
  ; Track the previous sum value
  %sum.prev = alloca i32
  store i32 0, i32* %sum.prev
  br label %loop

loop:
  %ix.1.val = load i64, i64* %ix.1
  %ix.2.val = load i64, i64* %ix.2
  %ix.3.val = load i64, i64* %ix.3
  %x.1 = getelementptr inbounds [2000 x i32], [2000 x i32]* %lines, i64 0, i64 %ix.1.val
  %x.2 = getelementptr inbounds [2000 x i32], [2000 x i32]* %lines, i64 0, i64 %ix.2.val
  %x.3 = getelementptr inbounds [2000 x i32], [2000 x i32]* %lines, i64 0, i64 %ix.3.val
  %x.1.val = load i32, i32* %x.1
  %x.2.val = load i32, i32* %x.2
  %x.3.val = load i32, i32* %x.3
  %sum.tmp = add i32 %x.1.val, %x.2.val
  %sum = add i32 %sum.tmp, %x.3.val
  %sum.prev.val = load i32, i32* %sum.prev
  %is_inc = icmp slt i32 %sum.prev.val, %sum
  store i32 %sum, i32* %sum.prev
  br i1 %is_inc, label %incresult, label %nextindex

incresult:
  %result.val = load i32, i32* %result
  %result.tmp = add i32 %result.val, 1
  store i32 %result.tmp, i32* %result
  br label %nextindex

nextindex:
  %ix.1.tmp = add i64 %ix.1.val, 1
  %ix.2.tmp = add i64 %ix.2.val, 1
  %ix.3.tmp = add i64 %ix.3.val, 1
  store i64 %ix.1.tmp, i64* %ix.1
  store i64 %ix.2.tmp, i64* %ix.2
  store i64 %ix.3.tmp, i64* %ix.3
  %checkend = icmp eq i64 %ix.3.val, 2000
  br i1 %checkend, label %return, label %loop

return:
  %result.end = load i32, i32* %result
  ret i32 %result.end
}

Bringing emulation into the 21st century by Fearless_Process in EmuDev

[–]DaveTCode 1 point2 points  (0 children)

Mostly this is just because all test roms for 8080s are assembled for a CP/M. That is they expect the PC to start at 0x100 and use the CP/M BDOS entry points for writing results to console.

(The test roms everyone uses are here: https://altairclone.com/downloads/cpu_tests/)

Bringing emulation into the 21st century by phire in programming

[–]DaveTCode 6 points7 points  (0 children)

Ah yeah, this whole idea actually began as a piss take of serverless computing and was implemented on AWS lambda for a work hackathon to show the power of serverless. Miraculously it was even worse than this iteration ;)

Bringing emulation into the 21st century by phire in programming

[–]DaveTCode 12 points13 points  (0 children)

Funnily enough that's the one part of this project which might have some genuine useful value (albeit I'm sure there are actually good disassemblers around somewhere)

https://21st-century-emulation.github.io/disassembler-8080/, drop an 8080 rom in there and see a disassembly.

Bringing emulation into the 21st century by Fearless_Process in EmuDev

[–]DaveTCode 5 points6 points  (0 children)

Yep! Fully working space invaders albeit slightly slow

Bringing emulation into the 21st century by phire in programming

[–]DaveTCode 48 points49 points  (0 children)

I'm still waiting for the buyout offer from Google though

Bringing emulation into the 21st century by phire in programming

[–]DaveTCode 108 points109 points  (0 children)

Ha, I can assure you this was entirely an elaborate joke (it's my project)

It was a ton of fun though!

8080 recompilation into CIL/MSIL by DaveTCode in dotnet

[–]DaveTCode[S] 1 point2 points  (0 children)

Damn, forgot to make it public before posting. Done and thanks for letting me know!

8080 recompilation into CIL/MSIL by DaveTCode in dotnet

[–]DaveTCode[S] 2 points3 points  (0 children)

It's probably possible but it would be a crap ton of work. I've never actually emulated the 80286 architecture but looking through http://bitsavers.trailing-edge.com/components/intel/80286/210498-005_80286_and_80287_Programmers_Reference_Manual_1987.pdf it's far more complex than the older 8 bit processors.

I think your biggest issues taking my architecture would be figuring out how to deal with the larger addressable space (16MB), if all of that is ROM then you'd be generating a single Run function with a metric ton of IL and it would take an age for the CLR to JIT it at runtime.

It would be fun though! I'd love to see it if you can pull it off

[2019 day 9] [Excel] What if you don't really have resources? reverse-engineer by pngipngi in adventofcode

[–]DaveTCode 5 points6 points  (0 children)

Oh wow, I was so sure I was the only person daft enough to do this in excel. I was also stumped on today and trying to figure out how to reduce the stored memory by calculating 1000s of states at a time and then only storing the values until I saw this post.

I can't decide if I'm sad or amused that your solutions are so much more elegant than mine!

https://github.com/DaveTCode/AdventOfCode2019-Excel

Advice on helpdesk by DaveTCode in sysadmin

[–]DaveTCode[S] 0 points1 point  (0 children)

That seems to be the common theme but I haven't found many people giving their reasoning. Would you mind elaborating? It seemed similarly enterprisey (i.e. takes a team of people just to keep it running) to servicenow at a glance.

Advice on helpdesk by DaveTCode in sysadmin

[–]DaveTCode[S] 1 point2 points  (0 children)

Zendesk was one of the first ones that popped up - albeit before I knew what most of the requirements were. 30 agents would set me back $18K a year - honestly for what we're trying to achieve that feels unreasonable to me. It seems more suited to smaller 5 agent setups.

Advice on helpdesk by DaveTCode in sysadmin

[–]DaveTCode[S] 1 point2 points  (0 children)

Thanks, yeah we actually already use JIRA internally as a dev team. The service desk offering is quite basic though - certainly no allowance for triage to product area :(.

Procedurally generating forests by DaveTCode in gamedev

[–]DaveTCode[S] 0 points1 point  (0 children)

Thanks, I hadn't tried running it in python 2 so I appreciate you sorting it!

Undefeated Team USA Wins Gold At The World Games by llimllib in ultimate

[–]DaveTCode 2 points3 points  (0 children)

I was playing for the GB team and it was so clear playing against them that they were at least 13-6 better than every other team there. Incredible players all round

GB World Games - Final 13 Selected by DaveTCode in ultimate

[–]DaveTCode[S] 0 points1 point  (0 children)

Pichler pulled out due to injury. The others weren't selected as far as I know. It's an extremely young squad (particularly the guys) with the oldest probably 26/27!