Here's my C implementation. Kind of glad it was a straightforward problem this time. Will do tomorrow's in Python.
#include <stdio.h> #include <string.h> int getSeatId(const char *seatDesc) { int ret = 0; for (int bi = 9; bi >= 0; bi--, seatDesc++) ret |= (*seatDesc == 'B' || *seatDesc == 'R') << bi; return ret; } int part1() { char seatDesc[100]; int maxId = -1, seatId; while (scanf("%s", seatDesc) == 1) { if ((seatId = getSeatId(seatDesc)) > maxId) maxId = seatId; printf("%s -> %d (%d)\n", seatDesc, seatId, maxId); } } int part2() { char seatDesc[100]; char filled[1 << 10]; memset(filled, 0, 1 << 10); while (scanf("%s", seatDesc) == 1) filled[getSeatId(seatDesc)] = 1; int seatId = 0; while (!filled[seatId]) seatId++; while (filled[seatId]) seatId++; printf("%d\n", seatId); } int main(int argc, const char *argv[]) { if (argc < 2 || argv[1][0] == '1') part1(); else part2(); return 0; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's my C implementation. Kind of glad it was a straightforward problem this time. Will do tomorrow's in Python.