Add everything I got

This commit is contained in:
Jakub Fišer 2023-12-01 14:20:13 +01:00
parent e2343da168
commit 7d709d6f24
13 changed files with 424 additions and 1 deletions

15
1a.sh Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
max=0
c=0
while read a; do
if [[ -z "$a" ]]; then
[[ $c -gt $max ]] && max=$c
c=0
else
let c+=$a
fi
done
echo $max

26
1b.sh Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
max1=0
max2=0
max3=0
c=0
while read a; do
if [[ -n "$a" ]]; then
let c+=$a
else
if [[ $c -gt $max1 ]]; then
max3=$max2
max2=$max1
max1=$c
elif [[ $c -gt $max2 ]]; then
max3=$max2
max2=$c
elif [[ $c -gt $max3 ]]; then
max3=$c
fi
c=0
fi
done
echo $(( $max1 + $max2 + $max3 ))

25
2a.sh Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
declare -A A B C
A['X']=3
A['Y']=6
A['Z']=0
B['X']=0
B['Y']=3
B['Z']=6
C['X']=6
C['Y']=0
C['Z']=3
X=1
Y=2
Z=3
s=0
while read a b; do
declare -n elf=$a
declare -n me=$b
let s+=$(( ${elf[$b]} + $me ))
done
echo $s

24
2b.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
declare -A A B C
A['X']=3
A['Y']=4
A['Z']=8
B['X']=1
B['Y']=5
B['Z']=9
C['X']=2
C['Y']=6
C['Z']=7
s=0
while read a b; do
declare -n elf=$a
declare -n me=$b
let s+=$(( ${elf[$b]} ))
done
echo $s

35
3a.sh Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
declare -A P
p=0
for i in {a..z} {A..Z}; do
let p++
P[$i]=$p
done
s=0
while read a; do
l=${#a}
ll=$(( $l / 2 ))
x=${a:0:$ll}
y=${a:$ll}
c=''
for i in `seq 0 $(( $ll - 1 ))`; do
if grep -q ${x:$i:1} <<< ${y}; then
c=${x:$i:1}
break
fi
done
let s+=P[$c]
done
echo $s

63
3b.sh Executable file
View File

@ -0,0 +1,63 @@
#!/usr/bin/env bash
function lowi() {
low=${#1}
i=0
li=0
shift
for l in "$@"; do
let i++
if [ ${#l} -lt $low ]; then
li=$i
low=${#l}
fi
done
echo $li
}
declare -A P
p=0
for i in {a..z} {A..Z}; do
let p++
P[$i]=$p
done
sum=0
while read a; read b; read c; do
bags=( $a $b $c )
li=$(lowi $a $b $c)
x=${bags[li]}
y=${bags[$(( (li + 1) % 3 ))]}
z=${bags[$(( (li + 2) % 3 ))]}
c1=''
for i in `seq 0 $(( ${#bags[$li]} - 1 ))`; do
if [[ $y == *${x:$i:1}* ]]; then
c1="${c1}${x:$i:1}"
fi
done
for i in `seq 0 $(( ${#c1} - 1 ))`; do
if [[ $z == *${c1:$i:1}* ]]; then
c=${c1:$i:1}
break
fi
done
let sum+=P[$c]
c=''
done
echo $sum

18
4a.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
sum=0
while read a; do
IFS=, read x y <<< $a
IFS=- read x1 x2 <<< $x
IFS=- read y1 y2 <<< $y
if [[ $(( (x1 - y1) * (x2 - y2) )) -le 0 ]]; then
let sum++
fi
done
echo $sum

17
4b.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
sum=0
while read a; do
IFS=, read x y <<< $a
IFS=- read x1 x2 <<< $x
IFS=- read y1 y2 <<< $y
if [[ $(( (x1 - y2) * (x2 - y1) )) -le 0 ]]; then
let sum++
fi
done
echo $sum

49
5a.sh Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env bash
sum=0
declare -a C
popped=''
function push() {
C[$1]="${C[$1]}${2}"
}
function pop() {
l=$(( ${#C[$1]} - 1 ))
popped=${C[$1]:$l:1}
C[$1]="${C[$1]:0:$l}"
}
while read a; do
if [[ "$a" == "1 2 3 4 5 6 7 8 9" ]]; then
break
fi
for i in {0..8}; do
c=${a:$(( 4 * $i + 1)):1}
if [[ "$c" == ' ' ]]; then
c=''
fi
C[$i]="${c}${C[$i]}"
done
done
read
while read x1 n x2 f x3 t; do
let f--
let t--
for i in `seq 1 $n`; do
pop $f
push $t $popped
done
done
out=""
for i in {0..8}; do
pop $i
echo -n "$popped"
done
echo

48
5b.sh Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
sum=0
declare -a C
popped=''
function push() {
C[$1]="${C[$1]}${2}"
}
function pop() {
a=${2:-1}
l=$(( ${#C[$1]} - $a ))
popped=${C[$1]:$l:$a}
C[$1]="${C[$1]:0:$l}"
}
while read a; do
if [[ "$a" == "1 2 3 4 5 6 7 8 9" ]]; then
break
fi
for i in {0..8}; do
c=${a:$(( 4 * $i + 1)):1}
if [[ "$c" == ' ' ]]; then
c=''
fi
C[$i]="${c}${C[$i]}"
done
done
read
while read x1 n x2 f x3 t; do
let f--
let t--
pop $f $n
push $t $popped
done
out=""
for i in {0..8}; do
pop $i
echo -n "$popped"
done
echo

46
6a.sh Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env bash
winl=4
win=''
function add() {
win="${win:1}${1}"
}
function contains() {
# $1 what
# $2 where
local l=${#2}
local ret=1
while (( l-- )); do
[[ "$1" = "${2:$l:1}" ]] && ret=0 && break
done
return $ret
}
function unq() {
local l=${#1}
while (( --l )); do
contains ${1:$l:1} ${1:0:$l} && break
done
return $l
}
i=$(( $winl - 1 ))
read -n $i win
win=${win:0:1}${win}
while read -n 1 a; do
let i++
add $a
unq "$win" && break
done
echo $i

44
6b.sh Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
winl=14
win=''
function add() {
win="${win:1}${1}"
}
function contains() {
# $1 what, $2 where
local l=${#2}
local ret=1
while (( l-- )); do
[[ "$1" = "${2:$l:1}" ]] && ret=0 && break
done
return $ret
}
function unq() {
local l=${#1}
while (( --l )); do
contains ${1:$l:1} ${1:0:$l} && break
done
return $l
}
i=$(( $winl - 1 ))
read -n $i win
win=${win:0:1}${win}
while read -n 1 a; do
let i++
add $a
unq "$win" && break
done
echo $i

15
LICENSE
View File

@ -1 +1,14 @@
"THE BEER-WARE LICENSE" (Revision 42): <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp /*
* ----------------------------------------------------------------------------
* "THE BEERWARE NO-WARRANTY LICENCE v1" (based on BEERWARE rev 42)
*
* <j@jfi.cz> made this stuff.
*
* As long as you retain this notice you can do whatever you want with this
* stuff. Use this stuff at your own risk however - no warranty at all.
*
* If we meet some day, and you think this stuff is worth it, you can buy me
* a beer in return.
* copyright (c) 2023, jficz
* ----------------------------------------------------------------------------
*/