/* aoc-c.c: Advent of Code 2022, day 4 * * Copyright (C) 2022 Bruno Raoult ("br") * Licensed under the GNU General Public License v3.0 or later. * Some rights reserved. See COPYING. * * You should have received a copy of the GNU General Public License along with this * program. If not, see . * * SPDX-License-Identifier: GPL-3.0-or-later */ #include #include #include #include "aoc.h" static int parse(int part) { int res = 0, val[4]; while (scanf("%d-%d,%d-%d", val, val+1, val+2, val+3) == 4) { if (part == 1) { if ( (val[0] >= val[2] && val[1] <= val[3] ) || (val[0] <= val[2] && val[1] >= val[3] ) ) { res++; } } else { if ( (val[0] >= val[2] && val[0] <= val[3] ) || (val[0] <= val[2] && val[1] >= val[2] ) ) { res++; } } } return res; } int main(int ac, char **av) { printf("%s: res=%d\n", *av, parse(parseargs(ac, av))); exit(0); }