Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
5
2021/day01/day01.bqn
Normal file
5
2021/day01/day01.bqn
Normal file
|
@ -0,0 +1,5 @@
|
|||
a←•BQN¨•Flines"input"
|
||||
# Fn←{+´(¯1⊸↓<1⊸↓)+˝˘ 𝕨↕𝕩}
|
||||
Fn←{+´0>𝕨↓⌽𝕩-𝕨⌽𝕩}
|
||||
•Show 1 Fn a # part 1
|
||||
•Show 3 Fn a # part 2
|
23
2021/day01/day01.c
Normal file
23
2021/day01/day01.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int buf[5000] = {0};
|
||||
int count = 0;
|
||||
while (scanf("%d\n", &buf[count++]) != EOF);
|
||||
count--;
|
||||
|
||||
int part1 = 0;
|
||||
for (int i = 1; i < count; ++i) {
|
||||
part1 += buf[i] > buf[i - 1];
|
||||
}
|
||||
printf("%d\n", part1);
|
||||
|
||||
int part2 = 0;
|
||||
for (int i = 3; i < count; ++i) {
|
||||
part2 += buf[i] > buf[i-3];
|
||||
}
|
||||
printf("%d\n", part2);
|
||||
|
||||
return 0;
|
||||
}
|
13
2021/day01/day01.scm
Normal file
13
2021/day01/day01.scm
Normal file
|
@ -0,0 +1,13 @@
|
|||
(import (chicken io) srfi-1)
|
||||
|
||||
(define (read-input #!optional (port (current-input-port)))
|
||||
(map string->number
|
||||
(read-lines port)))
|
||||
|
||||
(define (part1 l) (count < l (cdr l)))
|
||||
|
||||
(define (part2 l) (count < l (cdddr l)))
|
||||
|
||||
(let ((in (read-input)))
|
||||
(print (part1 in))
|
||||
(print (part2 in)))
|
7
2021/day01/day01_golf.c
Normal file
7
2021/day01/day01_golf.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
b[5000],p,q,n,i;
|
||||
main(){
|
||||
for(;~scanf("%d",b+n++););
|
||||
for(i=n-2;i--;)p+=b[i+1]>b[i];
|
||||
for(i=n-4;i--;)q+=b[i+3]>b[i];
|
||||
printf("%d %d",p,q);
|
||||
}
|
25
2021/day01/day01_r7rs.scm
Normal file
25
2021/day01/day01_r7rs.scm
Normal file
|
@ -0,0 +1,25 @@
|
|||
(cond-expand
|
||||
(r7rs)
|
||||
(chicken (import r7rs)))
|
||||
|
||||
(import (scheme base)
|
||||
(scheme write)
|
||||
(scheme cxr)
|
||||
(srfi 1))
|
||||
|
||||
(define (read-input)
|
||||
(let lp ((lines '()))
|
||||
(if (and (not (null? lines)) (eof-object? (car lines)))
|
||||
(map string->number (reverse (cdr lines)))
|
||||
(lp (cons (read-line (current-input-port)) lines)))))
|
||||
|
||||
(define (part1 l) (count < l (cdr l)))
|
||||
|
||||
(define (part2 l) (count < l (cdddr l)))
|
||||
|
||||
(let ((in (read-input)))
|
||||
(write (part1 in))
|
||||
(newline)
|
||||
(write (part2 in))
|
||||
(newline))
|
||||
|
2000
2021/day01/input
Normal file
2000
2021/day01/input
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue