From 68832a6f2b5ee7725e9cc21c21c57e1f3d151ff6 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 6 Dec 2019 05:53:42 -0500 Subject: Solve day 6 part 1 --- 2019/day06.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 2019/day06.c (limited to '2019') diff --git a/2019/day06.c b/2019/day06.c new file mode 100644 index 0000000..fbfda57 --- /dev/null +++ b/2019/day06.c @@ -0,0 +1,40 @@ +#include +#include +#include + +static struct Node { + char name[4]; + size_t parent; +} tree[2048]; + +static size_t node(const char *name) { + size_t i; + for (i = 0; tree[i].name[0]; ++i) { + if (strcmp(name, tree[i].name)) continue; + return i; + } + strncpy(tree[i].name, name, sizeof(tree[i].name)); + return i; +} + +static size_t ancestors(size_t i) { + size_t n = 0; + while (i) { + i = tree[i].parent; + n++; + } + return n; +} + +int main(void) { + node("COM"); + char parent[4], child[4]; + while (EOF != scanf("%3s)%3s\n", parent, child)) { + tree[node(child)].parent = node(parent); + } + size_t orbits = 0; + for (size_t i = 0; tree[i].name[0]; ++i) { + orbits += ancestors(i); + } + printf("%zu\n", orbits); +} -- cgit 1.4.1 efs/?h=1.3.0&id=c96becc1e5ebff9e6609e61e11e80debcb3a778c'>refs log tree commit diff
Commit message (Collapse)Author
2014-01-10cgit.c: Use "else" for mutually exclusive branchesLukas Fleischer
When parsing command line arguments, no pair of command line options can ever match simultaneously. Use "else if" blocks to reflect this. This change improves both readability and speed. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
2014-01-10ui-snapshot.c: Do not reinvent suffixcmp()Lukas Fleischer
Use suffixcmp() from Git instead of reimplementing it. This is a preparation for moving to ends_with() in Git 1.8.6. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
2014-01-10Refactor cgit_parse_snapshots_mask()Lukas Fleischer
Use Git string lists instead of str{spn,cspn,ncmp}() magic. This significantly improves readability. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
2014-01-10Disallow use of undocumented snapshot delimitersLukas Fleischer
Since the introduction of selective snapshot format configuration in dc3c9b5 (allow selective enabling of snapshots, 2007-07-21), we allowed seven different delimiters for snapshot formats, while the documentation has always been clear about spaces being the only valid delimiter: The value is a space-separated list of zero or more of the values "tar", "tar.gz", "tar.bz2", "tar.xz" and "zip". Supporting the undocumented delimiters makes the code unnecessarily complex. Remove them. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
2014-01-10Replace most uses of strncmp() with prefixcmp()Lukas Fleischer
This is a preparation for replacing all prefix checks with either strip_prefix() or starts_with() when Git 1.8.6 is released. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
2014-01-09README: Fix dependenciesLukas Fleischer
* Remove the dependency on Git (which can be obtained automatically when building, using either the Git submodule or `make get-git`). * Use proper upstream names of dependencies. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
2014-01-08README: Spelling and formatting fixesLukas Fleischer
* Several small spelling and capitalization fixes. * Use consistent and better-looking formatting that is compatible with AsciiDoc (and partly compatible with RST). Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
2014-01-08Fix UTF-8 with syntax-highlighting.pyPřemysl Janouch
Previously the script tried to encode output from Pygments with the ASCII codec, which failed. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com>
2014-01-08Add a suggestion to the manpagePřemysl Janouch
So that people wishing to use "enable-http-clone" don't have to find out the correct settings on their own. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com>
2014-01-08Fix the example configurationPřemysl Janouch
"enable-git-clone" doesn't exist, replaced with "enable-http-clone". Signed-off-by: Přemysl Janouch <p.janouch@gmail.com>
2014-01-08Fix about-formatting.shPřemysl Janouch
dash failed to parse the script. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com>
2014-01-08Fix some spelling errorsPřemysl Janouch
Signed-off-by: Přemysl Janouch <p.janouch@gmail.com>
2014-01-08filters: highlight.sh: add css comments for highlight 2.6 and 3.8Ferry Huberts