mid-kid
6 years ago
commit
4299855be7
22 changed files with 4211 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||||
|
CFLAGS := -Wall -Wextra -std=c17 -D_GNU_SOURCE |
||||
|
|
||||
|
.PHONY: all |
||||
|
all: main |
||||
|
|
||||
|
.PHONY: clean |
||||
|
clean: |
||||
|
rm -f main |
File diff suppressed because it is too large
Binary file not shown.
@ -0,0 +1,25 @@ |
|||||
|
#include <stdlib.h> |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
int value = 0; |
||||
|
char *line = NULL; |
||||
|
size_t line_len = 0; |
||||
|
FILE *f = fopen("input", "r"); |
||||
|
if (!f) { |
||||
|
perror("input"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
while (getline(&line, &line_len, f) != -1) { |
||||
|
long number = strtol(line, NULL, 0); |
||||
|
value += number; |
||||
|
} |
||||
|
|
||||
|
printf("%d\n", value); |
||||
|
|
||||
|
free(line); |
||||
|
fclose(f); |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
value = 0 |
||||
|
|
||||
|
for line in io.lines("input") do |
||||
|
value = value + tonumber(line) |
||||
|
end |
||||
|
|
||||
|
print(value) |
@ -0,0 +1,16 @@ |
|||||
|
CFLAGS := -Wall -Wextra -std=c17 -D_GNU_SOURCE |
||||
|
|
||||
|
LIBS := glib-2.0 |
||||
|
CFLAGS += $(shell pkg-config --cflags $(LIBS)) |
||||
|
LDLIBS := $(shell pkg-config --libs $(LIBS)) |
||||
|
|
||||
|
.PHONY: all |
||||
|
all: main main_hash |
||||
|
|
||||
|
.PHONY: clean |
||||
|
clean: |
||||
|
rm -f main main_hash |
||||
|
|
||||
|
main_hash: CFLAGS += -DUSE_HASH |
||||
|
main_hash: main.c |
||||
|
$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@ |
File diff suppressed because it is too large
Binary file not shown.
@ -0,0 +1,75 @@ |
|||||
|
#include <stdlib.h> |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
#include <glib.h> |
||||
|
|
||||
|
/*
|
||||
|
* Apparently using a hash table for this is much faster... |
||||
|
* |
||||
|
* $ time ./main |
||||
|
* 69285 |
||||
|
* ./main 271,27s user 0,11s system 99% cpu 4:33,04 total |
||||
|
* $ time ./main_hash |
||||
|
* 69285 |
||||
|
* ./main_hash 0,13s user 0,02s system 98% cpu 0,156 total |
||||
|
*/ |
||||
|
|
||||
|
#ifndef USE_HASH |
||||
|
gpointer g_array_lookup(GArray *array, gpointer item, guint size) |
||||
|
{ |
||||
|
for (gchar *i = array->data; i < array->data + array->len * size; i += size) { |
||||
|
if (memcmp(i, item, size) == 0) { |
||||
|
return i; |
||||
|
} |
||||
|
} |
||||
|
return NULL; |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
long value = 0; |
||||
|
char *line = NULL; |
||||
|
size_t line_len = 0; |
||||
|
FILE *f = fopen("input", "r"); |
||||
|
if (!f) { |
||||
|
perror("input"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
#ifdef USE_HASH |
||||
|
GHashTable *hash = g_hash_table_new(g_direct_hash, g_direct_equal); |
||||
|
g_hash_table_insert(hash, GINT_TO_POINTER(value), GINT_TO_POINTER(TRUE)); |
||||
|
#else |
||||
|
GArray *array = g_array_new(FALSE, FALSE, sizeof(long)); |
||||
|
g_array_append_val(array, value); |
||||
|
#endif |
||||
|
|
||||
|
while (1) { |
||||
|
rewind(f); |
||||
|
while (getline(&line, &line_len, f) != -1) { |
||||
|
long number = strtol(line, NULL, 0); |
||||
|
value += number; |
||||
|
|
||||
|
#ifdef USE_HASH |
||||
|
if (g_hash_table_lookup(hash, GINT_TO_POINTER(value))) goto found; |
||||
|
g_hash_table_insert(hash, GINT_TO_POINTER(value), GINT_TO_POINTER(TRUE)); |
||||
|
#else |
||||
|
if (g_array_lookup(array, &value, sizeof(long))) goto found; |
||||
|
g_array_append_val(array, value); |
||||
|
#endif |
||||
|
} |
||||
|
} |
||||
|
found: |
||||
|
|
||||
|
printf("%ld\n", value); |
||||
|
|
||||
|
#ifdef USE_HASH |
||||
|
g_hash_table_destroy(hash); |
||||
|
#else |
||||
|
g_array_free(array, TRUE); |
||||
|
#endif |
||||
|
free(line); |
||||
|
fclose(f); |
||||
|
return 0; |
||||
|
} |
Binary file not shown.
@ -0,0 +1,8 @@ |
|||||
|
CFLAGS := -Wall -Wextra -std=c17 -D_GNU_SOURCE |
||||
|
|
||||
|
.PHONY: all |
||||
|
all: main |
||||
|
|
||||
|
.PHONY: clean |
||||
|
clean: |
||||
|
rm -f main |
@ -0,0 +1,250 @@ |
|||||
|
wkzhyfdpluzeqvajtbbosngkxc |
||||
|
wrzhyfdplumeqvajtbioskfksc |
||||
|
wrzhyfdolumyqvajtbiosngkxs |
||||
|
urzhyfdplbmeqvrjtbiosngkxc |
||||
|
wrzhyfrulumeqvajtbiosngkxf |
||||
|
wrzhnfdprumvqvajtbiosngkxc |
||||
|
wrzhyfpplumeivajtbiosrgkxc |
||||
|
wrzhybdplumeqvaftbiosxgkxc |
||||
|
wrzgyfdplumeqvaltbiosngcxc |
||||
|
wrzhbfdzlumeqvajtbipsngkxc |
||||
|
wrzhyfdplumwqeajtbiosngxxc |
||||
|
wrzhyddplumeqvajtbimsngkxo |
||||
|
wrzhyfdplumsqdajtfiosngkxc |
||||
|
wrzvyfdplumeqjajtbkosngkxc |
||||
|
wrzhyfddlumeqvujtbiosngxxc |
||||
|
nrzhywdplumeqvajtbtosngkxc |
||||
|
wzzhyfdplomeqvdjtbiosngkxc |
||||
|
urzhyfdplumeqvaatbiosngkxb |
||||
|
wtzyyfdplumeqvajtbiosngkxl |
||||
|
wrzhyfdhlumnqvajebiosngkxc |
||||
|
wrzhyfdplumpqvajtbiosnyjxc |
||||
|
wrzdyfdplumeqvajtviospgkxc |
||||
|
wrzhyfdplzmeqvajtbiosegfxc |
||||
|
wrzhyfdglumkqvajtwiosngkxc |
||||
|
wrzhtfdplgmeqvaqtbiosngkxc |
||||
|
wrzhyfdplumeqvajxpiosngexc |
||||
|
frzhyfdplvmeqvajtbiosngkxp |
||||
|
wrzhyfkplumeqvajtbfosngkpc |
||||
|
irzhyfqplumeqvajtbiosngktc |
||||
|
wrzhyfdpluvoqvajtbioingkxc |
||||
|
wrzhyfdplumemvautbuosngkxc |
||||
|
wfzhyflplumeqvijtbiosngkxc |
||||
|
wrzhyfdglumeqvzjkbiosngkxc |
||||
|
wrzcyfdplaneqvajtbiosngkxc |
||||
|
wrzhbfdplumeqwajtbiosngpxc |
||||
|
szdhyfdplumeqvajtbiosngkxc |
||||
|
krzhyfdplumeqvajtxilsngkxc |
||||
|
brzhyfmplumexvajtbiosngkxc |
||||
|
wrzhyvdplumeqvajtbiosiglxc |
||||
|
orzhyfdplumeqvaotbcosngkxc |
||||
|
hrzhyfdplumeqvaptbiocngkxc |
||||
|
wwzhyfdklummqvajtbiosngkxc |
||||
|
wrzhyfdppymeqvvjtbiosngkxc |
||||
|
wsehyudplumeqvajtbiosngkxc |
||||
|
wrzhyzpplumeqvajtbioscgkxc |
||||
|
wrzhyfqpyumeqvajtbiusngkxc |
||||
|
urzhyfdpdumeqmajtbiosngkxc |
||||
|
wrzhyfdrlumxqvajtbiosnakxc |
||||
|
wrthyfdplumeskajtbiosngkxc |
||||
|
wrzhyfdplymeqvajtbiesbgkxc |
||||
|
wrzhyfdqlumeqyajtciosngkxc |
||||
|
trzhsfdplumeqyajtbiosngkxc |
||||
|
wpzhyfdplimeqvajtbiosngfxc |
||||
|
wrzhhfdplrmeqvajtbiosngkxx |
||||
|
wrzhycdpgumeqvajtbioslgkxc |
||||
|
wrzhyfdelumeqvajgtiosngkxc |
||||
|
wrzhyfdplutebvajtbiosygkxc |
||||
|
wrzhyfdplukeqvajtbiorngkec |
||||
|
erzhyfdilumeqvajwbiosngkxc |
||||
|
wrzhyfdplumnivxjtbiosngkxc |
||||
|
wrzhyfdplumebvajtoiovngkxc |
||||
|
wrzhyfdplumeqvajtbtosnwkxe |
||||
|
wrzhyfxplumevvajtciosngkxc |
||||
|
wbzhyfdxlumeqvajtriosngkxc |
||||
|
wrzyyfdplumeqvajmbiosngkxb |
||||
|
wfthyfdplumeqvajtbiosngkdc |
||||
|
wrzhuedplumeqvajtbgosngkxc |
||||
|
wrzhifdplumeqvajtsrosngkxc |
||||
|
wrzhyfdplumqqvajtaiosngkac |
||||
|
krzhyfvvlumeqvajtbiosngkxc |
||||
|
wrzhyfdplzmeqqajtbiosngkvc |
||||
|
wrzhyfqplumeqvajtbiosngdxy |
||||
|
wrzhyfdpluieqvajtbiosngjjc |
||||
|
wrzhyfdvlumeqrajdbiosngkxc |
||||
|
wrzhcfdpxumeqvajtbiotngkxc |
||||
|
wrzhyfdprumeqvaitbiosngexc |
||||
|
wrzhygdplumeqvpjtbiasngkxc |
||||
|
wrzhyndplumeqvajtpiosngkoc |
||||
|
wrzhyfdplumedvajtriowngkxc |
||||
|
wezjyndplumeqvajtbiosngkxc |
||||
|
wrmhyfdplumewiajtbiosngkxc |
||||
|
wrztyfdplumeqnajtbiobngkxc |
||||
|
wrzhyfdpyumeqvajjbijsngkxc |
||||
|
wrfhyfdplumeqkajtbiosnqkxc |
||||
|
wrzhyfdpllmezvartbiosngkxc |
||||
|
wszhyfdplumeqeajtbiqsngkxc |
||||
|
wrzhyfdplumeqwajtbnosnikxc |
||||
|
wrzvyfqulumeqvajtbiosngkxc |
||||
|
drzhyfdplureqvajtbiqsngkxc |
||||
|
wrzhyfdplumeqjamtbigsngkxc |
||||
|
wrzhyfdplumeqvajbbiosngzrc |
||||
|
grzhyfdpuumeqvajtbicsngkxc |
||||
|
wrrhyfdplumeqvajtgiosnggxc |
||||
|
wrzhyfkplumvqvajtbiosnhkxc |
||||
|
wrzhyfdplumeqvajtbicspgkxa |
||||
|
wrzhyfdplumeqvajtiiosnggoc |
||||
|
wfzhyfdplumyqvaytbiosngkxc |
||||
|
wrzhyfdpcumeqvajtbibsnfkxc |
||||
|
wrzhyfdplumeqvajtbigsnzkmc |
||||
|
wrzhyfdplcmeqvqjtriosngkxc |
||||
|
wrzhypdplwmeqvajtbiosnvkxc |
||||
|
wrziyfdmlumeqvaatbiosngkxc |
||||
|
wkzhyfdplsmeqvajobiosngkxc |
||||
|
wrzhyfdplumeqvkjvliosngkxc |
||||
|
wzzbyfdplumeqvajtbiolngkxc |
||||
|
wrzhyfdplvweqvajtbipsngkxc |
||||
|
wrzhyvdplumeqvujtbiosnfkxc |
||||
|
wrbhyfdplumedvajtbiosnhkxc |
||||
|
wrzhofdplumeqvajtbiosnskxy |
||||
|
wrzhyfdplumeqvaetbiohwgkxc |
||||
|
wezhyfoplumeqvajtbiosngmxc |
||||
|
wrzhykdblumeqvajtbiosngkjc |
||||
|
wrzhyddplwmeqvajtbioungkxc |
||||
|
wrzhyldplumqqvajpbiosngkxc |
||||
|
wrzhyfdtlumeqvajtbiusngkcc |
||||
|
wrzhyfdilumeqvajtbiosdgkxk |
||||
|
wrvhywdplumeqvajtbiosngoxc |
||||
|
wrzhyfdpyumeqvajtkiomngkxc |
||||
|
wrzhyfdpbummqvajtbiosngcxc |
||||
|
wrzhyfdpljmeqvajlbiosngjxc |
||||
|
wrzhyfdpmuieqdajtbiosngkxc |
||||
|
wrzgrfdplumeqvaktbiosngkxc |
||||
|
wrzhgrdpluueqvajtbiosngkxc |
||||
|
wazhyfdplhmeqvaqtbiosngkxc |
||||
|
wruhyfdplumeqvujtliosngkxc |
||||
|
wrzvyfdslumeqvajtbiwsngkxc |
||||
|
wrzhyfdplumeivactbiosqgkxc |
||||
|
wrzpyfdpbumeqvajtbioszgkxc |
||||
|
bgzhyfdplumeyvajtbiosngkxc |
||||
|
wrzhyfkplumeqvajtbiotngkxh |
||||
|
wrdhyfhplumexvajtbiosngkxc |
||||
|
brzhyfdpgumeqvgjtbiosngkxc |
||||
|
arzhqfdpeumeqvajtbiosngkxc |
||||
|
wrzhyftplumeqvajfbiosnykxc |
||||
|
wrzhyfdpcumeqvartbtosngkxc |
||||
|
wrzhvfzplumdqvajtbiosngkxc |
||||
|
wrzhyfdjlumeqvaetbiosjgkxc |
||||
|
wrbhyfdplumeqvajjjiosngkxc |
||||
|
wrxhyfdplumeqvajtbiyskgkxc |
||||
|
wpzhyydplumeqvajtbiosqgkxc |
||||
|
wrzhyfdplumzqvajtbzoongkxc |
||||
|
crzhyfdplnmeqvajtbjosngkxc |
||||
|
wrzhyfdpluveusajtbiosngkxc |
||||
|
wrzhypdpluyecvajtbiosngkxc |
||||
|
wrnhyfdplumeqvajtbioengoxc |
||||
|
wrzhypdplumefvajybiosngkxc |
||||
|
wrzhyfdplumeqvattviosngkdc |
||||
|
wrzhyfdplqmeqbajtbiostgkxc |
||||
|
wrghyfdpluveqvajtbiosngkxn |
||||
|
wryhyfdplumeqvajrbiopngkxc |
||||
|
wrzhyqdplumeqvajtbiwsngkxt |
||||
|
wrmoyfdpluheqvajtbiosngkxc |
||||
|
wrghyfdnlumeqvyjtbiosngkxc |
||||
|
wrzpyfdplumevvaatbiosngkxc |
||||
|
wrzhyfdplumhqvajtbiodngxxc |
||||
|
wrzhyfdplumeqcajtbioyjgkxc |
||||
|
wrzhyfdplumeqvajabirsngkgc |
||||
|
wrzhtfnplukeqvajtbiosngkxc |
||||
|
wqzhyfdplumeqvajtbiopegkxc |
||||
|
lrzhzfdplumeqdajtbiosngkxc |
||||
|
wrzzyfdplumeqvajnkiosngkxc |
||||
|
wrzhyfdflmmeqvajmbiosngkxc |
||||
|
wrzoyfdplumeqvjjtpiosngkxc |
||||
|
wrzhyfdpmpmeqvajhbiosngkxc |
||||
|
krvhyfdplumeqvajtbiossgkxc |
||||
|
wrzhyfdplumeqvaetviosnmkxc |
||||
|
wrzhyfzclumeqvajtbiosngwxc |
||||
|
wrzhyfdpvumeqvajtbiosngkcv |
||||
|
wrzhyfdpoumeqvajtbiozngoxc |
||||
|
wrzhyfwglumeqvajtbxosngkxc |
||||
|
wrshyfdplumeqiajtbiosngklc |
||||
|
wrzhyfdptdmeqvajtziosngkxc |
||||
|
wrwhyfdplumeqqajtbiosngkxj |
||||
|
wrzlyfypldmeqvajtbiosngkxc |
||||
|
wrzhyfdplumeqvajtbirknikxc |
||||
|
wrzhyhdplumeqvajtbmosnbkxc |
||||
|
wyzhyfiplumeqvwjtbiosngkxc |
||||
|
wrzgyfsplumeqvajtziosngkxc |
||||
|
wrzhrfdllumepvajtbiosngkxc |
||||
|
wrzayfdplumeqvajtbiosqgktc |
||||
|
whzhyfdplemnqvajtbiosngkxc |
||||
|
wazhyfdplumeqvaptbioongkxc |
||||
|
wrzhyfdpluueqvajtbiosnglvc |
||||
|
wrzhyfdplumjqvajmbionngkxc |
||||
|
wrzhofdplvmeqvajtbiosnqkxc |
||||
|
wrzhfidpluzeqvajtbiosngkxc |
||||
|
wrzhlfdpcumeqvaatbiosngkxc |
||||
|
wrzhyfdplumewvajtbiosigkoc |
||||
|
wrzjyfdplwmeqvajtbiodngkxc |
||||
|
wrzhyfdplumeqnsjtniosngkxc |
||||
|
wrzxyfdplxmeqvajtbiosngkdc |
||||
|
wrzhyfdplumpqvartbuosngkxc |
||||
|
orzhyfdplumeqzsjtbiosngkxc |
||||
|
wrzhyfdplumebvawtbiosngkxt |
||||
|
wrztyfdulumeqvajtbiosngkxy |
||||
|
wrzhytdplumeqvajtbznsngkxc |
||||
|
wrzhvfdplumeqvajtbinsngkxu |
||||
|
wezmyfdplumeqvajhbiosngkxc |
||||
|
wrzhhftplumeqvajtaiosngkxc |
||||
|
wrzhyfgplumeqvajtbioskgjxc |
||||
|
ujuhyfdplumeqvajtbiosngkxc |
||||
|
wryhymdplumeqvaftbiosngkxc |
||||
|
wrzhygdplumeqvajibiosfgkxc |
||||
|
frzhyfdppumeqvavtbiosngkxc |
||||
|
wruhyfdylumeqvajzbiosngkxc |
||||
|
wrzhzfdplumeqvajtbwosygkxc |
||||
|
wrzhyfdplumeqvaeteiojngkxc |
||||
|
wrhhyfdplumeqvajtiiopngkxc |
||||
|
irzhyfdplumeqvajtbiosngryc |
||||
|
wrvhycdpzumeqvajtbiosngkxc |
||||
|
wrzhyfdplumyqwajtboosngkxc |
||||
|
wrzthfdplumeqvajtbioengkxc |
||||
|
mrzhyfdalumeqvajtbiosngcxc |
||||
|
wrzhyfdflumpqvajtbiosngkmc |
||||
|
wrzhyfxplumeqvajtbiosnvkxo |
||||
|
wrzhyfdglumeqvajtbiosnfkxu |
||||
|
wrzhyfdnrumeqpajtbiosngkxc |
||||
|
wrzhlipplumeqvajtbiosngkxc |
||||
|
wrzhkfdplumemvajtbiohngkxc |
||||
|
wrziyfdmlumeqvaatbiosngkoc |
||||
|
wrzhyfdplwceqvajtbiosngzxc |
||||
|
wrzhyfdplumpqvactbiosngixc |
||||
|
wdzhyfdhdumeqvajtbiosngkxc |
||||
|
wnzhyfdplumeqvajtbbosngrxc |
||||
|
wrzhyfdblumeqvajtbiosngvxw |
||||
|
wyzhyfxpkumeqvajtbiosngkxc |
||||
|
wrzhywdplumjqvajgbiosngkxc |
||||
|
wrzhyfdpxumhqvajtbiokngkxc |
||||
|
wrzhxfpplumeqvajtbiosngkxk |
||||
|
mrzhyfdplumeqkajubiosngkxc |
||||
|
drzhyfdplumeqvajtbioingnxc |
||||
|
wrekyfdplumeqvajtbidsngkxc |
||||
|
wrzhyfdplumeanyjtbiosngkxc |
||||
|
wrzhyddpluzeqvajtbiosngtxc |
||||
|
wrzfyfdplumeqvaqtbiosngkxr |
||||
|
wrghywdpluneqvajtbiosngkxc |
||||
|
wrzhyfdplueeqvaptbioyngkxc |
||||
|
wrzhyqdpllmeqvajtbiosngdxc |
||||
|
whzhyfdxlumeqvajtbiosngksc |
||||
|
wrzjyfdplumeqvuitbiosngkxc |
||||
|
brzhyfdplumeqhajtbiolngkxc |
||||
|
wrzhyfqclureqvajtbiosngkxc |
||||
|
wwzhpfdplureqvajtbiosngkxc |
||||
|
wrzhyfdplumeqvavebijsngkxc |
||||
|
wrzhyfdpuumeqvajtsiosnkkxc |
||||
|
wrxhyfuplumeqvajtbiosngpxc |
||||
|
wrzhyfdplumeqvujlbiospgkxc |
||||
|
wrzvyfdplumeqvajtbiwsngpxc |
||||
|
wrzhyndplumeqvajtbiwsnekxc |
||||
|
wrzhkfdpoumeqvautbiosngkxc |
Binary file not shown.
@ -0,0 +1,57 @@ |
|||||
|
#include <stdlib.h> |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
int compare_char(const void *a, const void *b) |
||||
|
{ |
||||
|
return *(const char *)a - *(const char *)b; |
||||
|
} |
||||
|
|
||||
|
char find_reoccurrence(const char *array, const ssize_t len, const int times) |
||||
|
{ |
||||
|
if (!len) return 0; |
||||
|
if (!times) return 0; |
||||
|
|
||||
|
char current = *array; |
||||
|
int count = 0; |
||||
|
|
||||
|
for (const char *i = array; i < array + len; i++) { |
||||
|
if (*i == current) { |
||||
|
count++; |
||||
|
continue; |
||||
|
} |
||||
|
if (count == times) return current; |
||||
|
current = *i; |
||||
|
count = 1; |
||||
|
} |
||||
|
|
||||
|
return count == times ? current : 0; |
||||
|
} |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
char *line = NULL; |
||||
|
size_t line_len = 0; |
||||
|
ssize_t len = 0; |
||||
|
FILE *f = fopen("input", "r"); |
||||
|
if (!f) { |
||||
|
perror("input"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
int twice = 0; |
||||
|
int thrice = 0; |
||||
|
|
||||
|
while ((len = getline(&line, &line_len, f)) != -1) { |
||||
|
while (line[len - 1] == '\n') line[--len] = '\0'; |
||||
|
qsort(line, len, sizeof(char), compare_char); |
||||
|
|
||||
|
if (find_reoccurrence(line, len, 2)) twice++; |
||||
|
if (find_reoccurrence(line, len, 3)) thrice++; |
||||
|
} |
||||
|
|
||||
|
printf("%d\n", twice * thrice); |
||||
|
|
||||
|
free(line); |
||||
|
fclose(f); |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
CFLAGS := -Wall -Wextra -std=c17 -D_GNU_SOURCE |
||||
|
|
||||
|
LIBS := glib-2.0 |
||||
|
CFLAGS += $(shell pkg-config --cflags $(LIBS)) |
||||
|
LDLIBS := $(shell pkg-config --libs $(LIBS)) |
||||
|
|
||||
|
.PHONY: all |
||||
|
all: main |
||||
|
|
||||
|
.PHONY: clean |
||||
|
clean: |
||||
|
rm -f main |
@ -0,0 +1,250 @@ |
|||||
|
wkzhyfdpluzeqvajtbbosngkxc |
||||
|
wrzhyfdplumeqvajtbioskfksc |
||||
|
wrzhyfdolumyqvajtbiosngkxs |
||||
|
urzhyfdplbmeqvrjtbiosngkxc |
||||
|
wrzhyfrulumeqvajtbiosngkxf |
||||
|
wrzhnfdprumvqvajtbiosngkxc |
||||
|
wrzhyfpplumeivajtbiosrgkxc |
||||
|
wrzhybdplumeqvaftbiosxgkxc |
||||
|
wrzgyfdplumeqvaltbiosngcxc |
||||
|
wrzhbfdzlumeqvajtbipsngkxc |
||||
|
wrzhyfdplumwqeajtbiosngxxc |
||||
|
wrzhyddplumeqvajtbimsngkxo |
||||
|
wrzhyfdplumsqdajtfiosngkxc |
||||
|
wrzvyfdplumeqjajtbkosngkxc |
||||
|
wrzhyfddlumeqvujtbiosngxxc |
||||
|
nrzhywdplumeqvajtbtosngkxc |
||||
|
wzzhyfdplomeqvdjtbiosngkxc |
||||
|
urzhyfdplumeqvaatbiosngkxb |
||||
|
wtzyyfdplumeqvajtbiosngkxl |
||||
|
wrzhyfdhlumnqvajebiosngkxc |
||||
|
wrzhyfdplumpqvajtbiosnyjxc |
||||
|
wrzdyfdplumeqvajtviospgkxc |
||||
|
wrzhyfdplzmeqvajtbiosegfxc |
||||
|
wrzhyfdglumkqvajtwiosngkxc |
||||
|
wrzhtfdplgmeqvaqtbiosngkxc |
||||
|
wrzhyfdplumeqvajxpiosngexc |
||||
|
frzhyfdplvmeqvajtbiosngkxp |
||||
|
wrzhyfkplumeqvajtbfosngkpc |
||||
|
irzhyfqplumeqvajtbiosngktc |
||||
|
wrzhyfdpluvoqvajtbioingkxc |
||||
|
wrzhyfdplumemvautbuosngkxc |
||||
|
wfzhyflplumeqvijtbiosngkxc |
||||
|
wrzhyfdglumeqvzjkbiosngkxc |
||||
|
wrzcyfdplaneqvajtbiosngkxc |
||||
|
wrzhbfdplumeqwajtbiosngpxc |
||||
|
szdhyfdplumeqvajtbiosngkxc |
||||
|
krzhyfdplumeqvajtxilsngkxc |
||||
|
brzhyfmplumexvajtbiosngkxc |
||||
|
wrzhyvdplumeqvajtbiosiglxc |
||||
|
orzhyfdplumeqvaotbcosngkxc |
||||
|
hrzhyfdplumeqvaptbiocngkxc |
||||
|
wwzhyfdklummqvajtbiosngkxc |
||||
|
wrzhyfdppymeqvvjtbiosngkxc |
||||
|
wsehyudplumeqvajtbiosngkxc |
||||
|
wrzhyzpplumeqvajtbioscgkxc |
||||
|
wrzhyfqpyumeqvajtbiusngkxc |
||||
|
urzhyfdpdumeqmajtbiosngkxc |
||||
|
wrzhyfdrlumxqvajtbiosnakxc |
||||
|
wrthyfdplumeskajtbiosngkxc |
||||
|
wrzhyfdplymeqvajtbiesbgkxc |
||||
|
wrzhyfdqlumeqyajtciosngkxc |
||||
|
trzhsfdplumeqyajtbiosngkxc |
||||
|
wpzhyfdplimeqvajtbiosngfxc |
||||
|
wrzhhfdplrmeqvajtbiosngkxx |
||||
|
wrzhycdpgumeqvajtbioslgkxc |
||||
|
wrzhyfdelumeqvajgtiosngkxc |
||||
|
wrzhyfdplutebvajtbiosygkxc |
||||
|
wrzhyfdplukeqvajtbiorngkec |
||||
|
erzhyfdilumeqvajwbiosngkxc |
||||
|
wrzhyfdplumnivxjtbiosngkxc |
||||
|
wrzhyfdplumebvajtoiovngkxc |
||||
|
wrzhyfdplumeqvajtbtosnwkxe |
||||
|
wrzhyfxplumevvajtciosngkxc |
||||
|
wbzhyfdxlumeqvajtriosngkxc |
||||
|
wrzyyfdplumeqvajmbiosngkxb |
||||
|
wfthyfdplumeqvajtbiosngkdc |
||||
|
wrzhuedplumeqvajtbgosngkxc |
||||
|
wrzhifdplumeqvajtsrosngkxc |
||||
|
wrzhyfdplumqqvajtaiosngkac |
||||
|
krzhyfvvlumeqvajtbiosngkxc |
||||
|
wrzhyfdplzmeqqajtbiosngkvc |
||||
|
wrzhyfqplumeqvajtbiosngdxy |
||||
|
wrzhyfdpluieqvajtbiosngjjc |
||||
|
wrzhyfdvlumeqrajdbiosngkxc |
||||
|
wrzhcfdpxumeqvajtbiotngkxc |
||||
|
wrzhyfdprumeqvaitbiosngexc |
||||
|
wrzhygdplumeqvpjtbiasngkxc |
||||
|
wrzhyndplumeqvajtpiosngkoc |
||||
|
wrzhyfdplumedvajtriowngkxc |
||||
|
wezjyndplumeqvajtbiosngkxc |
||||
|
wrmhyfdplumewiajtbiosngkxc |
||||
|
wrztyfdplumeqnajtbiobngkxc |
||||
|
wrzhyfdpyumeqvajjbijsngkxc |
||||
|
wrfhyfdplumeqkajtbiosnqkxc |
||||
|
wrzhyfdpllmezvartbiosngkxc |
||||
|
wszhyfdplumeqeajtbiqsngkxc |
||||
|
wrzhyfdplumeqwajtbnosnikxc |
||||
|
wrzvyfqulumeqvajtbiosngkxc |
||||
|
drzhyfdplureqvajtbiqsngkxc |
||||
|
wrzhyfdplumeqjamtbigsngkxc |
||||
|
wrzhyfdplumeqvajbbiosngzrc |
||||
|
grzhyfdpuumeqvajtbicsngkxc |
||||
|
wrrhyfdplumeqvajtgiosnggxc |
||||
|
wrzhyfkplumvqvajtbiosnhkxc |
||||
|
wrzhyfdplumeqvajtbicspgkxa |
||||
|
wrzhyfdplumeqvajtiiosnggoc |
||||
|
wfzhyfdplumyqvaytbiosngkxc |
||||
|
wrzhyfdpcumeqvajtbibsnfkxc |
||||
|
wrzhyfdplumeqvajtbigsnzkmc |
||||
|
wrzhyfdplcmeqvqjtriosngkxc |
||||
|
wrzhypdplwmeqvajtbiosnvkxc |
||||
|
wrziyfdmlumeqvaatbiosngkxc |
||||
|
wkzhyfdplsmeqvajobiosngkxc |
||||
|
wrzhyfdplumeqvkjvliosngkxc |
||||
|
wzzbyfdplumeqvajtbiolngkxc |
||||
|
wrzhyfdplvweqvajtbipsngkxc |
||||
|
wrzhyvdplumeqvujtbiosnfkxc |
||||
|
wrbhyfdplumedvajtbiosnhkxc |
||||
|
wrzhofdplumeqvajtbiosnskxy |
||||
|
wrzhyfdplumeqvaetbiohwgkxc |
||||
|
wezhyfoplumeqvajtbiosngmxc |
||||
|
wrzhykdblumeqvajtbiosngkjc |
||||
|
wrzhyddplwmeqvajtbioungkxc |
||||
|
wrzhyldplumqqvajpbiosngkxc |
||||
|
wrzhyfdtlumeqvajtbiusngkcc |
||||
|
wrzhyfdilumeqvajtbiosdgkxk |
||||
|
wrvhywdplumeqvajtbiosngoxc |
||||
|
wrzhyfdpyumeqvajtkiomngkxc |
||||
|
wrzhyfdpbummqvajtbiosngcxc |
||||
|
wrzhyfdpljmeqvajlbiosngjxc |
||||
|
wrzhyfdpmuieqdajtbiosngkxc |
||||
|
wrzgrfdplumeqvaktbiosngkxc |
||||
|
wrzhgrdpluueqvajtbiosngkxc |
||||
|
wazhyfdplhmeqvaqtbiosngkxc |
||||
|
wruhyfdplumeqvujtliosngkxc |
||||
|
wrzvyfdslumeqvajtbiwsngkxc |
||||
|
wrzhyfdplumeivactbiosqgkxc |
||||
|
wrzpyfdpbumeqvajtbioszgkxc |
||||
|
bgzhyfdplumeyvajtbiosngkxc |
||||
|
wrzhyfkplumeqvajtbiotngkxh |
||||
|
wrdhyfhplumexvajtbiosngkxc |
||||
|
brzhyfdpgumeqvgjtbiosngkxc |
||||
|
arzhqfdpeumeqvajtbiosngkxc |
||||
|
wrzhyftplumeqvajfbiosnykxc |
||||
|
wrzhyfdpcumeqvartbtosngkxc |
||||
|
wrzhvfzplumdqvajtbiosngkxc |
||||
|
wrzhyfdjlumeqvaetbiosjgkxc |
||||
|
wrbhyfdplumeqvajjjiosngkxc |
||||
|
wrxhyfdplumeqvajtbiyskgkxc |
||||
|
wpzhyydplumeqvajtbiosqgkxc |
||||
|
wrzhyfdplumzqvajtbzoongkxc |
||||
|
crzhyfdplnmeqvajtbjosngkxc |
||||
|
wrzhyfdpluveusajtbiosngkxc |
||||
|
wrzhypdpluyecvajtbiosngkxc |
||||
|
wrnhyfdplumeqvajtbioengoxc |
||||
|
wrzhypdplumefvajybiosngkxc |
||||
|
wrzhyfdplumeqvattviosngkdc |
||||
|
wrzhyfdplqmeqbajtbiostgkxc |
||||
|
wrghyfdpluveqvajtbiosngkxn |
||||
|
wryhyfdplumeqvajrbiopngkxc |
||||
|
wrzhyqdplumeqvajtbiwsngkxt |
||||
|
wrmoyfdpluheqvajtbiosngkxc |
||||
|
wrghyfdnlumeqvyjtbiosngkxc |
||||
|
wrzpyfdplumevvaatbiosngkxc |
||||
|
wrzhyfdplumhqvajtbiodngxxc |
||||
|
wrzhyfdplumeqcajtbioyjgkxc |
||||
|
wrzhyfdplumeqvajabirsngkgc |
||||
|
wrzhtfnplukeqvajtbiosngkxc |
||||
|
wqzhyfdplumeqvajtbiopegkxc |
||||
|
lrzhzfdplumeqdajtbiosngkxc |
||||
|
wrzzyfdplumeqvajnkiosngkxc |
||||
|
wrzhyfdflmmeqvajmbiosngkxc |
||||
|
wrzoyfdplumeqvjjtpiosngkxc |
||||
|
wrzhyfdpmpmeqvajhbiosngkxc |
||||
|
krvhyfdplumeqvajtbiossgkxc |
||||
|
wrzhyfdplumeqvaetviosnmkxc |
||||
|
wrzhyfzclumeqvajtbiosngwxc |
||||
|
wrzhyfdpvumeqvajtbiosngkcv |
||||
|
wrzhyfdpoumeqvajtbiozngoxc |
||||
|
wrzhyfwglumeqvajtbxosngkxc |
||||
|
wrshyfdplumeqiajtbiosngklc |
||||
|
wrzhyfdptdmeqvajtziosngkxc |
||||
|
wrwhyfdplumeqqajtbiosngkxj |
||||
|
wrzlyfypldmeqvajtbiosngkxc |
||||
|
wrzhyfdplumeqvajtbirknikxc |
||||
|
wrzhyhdplumeqvajtbmosnbkxc |
||||
|
wyzhyfiplumeqvwjtbiosngkxc |
||||
|
wrzgyfsplumeqvajtziosngkxc |
||||
|
wrzhrfdllumepvajtbiosngkxc |
||||
|
wrzayfdplumeqvajtbiosqgktc |
||||
|
whzhyfdplemnqvajtbiosngkxc |
||||
|
wazhyfdplumeqvaptbioongkxc |
||||
|
wrzhyfdpluueqvajtbiosnglvc |
||||
|
wrzhyfdplumjqvajmbionngkxc |
||||
|
wrzhofdplvmeqvajtbiosnqkxc |
||||
|
wrzhfidpluzeqvajtbiosngkxc |
||||
|
wrzhlfdpcumeqvaatbiosngkxc |
||||
|
wrzhyfdplumewvajtbiosigkoc |
||||
|
wrzjyfdplwmeqvajtbiodngkxc |
||||
|
wrzhyfdplumeqnsjtniosngkxc |
||||
|
wrzxyfdplxmeqvajtbiosngkdc |
||||
|
wrzhyfdplumpqvartbuosngkxc |
||||
|
orzhyfdplumeqzsjtbiosngkxc |
||||
|
wrzhyfdplumebvawtbiosngkxt |
||||
|
wrztyfdulumeqvajtbiosngkxy |
||||
|
wrzhytdplumeqvajtbznsngkxc |
||||
|
wrzhvfdplumeqvajtbinsngkxu |
||||
|
wezmyfdplumeqvajhbiosngkxc |
||||
|
wrzhhftplumeqvajtaiosngkxc |
||||
|
wrzhyfgplumeqvajtbioskgjxc |
||||
|
ujuhyfdplumeqvajtbiosngkxc |
||||
|
wryhymdplumeqvaftbiosngkxc |
||||
|
wrzhygdplumeqvajibiosfgkxc |
||||
|
frzhyfdppumeqvavtbiosngkxc |
||||
|
wruhyfdylumeqvajzbiosngkxc |
||||
|
wrzhzfdplumeqvajtbwosygkxc |
||||
|
wrzhyfdplumeqvaeteiojngkxc |
||||
|
wrhhyfdplumeqvajtiiopngkxc |
||||
|
irzhyfdplumeqvajtbiosngryc |
||||
|
wrvhycdpzumeqvajtbiosngkxc |
||||
|
wrzhyfdplumyqwajtboosngkxc |
||||
|
wrzthfdplumeqvajtbioengkxc |
||||
|
mrzhyfdalumeqvajtbiosngcxc |
||||
|
wrzhyfdflumpqvajtbiosngkmc |
||||
|
wrzhyfxplumeqvajtbiosnvkxo |
||||
|
wrzhyfdglumeqvajtbiosnfkxu |
||||
|
wrzhyfdnrumeqpajtbiosngkxc |
||||
|
wrzhlipplumeqvajtbiosngkxc |
||||
|
wrzhkfdplumemvajtbiohngkxc |
||||
|
wrziyfdmlumeqvaatbiosngkoc |
||||
|
wrzhyfdplwceqvajtbiosngzxc |
||||
|
wrzhyfdplumpqvactbiosngixc |
||||
|
wdzhyfdhdumeqvajtbiosngkxc |
||||
|
wnzhyfdplumeqvajtbbosngrxc |
||||
|
wrzhyfdblumeqvajtbiosngvxw |
||||
|
wyzhyfxpkumeqvajtbiosngkxc |
||||
|
wrzhywdplumjqvajgbiosngkxc |
||||
|
wrzhyfdpxumhqvajtbiokngkxc |
||||
|
wrzhxfpplumeqvajtbiosngkxk |
||||
|
mrzhyfdplumeqkajubiosngkxc |
||||
|
drzhyfdplumeqvajtbioingnxc |
||||
|
wrekyfdplumeqvajtbidsngkxc |
||||
|
wrzhyfdplumeanyjtbiosngkxc |
||||
|
wrzhyddpluzeqvajtbiosngtxc |
||||
|
wrzfyfdplumeqvaqtbiosngkxr |
||||
|
wrghywdpluneqvajtbiosngkxc |
||||
|
wrzhyfdplueeqvaptbioyngkxc |
||||
|
wrzhyqdpllmeqvajtbiosngdxc |
||||
|
whzhyfdxlumeqvajtbiosngksc |
||||
|
wrzjyfdplumeqvuitbiosngkxc |
||||
|
brzhyfdplumeqhajtbiolngkxc |
||||
|
wrzhyfqclureqvajtbiosngkxc |
||||
|
wwzhpfdplureqvajtbiosngkxc |
||||
|
wrzhyfdplumeqvavebijsngkxc |
||||
|
wrzhyfdpuumeqvajtsiosnkkxc |
||||
|
wrxhyfuplumeqvajtbiosngpxc |
||||
|
wrzhyfdplumeqvujlbiospgkxc |
||||
|
wrzvyfdplumeqvajtbiwsngpxc |
||||
|
wrzhyndplumeqvajtbiwsnekxc |
||||
|
wrzhkfdpoumeqvautbiosngkxc |
Binary file not shown.
@ -0,0 +1,68 @@ |
|||||
|
#include <stdio.h> |
||||
|
|
||||
|
#include <glib.h> |
||||
|
|
||||
|
int strcmpmatch(const char *a, const char *b) |
||||
|
{ |
||||
|
int result = 0; |
||||
|
while (*a && *b) if (*a++ == *b++) result++; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
void stripnoncommon(char *a, const char *b) |
||||
|
{ |
||||
|
while (*a && *b) { |
||||
|
if (*a++ != *b++) { |
||||
|
memmove(a - 1, a, strlen(a)); |
||||
|
a--; |
||||
|
} |
||||
|
} |
||||
|
*a = '\0'; |
||||
|
} |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
gchar *contents; |
||||
|
gchar **strings; |
||||
|
GError *err = NULL; |
||||
|
|
||||
|
g_file_get_contents("input", &contents, NULL, &err); |
||||
|
if (err) { |
||||
|
fprintf(stderr, "%s\n", err->message); |
||||
|
g_error_free(err); |
||||
|
return 1; |
||||
|
} |
||||
|
g_strstrip(contents); |
||||
|
strings = g_strsplit(contents, "\n", -1); |
||||
|
g_free(contents); |
||||
|
|
||||
|
int bestmatch_len = 0; |
||||
|
char *bestmatch_1 = NULL; |
||||
|
char *bestmatch_2 = NULL; |
||||
|
|
||||
|
for (char **first = strings; *first; first++) { |
||||
|
for (char **second = strings; *second; second++) { |
||||
|
if (first == second) continue; |
||||
|
|
||||
|
int len = strcmpmatch(*first, *second); |
||||
|
if (len <= bestmatch_len) continue; |
||||
|
bestmatch_1 = *first; |
||||
|
bestmatch_2 = *second; |
||||
|
bestmatch_len = len; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!bestmatch_1 || !bestmatch_2) { |
||||
|
puts("No match found!"); |
||||
|
goto end; |
||||
|
} |
||||
|
|
||||
|
char *final = g_strdup(bestmatch_1); |
||||
|
stripnoncommon(final, bestmatch_2); |
||||
|
puts(final); |
||||
|
g_free(final); |
||||
|
|
||||
|
end: |
||||
|
g_strfreev(strings); |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
CFLAGS := -Wall -Wextra -std=c17 -D_GNU_SOURCE |
||||
|
|
||||
|
LIBS := glib-2.0 |
||||
|
CFLAGS += $(shell pkg-config --cflags $(LIBS)) |
||||
|
LDLIBS := $(shell pkg-config --libs $(LIBS)) |
||||
|
|
||||
|
.PHONY: all |
||||
|
all: main |
||||
|
|
||||
|
.PHONY: clean |
||||
|
clean: |
||||
|
rm -f main |
File diff suppressed because it is too large
Binary file not shown.
@ -0,0 +1,92 @@ |
|||||
|
#include <stdio.h> |
||||
|
|
||||
|
#include <glib.h> |
||||
|
|
||||
|
struct claim { |
||||
|
unsigned id; |
||||
|
unsigned x; |
||||
|
unsigned y; |
||||
|
unsigned w; |
||||
|
unsigned h; |
||||
|
}; |
||||
|
|
||||
|
struct claim *parseclaims(unsigned *len, const char *fname) |
||||
|
{ |
||||
|
FILE *f = fopen(fname, "r"); |
||||
|
if (!f) { |
||||
|
perror(fname); |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
GArray *array = g_array_new(FALSE, FALSE, sizeof(struct claim)); |
||||
|
*len = 0; |
||||
|
|
||||
|
char *line = NULL; |
||||
|
size_t line_len = 0; |
||||
|
while (getline(&line, &line_len, f) != -1) { |
||||
|
struct claim claim = {0}; |
||||
|
|
||||
|
// Haha what is proper parsing
|
||||
|
sscanf(line, "#%u @ %u,%u: %ux%u", |
||||
|
&claim.id, |
||||
|
&claim.x, |
||||
|
&claim.y, |
||||
|
&claim.w, |
||||
|
&claim.h |
||||
|
); |
||||
|
|
||||
|
g_array_append_val(array, claim); |
||||
|
(*len)++; |
||||
|
} |
||||
|
|
||||
|
free(line); |
||||
|
fclose(f); |
||||
|
struct claim *res = (struct claim *)g_array_free(array, FALSE); |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
unsigned claims_len; |
||||
|
struct claim *claims = parseclaims(&claims_len, "input"); |
||||
|
if (!claims) return 1; |
||||
|
|
||||
|
char (*tilemap)[1000] = g_malloc0(sizeof(char[1000][1000])); |
||||
|
|
||||
|
for (struct claim *claim = claims; |
||||
|
claim < claims + claims_len; claim++) { |
||||
|
// Basic sanity check
|
||||
|
if (claim->y > 1000 || |
||||
|
claim->y + claim->h > 1000 || |
||||
|
claim->x > 1000 || |
||||
|
claim->x + claim->w > 1000) { |
||||
|
fprintf(stderr, "Warning: Ignoring out-of-bounds claim: " |
||||
|
"#%u @ %u,%u: %ux%u\n", |
||||
|
claim->id, |
||||
|
claim->x, |
||||
|
claim->y, |
||||
|
claim->w, |
||||
|
claim->h |
||||
|
); |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
for (unsigned y = claim->y; y < claim->y + claim->h; y++) { |
||||
|
for (unsigned x = claim->x; x < claim->x + claim->w; x++) { |
||||
|
if (tilemap[y][x] >= 2) continue; |
||||
|
tilemap[y][x]++; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int tally = 0; |
||||
|
for (char *i = *tilemap; i < *tilemap + 1000 * 1000; i++) { |
||||
|
if (*i >= 2) tally++; |
||||
|
} |
||||
|
|
||||
|
printf("%d\n", tally); |
||||
|
|
||||
|
g_free(claims); |
||||
|
g_free(tilemap); |
||||
|
return 0; |
||||
|
} |
Loading…
Reference in new issue