~aperezdc/aoc2023

c29a87fb28170d9b551e7846fc459a487631e0fb — Adrian Perez de Castro 10 months ago 1ae2cf8
Day 02, part 2
4 files changed, 30 insertions(+), 10 deletions(-)

M .gitignore
M day02/Makefile
R day02/{day02a.d => day02.d}
R day02/{day02a.test => day02.test}
M .gitignore => .gitignore +1 -1
@@ 1,3 1,3 @@
*.r
*.in
/day02/day02a
/day02/day02

M day02/Makefile => day02/Makefile +3 -3
@@ 1,8 1,8 @@
all: day02a
all: day02

day02a: day02a.r
day02: day02.r
	vamos -c ~/draco/config c:drlink to $@ \
		from drlib:drstart.o+day02a.r \
		from drlib:drstart.o+day02.r \
		library drlib:drio.lib+drlib:draco.lib+drlib:dos.lib+drlib:exec.lib \
		smallcode


R day02/day02a.d => day02/day02.d +26 -6
@@ 138,47 138,67 @@ proc readColors(*uint red, green, blue) void:
    od;
corp;

proc doGame(uint gameid) bool:
proc doGame(uint gameid; *uint power) bool:
    uint min_red, min_green, min_blue;
    uint red, green, blue;
    bool continue, valid;

    min_red := 0;
    min_green := 0;
    min_blue := 0;

    valid := true;
    continue := true;
    while not match('\n') do
        readColors(&red, &green, &blue);

        if red > MAX_RED or green > MAX_GREEN or blue > MAX_BLUE then
            valid := false;
        fi;

        if red > min_red then
            min_red := red;
        fi;
        if green > min_green then
            min_green := green;
        fi;
        if blue > min_blue then
            min_blue := blue;
        fi;

        if match(';') then
            nextChar();
        fi;
    od;

    power* := min_red * min_green * min_blue;
    valid
corp;

proc main() void:
    uint gameid;
    uint sum;
    uint gameid, sum, power, powersum;

    HasPeekChar := false;

    sum := 0;
    sum := 0; powersum := 0;

    while peek() ~= END do
        expect("Game");
        gameid := readUint();
        expect(":");

        if doGame(gameid) then
        if doGame(gameid, &power) then
            sum := sum + gameid;
        fi;
        powersum := powersum + power;

        if match('\n') then
            nextChar();
        fi;
    od;

    writeln("Result: ", sum);
    writeln("Result 1: ", sum);
    writeln("Result 2: ", powersum);
    exit(0);
corp;


R day02/day02a.test => day02/day02.test +0 -0