gitifyed
This commit is contained in:
10
AoC/2022/7/1.py
Executable file
10
AoC/2022/7/1.py
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/python
|
||||
|
||||
"""
|
||||
Description:
|
||||
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1000
AoC/2023/trebuchet/input.in
Normal file
1000
AoC/2023/trebuchet/input.in
Normal file
File diff suppressed because it is too large
Load Diff
28
AoC/2023/trebuchet/trebuchet.c
Normal file
28
AoC/2023/trebuchet/trebuchet.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
char c;
|
||||
int sum = 0;
|
||||
int first = -1, last = -1;
|
||||
while ((c = getchar()) != EOF) {
|
||||
|
||||
if (c == '\n') {
|
||||
sum += last != -1 ? first*10 + last : first*10 + first;
|
||||
first = -1;
|
||||
last = -1;
|
||||
} else {
|
||||
if (c <= '9' && c >= '0') {
|
||||
if (first == -1) {
|
||||
first = c - '0';
|
||||
} else {
|
||||
last = c - '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d\n", sum);
|
||||
|
||||
return 0;
|
||||
}
|
32
AoC/2023/trebuchet/trebuchet.py
Normal file
32
AoC/2023/trebuchet/trebuchet.py
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
def findFirstAndLastInt(inp):
|
||||
first = 0
|
||||
last = 0
|
||||
for i in inp:
|
||||
if i.isdigit():
|
||||
if first == 0:
|
||||
first = i
|
||||
else:
|
||||
last = i
|
||||
if last == 0:
|
||||
last = first
|
||||
|
||||
return int(first), int(last)
|
||||
|
||||
|
||||
def main():
|
||||
inputs = []
|
||||
with open("input.in", "r") as f:
|
||||
for line in f:
|
||||
inputs.append(line.strip())
|
||||
|
||||
s = 0
|
||||
for inp in inputs:
|
||||
first, last = findFirstAndLastInt(inp)
|
||||
s += first*10 + last
|
||||
|
||||
print(s)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user