Advent of Code

Check-in [52ef9f6ef4]
Login

Check-in [52ef9f6ef4]

Overview
Comment:201501 2nd star
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 52ef9f6ef4ba7228f1023e49bfeeae8c1ce550b4ff7aced90fa39e68776c1faa
User & Date: nnz on 2024-12-04 14:35:00
Original Comment: 201501: 2 stars
Other Links: manifest | tags
Context
2024-12-04
14:49
201502 1st star check-in: 94e59cac7b user: nnz tags: trunk
14:35
201501 2nd star check-in: 52ef9f6ef4 user: nnz tags: trunk
14:27
201501 1st star check-in: 7f37290fac user: nnz tags: trunk
Changes

Modified aoc2015.c from [e0a90f0adb] to [16ef74232c].

1

2
3
4
5












6
7
8
9
10
11

12
#include <stdio.h>


void aoc201501(char *data, size_t len) {
    (void)len; // unused argument
    int floor = 0;












    while (*data) {
        if (*data == '(') floor++;
        else if (*data == ')') floor--;
        data++;
    }
    printf("Santa is taken to floor {%d}.\n", floor);

}

>



|
>
>
>
>
>
>
>
>
>
>
>
>






>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include "aocdailies.h"

void aoc201501(char *data, size_t len) {
    (void)len; // unused argument
    int floor = 0, basementsteps = -1;
    char *ddata = data;                            // save start
    while (*data) {
        if (*data == '(') floor++;
        else if (*data == ')') floor--;
        data++;
        // if entered the basement, part 2 done
        if (floor == -1) {
            basementsteps = data - ddata;          // steps taken
            break;
        }
    }
    // continue with no regard to basement
    while (*data) {
        if (*data == '(') floor++;
        else if (*data == ')') floor--;
        data++;
    }
    printf("Santa is taken to floor {%d}.\n", floor);
    printf("Santa first goes to the basement at step {%d}.\n", basementsteps);
}