import Data.Char
import Data.List
prio c | c >= 'a' = ord c - ord 'a' + 1 | otherwise = ord c - ord 'A' + 27
slice (x:y:z:xs) = (x,y,z) : slice xs
slice [] = []
main = do
ls <- readFile "day03.in"
-- Part 1
print $ sum . map (\l -> (prio . head . uncurry intersect) $ splitAt (length l `div` 2) l) $ lines ls
-- Part 2
print $ sum . map (\(x,y,z) -> prio $ head $ intersect x (intersect y z)) $ slice $ lines ls
using namespace std
, you don't need to qualify things with std::
anymoreusing namespace std
using namespace std
using namespace std
, then you'll write std::
everywhere#!/bin/bash
# Advent of Code 03 / PART 1
while read -r l; do
p1+=( "${l:0:${#l}/2}" )
p2+=( "${l:${#l}/2}" )
done < "$1"
for i in $(seq 1 ${#p1[@]}); do
a=$(echo ${p1[i-1]} | sed "s/./&\n/g" | sort)
b=$(echo ${p2[i-1]} | sed "s/./&\n/g" | sort)
r=$(comm -12 <(echo $a | tr ' ' '\n') <(echo $b | tr ' ' '\n') | uniq)
n=$(echo -n "$r" | od -An -tuC)
[[ $r =~ [a-z] ]] && n=$((n - 96))
[[ $r =~ [A-Z] ]] && n=$((n - 38))
echo $n
done | paste -s -d+ | bc
(edited)ans = [0, 0]
for line in open('i.input', 'r').readlines():
if (int(line.strip().split(',')[0].split('-')[0])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[1])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[0])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[1])<=int(line.strip().split(',')[0].split('-')[1])):
ans[0] += 1
if (int(line.strip().split(',')[0].split('-')[0])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[0])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[0].split('-')[1])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[1])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[0])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[0])<=int(line.strip().split(',')[0].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[1])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[1])<=int(line.strip().split(',')[0].split('-')[1])):
ans[1] += 1
print(ans)
using namespace std
, then you'll write std::
everywhere std::
cuz too used to itmap eval $ map head $ map intersect $ map half
can be rewritten to map (eval . head . intersect . half)
chunksOf
, even tried the great Hoogle signature search: https://hoogle.haskell.org/
It's usually easier in Haskell to write down the signature of a function you want than to describe what it should do #!/bin/bash
# Advent of Code 03 / PART 1
while read -r l; do
p1+=( "${l:0:${#l}/2}" )
p2+=( "${l:${#l}/2}" )
done < "$1"
for i in $(seq 1 ${#p1[@]}); do
a=$(echo ${p1[i-1]} | sed "s/./&\n/g" | sort)
b=$(echo ${p2[i-1]} | sed "s/./&\n/g" | sort)
r=$(comm -12 <(echo $a | tr ' ' '\n') <(echo $b | tr ' ' '\n') | uniq)
n=$(echo -n "$r" | od -An -tuC)
[[ $r =~ [a-z] ]] && n=$((n - 96))
[[ $r =~ [A-Z] ]] && n=$((n - 38))
echo $n
done | paste -s -d+ | bc
(edited)ans = [0, 0]
for line in open('i.input', 'r').readlines():
if (int(line.strip().split(',')[0].split('-')[0])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[1])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[0])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[1])<=int(line.strip().split(',')[0].split('-')[1])):
ans[0] += 1
if (int(line.strip().split(',')[0].split('-')[0])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[0])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[0].split('-')[1])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[1])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[0])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[0])<=int(line.strip().split(',')[0].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[1])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[1])<=int(line.strip().split(',')[0].split('-')[1])):
ans[1] += 1
print(ans)
-g
Now it should in worst case only overwrite custom settings by the user. but dunno how often u actually do that anyway inside a IDE
but if someone knows better I'm glad to hear it
ans = [0, 0]
for line in open('i.input', 'r').readlines():
if (int(line.strip().split(',')[0].split('-')[0])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[1])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[0])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[1])<=int(line.strip().split(',')[0].split('-')[1])):
ans[0] += 1
if (int(line.strip().split(',')[0].split('-')[0])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[0])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[0].split('-')[1])>=int(line.strip().split(',')[1].split('-')[0]) and int(line.strip().split(',')[0].split('-')[1])<=int(line.strip().split(',')[1].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[0])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[0])<=int(line.strip().split(',')[0].split('-')[1])) or (int(line.strip().split(',')[1].split('-')[1])>=int(line.strip().split(',')[0].split('-')[0]) and int(line.strip().split(',')[1].split('-')[1])<=int(line.strip().split(',')[0].split('-')[1])):
ans[1] += 1
print(ans)
if (0 < y % (4 * (4 + 2) + 1)) {
y = y % 4;
}
return y % (4 * 4) < 1;
if (y % 25 != 0) { y %= 4 }; return y % 16 == 0;
(edited)y % 16 == 0
if (y % 25 != 0) { y %= 4 }; return y % 16 == 0;
(edited)return y % (y % 25 < 1 ? 16 : 4) < 1;
return y % ((y % 25 < 1) * 12 + 4) < 1;
return y % (y % 25 < 1 ? 16 : 4) < 1;
return y % ((y % 25 < 1) * 12 + 4) < 1;
1 * 12
c++
#include <stdio.h>
#define n int
n main(){for(n m=1800;m<=2400;++m)if(m%(m%25?4:16)<1)printf("%d\n",m);}
i bet u can somehow use macros and compress ur code in itself, but im too stupid for it xdc++
#include <stdio.h>
#define n int
n main(){for(n m=1800;m<=2400;++m)if(m%(m%25?4:16)<1)printf("%d\n",m);}
i bet u can somehow use macros and compress ur code in itself, but im too stupid for it xd int
if not specified. Also m<=2400
--> m<2401
would save one character.c++
#include <stdio.h>
#define n int
n main(){for(n m=1800;m<=2400;++m)if(m%(m%25?4:16)<1)printf("%d\n",m);}
i bet u can somehow use macros and compress ur code in itself, but im too stupid for it xd #include <stdio.h>
main(){for(int m=1800;m<2401;++m)m%(m%25?4:16)<1?printf("%d\n",m):0;}
(edited)#include <stdio.h>
?#include<cstdio>
int main(){for(int m=1800;m<2401;++m)m%(m%25?4:16)<1?printf("%d\n",m):0;}
90 characters for a C++ version (edited)?0:print(…)
<1
(edited)#include<cstdio>
int main(){for(int m=1800;m<2401;++m)!m%(m%25?4:16)?0:printf("%d\n",m);}
!
#include<cstdio>
int main(){for(int m=1800;m<2401;++m)m%(m%25?4:16)?0:printf("%d\n",m);}
c++
#include<cstdio>
int main(){for(int m=1800;m<2401;m+=4)m%16<1|m%25?printf("%d\n",m):0;}
c++
#include<cstdio>
int main(){for(int m=1800;m<2401;m+=4)m%16<1|m%25?printf("%d\n",m):0;}
|
__|__
|/___\|
|___|_|
_|___|_|_
|___|___|_|
|___|___|_|
|___|___|_|
|___|___|
|___|___|
|___|_|
\___/
,[------------------------------------------------[->>>>>>+<<<<<<]>,------------
---------------------------------[--->>>>>[-<<<<++++++++++>>>>]<<<<<[->+<],[-]]>
>>>>[-<<<<+>>>>]<<<<<<,------------------------------------------------[->>>>>>+
<<<<<<]>,--------------------------------------------[---->>>>>[-<<<++++++++++>>
>]<<<<<[->>+<<],[-]]>>>>>[-<<<+>>>]<<<<<<,--------------------------------------
----------[->>>>>>+<<<<<<]>,---------------------------------------------[--->>>
>>[-<<++++++++++>>]<<<<<[->>>+<<<],[-]]>>>>>[-<<+>>]<<<<<<,---------------------
---------------------------[->>>>>>+<<<<<<]>,----------[------------------------
-------------->>>>>[-<++++++++++>]<<<<<[->>>>+<<<<],[-]]>>>>>[-<+>]>+<<<<<[->>>>
>>>+<<<<<<<]>>[->>>>>>+<<<<<<]>>>>>[->-[>]<<]<[->>>>>>+<<<<[[-]>>>>[-]<<<<<<<<<<
[->+<]>>[-<<+>>]<<<<+>>[->-[>]<<]<[->>>>>>>>>>>+<<<<<<<<<<<]<[-<]>>>>>>]>>>>[-<+
<<]<<<]<[-<<[-<+>]<<<<+>>[->-[>]<<]<[->>>>>>>>>>>+<<<<<<<<<<<]<[-<]>>>>>>]>>>>>[
-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-],]>>>>>>>>>>>>>>++++++++++<<[[->+>
-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>>>>[>]++++++++++++++++++++++++++++++++++++++++++
++++++[<]<<<[-<+>>>>>[>]<+[<]<<<]>[-<<<<+>>>>]<<<[-]<]>>>>>>>[>]<[.<]++++++++++.
,[------------------------------------------------[->>>>>>+<<<<<<]>,------------
---------------------------------[--->>>>>[-<<<<++++++++++>>>>]<<<<<[->+<],[-]]>
>>>>[-<<<<+>>>>]<<<<<<,------------------------------------------------[->>>>>>+
<<<<<<]>,--------------------------------------------[---->>>>>[-<<<++++++++++>>
>]<<<<<[->>+<<],[-]]>>>>>[-<<<+>>>]<<<<<<,--------------------------------------
----------[->>>>>>+<<<<<<]>,---------------------------------------------[--->>>
>>[-<<++++++++++>>]<<<<<[->>>+<<<],[-]]>>>>>[-<<+>>]<<<<<<,---------------------
---------------------------[->>>>>>+<<<<<<]>,----------[------------------------
-------------->>>>>[-<++++++++++>]<<<<<[->>>>+<<<<],[-]]>>>>>[-<+>]>+<<<<<[->>>>
>>>+<<<<<<<]>>[->>>>>>+<<<<<<]>>>>>[->-[>]<<]<[->>>>>>+<<<<[[-]>>>>[-]<<<<<<<<<<
[->+<]>>[-<<+>>]<<<<+>>[->-[>]<<]<[->>>>>>>>>>>+<<<<<<<<<<<]<[-<]>>>>>>]>>>>[-<+
<<]<<<]<[-<<[-<+>]<<<<+>>[->-[>]<<]<[->>>>>>>>>>>+<<<<<<<<<<<]<[-<]>>>>>>]>>>>>[
-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-],]>>>>>>>>>>>>>>++++++++++<<[[->+>
-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>>>>[>]++++++++++++++++++++++++++++++++++++++++++
++++++[<]<<<[-<+>>>>>[>]<+[<]<<<]>[-<<<<+>>>>]<<<[-]<]>>>>>>>[>]<[.<]++++++++++.
,[------------------------------------------------[->>>>>>+<<<<<<]>,------------
---------------------------------[--->>>>>[-<<<<++++++++++>>>>]<<<<<[->+<],[-]]>
>>>>[-<<<<+>>>>]<<<<<<,------------------------------------------------[->>>>>>+
<<<<<<]>,--------------------------------------------[---->>>>>[-<<<++++++++++>>
>]<<<<<[->>+<<],[-]]>>>>>[-<<<+>>>]<<<<<<,--------------------------------------
----------[->>>>>>+<<<<<<]>,---------------------------------------------[--->>>
>>[-<<++++++++++>>]<<<<<[->>>+<<<],[-]]>>>>>[-<<+>>]<<<<<<,---------------------
---------------------------[->>>>>>+<<<<<<]>,----------[------------------------
-------------->>>>>[-<++++++++++>]<<<<<[->>>>+<<<<],[-]]>>>>>[-<+>]>+<<<<<[->>>>
>>>+<<<<<<<]>>[->>>>>>+<<<<<<]>>>>>[->-[>]<<]<[->>>>>>+<<<<[[-]>>>>[-]<<<<<<<<<<
[->+<]>>[-<<+>>]<<<<+>>[->-[>]<<]<[->>>>>>>>>>>+<<<<<<<<<<<]<[-<]>>>>>>]>>>>[-<+
<<]<<<]<[-<<[-<+>]<<<<+>>[->-[>]<<]<[->>>>>>>>>>>+<<<<<<<<<<<]<[-<]>>>>>>]>>>>>[
-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-],]>>>>>>>>>>>>>>++++++++++<<[[->+>
-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>>>>[>]++++++++++++++++++++++++++++++++++++++++++
++++++[<]<<<[-<+>>>>>[>]<+[<]<<<]>[-<<<<+>>>>]<<<[-]<]>>>>>>>[>]<[.<]++++++++++.
map eval $ map head $ map intersect $ map half
can be rewritten to map (eval . head . intersect . half)
.
cleans it up significantly, thanks :)otherwise
yet, thats neat,[------------------------------------------------[->>>>>>+<<<<<<]>,------------
---------------------------------[--->>>>>[-<<<<++++++++++>>>>]<<<<<[->+<],[-]]>
>>>>[-<<<<+>>>>]<<<<<<,------------------------------------------------[->>>>>>+
<<<<<<]>,--------------------------------------------[---->>>>>[-<<<++++++++++>>
>]<<<<<[->>+<<],[-]]>>>>>[-<<<+>>>]<<<<<<,--------------------------------------
----------[->>>>>>+<<<<<<]>,---------------------------------------------[--->>>
>>[-<<++++++++++>>]<<<<<[->>>+<<<],[-]]>>>>>[-<<+>>]<<<<<<,---------------------
---------------------------[->>>>>>+<<<<<<]>,----------[------------------------
-------------->>>>>[-<++++++++++>]<<<<<[->>>>+<<<<],[-]]>>>>>[-<+>]>+<<[->>>>+<<
<<]<<<[->>>>>>>>+<<<<<<<<]>>>>>>>[->-[>]<<]<[-<<<<<<+>>[->-[>]<<]<[->>>>>>>>>>>+
<<<<<<<<<<<]<[-<]>>>>>>>]<[-<]>>>>>[ -]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<
[-],]>>>>>>>>>>>>>>++++++++++<<[[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>>>>[>]+++++
+++++++++++++++++++++++++++++++++++++++++++[<]<<<[-<+>>>>>[>]<+[<]<<<]>[-<<<<+>>
>>]<<<[-]<]>>>>>>>[>]<[.<]++++++++++.