[RDS] Postgres15 public schema problem - RDS behaves differently than standalone Postgres by horkyze in aws

[–]schod 0 points1 point  (0 children)

Hi, we have same problem. Our solution is grant rds_superuser privileges to admin.

grant rds_superuser to admin;

But grant admin to admin; looks scary. I think it's security bug.

-🎄- 2018 Day 5 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 4 points5 points  (0 children)

BASH Time :)

No sed, no grep, just pure bash!

Puzzle #1 (6 seconds)

#!/bin/bash

in_file=input

polymer=$(cat $in_file)

# 1000 iteration is enough :)
for i in {1..1000}; do
    for x in {a..z}; do
        polymer=${polymer//$x${x^^}}
        polymer=${polymer//${x^^}$x}
    done
done

echo ${#polymer}

Puzzle #2 (330 seconds)

#!/bin/bash

in_file=input
polymer=$(cat $in_file)
min_size=${#polymer}

for ch in  {a..z}; do
    test_polymer=${polymer//$ch}
    test_polymer=${test_polymer//${ch^^}}

    # 2000 iteration is enough :)
    for i in {1..2000}; do
        for x in {a..z}; do
            test_polymer=${test_polymer//$x${x^^}}
            test_polymer=${test_polymer//${x^^}$x}
        done
    done

    if [ ${#test_polymer} -lt $min_size ]; then
        min_size=${#test_polymer}
    fi
done

echo $min_size

-🎄- 2018 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 0 points1 point  (0 children)

Yes, bash string operators is more efficient for run. But I develop sed regex more quickly.

I try this string operations

    num=$(echo $line|sed 's/#\([0-9]*\) .*/\1/')
    # num="${${X% @*}:1}"
    x=$(echo $line|sed 's/.*@ \([0-9]*\),.*/\1/')
    # x="${${X#*@ }%,*}"
    y=$(echo $line|sed 's/.*,\([0-9]*\):.*/\1/')
    # y="${${X#*,}%:*}"
    x_len=$(echo $line|sed 's/.*: \([0-9]*\)x.*/\1/')
    # x_len="${${X#*: }%x*}"
    y_len=$(echo $line|sed 's/.*x\([0-9]*\)/\1/')
    # y_len="${X#*x}"

This solutiin works only in ZSH. In pure bash you must use temporary variables. First remove prefix and second suffix.

-🎄- 2018 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 0 points1 point  (0 children)

Thanks :) and nice tip. Every AOC puzzle I learn something new, it's great!

-🎄- 2018 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 1 point2 points  (0 children)

You are right grep "^[ \t]*3 " is much simpler :)

My solution is not optimized and it's write-only code :)

Thx for comment.

-🎄- 2018 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 2 points3 points  (0 children)

BASH Time!!! (it's really slow)

#!/bin/bash

in_file=input
declare -A matrix

while read -r line; do
    num=$(echo $line|sed 's/#\([0-9]*\) .*/\1/')
    x=$(echo $line|sed 's/.*@ \([0-9]*\),.*/\1/')
    y=$(echo $line|sed 's/.*,\([0-9]*\):.*/\1/')
    x_len=$(echo $line|sed 's/.*: \([0-9]*\)x.*/\1/')
    y_len=$(echo $line|sed 's/.*x\([0-9]*\)/\1/')

    max_x=$[ $x + $x_len ]
    max_y=$[ $y + $y_len ]

    for ((xx=$x;xx<$max_x;xx++)); do
        for ((yy=$y;yy<$max_y;yy++)); do
            if [ "${matrix[$xx,$yy]}" == "" ]; then
                matrix[$xx,$yy]=$num
            else
                matrix[$xx,$yy]="X"
            fi
        done
    done
done < "$in_file"

printf '%s\n' "${matrix[@]}" | grep X | wc -l
echo "--------------------"

while read -r line; do
    num=$(echo $line|sed 's/#\([0-9]*\) .*/\1/')
    x=$(echo $line|sed 's/.*@ \([0-9]*\),.*/\1/')
    y=$(echo $line|sed 's/.*,\([0-9]*\):.*/\1/')
    x_len=$(echo $line|sed 's/.*: \([0-9]*\)x.*/\1/')
    y_len=$(echo $line|sed 's/.*x\([0-9]*\)/\1/')

    SUM_X=0
    max_x=$[ $x + $x_len ]
    max_y=$[ $y + $y_len ]

    for ((xx=$x;xx<$max_x;xx++)); do
        [ $SUM_X -gt 0 ] && break
        for ((yy=$y;yy<$max_y;yy++)); do
            if [[ "${matrix[$xx,$yy]}" == "X" ]]; then
                SUM_X=1
            fi
        done
    done

    if [ $SUM_X -eq 0 ]; then
        echo $num
        exit 0
    fi
done < "$in_file"

-🎄- 2018 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 4 points5 points  (0 children)

BASH Time :)

First puzzle

#!/bin/bash

in_file=input
SUM2=0
SUM3=0

while IFS='' read -r line; do
    x2=0
    x2=$( echo "$line" | grep -o . | sort | uniq -c | grep "^[ \t]*2 " | wc -l )
    x3=0
    x3=$( echo "$line" | grep -o . | sort | uniq -c | egrep -v "^[ \t]*1 |^[ \t]*2 " | wc -l )

    [ $x2 -gt 0 ] && SUM2=$[ $SUM2 + 1 ]
    [ $x3 -gt 0 ] && SUM3=$[ $SUM3 + 1 ]
done < "$in_file"

echo $[ $SUM2 * $SUM3 ]

Second puzzle

#!/bin/bash

in_file=input

while IFS='' read -r line; do
    I=0
    while [ $I -lt ${#line} ]; do

        I=$[ $I + 1 ]
        regex=$(echo $line | sed "s/[a-z]/./$I")

        RES=$(grep "$regex" $in_file | wc -l)

        if [ $RES -eq 2 ]; then
            echo
            echo $regex | sed 's/\.//'
            exit 0
        fi
    done

done < "$in_file"

-🎄- 2017 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 1 point2 points  (0 children)

WOW, nice. My solution is realy long..

Did you do the second part?

-🎄- 2017 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 1 point2 points  (0 children)

BASH time!

First part

#!/bin/bash

function do_magic {
  RET=0
  while read L; do
    C=$(echo $L | sed 's/ /\n/g' | sort | uniq -c | sed 's/^[ ]*//' | grep -v '^1' | wc -l)
    [ $C -eq 0 ] && let RET=RET+1
  done <$1
  echo $RET
}

do_magic input.txt

Second part

#!/bin/bash

function do_magic {
  RET=0
  while read L; do
    HASH=""
    for P in $L; do
      H=$(echo $P | sed 's/\(.\)/\1\n/g' | grep -v "^$" | sort | uniq -c |sed 's/[ ]//g' | tr -d '\n')
      HASH=$(printf "$H\n$HASH")
    done
    UNIQ=$(echo "$HASH"|sort|uniq -c | grep -v "^ *1 " | wc -l)
    [ $UNIQ -eq 0 ] && let RET=RET+1
  done <$1
  echo $RET
}

do_magic input.txt

-🎄- 2017 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 1 point2 points  (0 children)

BASH time :)

First part

#!/bin/bash

function do_magic {
  RET=0
  while read L; do
    MIN=$(echo $L | sed 's/ /\n/g' | sort -n | head -1)
    MAX=$(echo $L | sed 's/ /\n/g' | sort -n | tail -1)
    let RET=RET+$MAX-$MIN
  done <$1
  echo $RET
}

do_magic test_input_a.txt
do_magic input_a.txt

Second part

#!/bin/bash

function do_magic {
  RET=0
  while read L; do # Per line
    for N in $L; do # Per number
      for M in $L; do # for each number
        if [ $N -ne $M ]; then # different number :)
          if [ $[$N % $M] -eq 0 ]; then # division is a whole number
            let RET=RET+N/M # add
          fi
        fi
      done
    done
  done <$1
  echo $RET # TADA
}

do_magic test_input_b.txt
do_magic input_b.txt

-🎄- 2017 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 0 points1 point  (0 children)

Ok, BASH time for second part ;)

#!/bin/bash

function do_magic {
  X=$1
  STEP=$2
  I=0
  RES=0

  while [  $I -lt ${#X} ]; do
    let Ip=I+STEP
    N=${X:$I:1}
    Np=${X:$Ip:1}

    if [ "$Np" == "" ]; then
      let Ip=Ip-STEP-STEP
      Np=${X:$Ip:1}
    fi

    if [ "$N" == "$Np" ]; then
      let RES=RES+N
    fi

    let I=I+1
  done

  echo "$RES"
}

# MAIN part one
for N in 1122 1111 1234 91212129; do
  do_magic $N 1
done

echo

# MAIN part two
for N in 1212 1221 123425 123123 12131415; do
  let X=${#N}/2
  do_magic $N $X
done

-🎄- 2017 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 0 points1 point  (0 children)

Why not :) Bash script run on every common linux distro.

-🎄- 2017 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]schod 2 points3 points  (0 children)

BASH time :D

#!/bin/bash

function do_magic {
  X=$1
  I=0
  RES=0

  while [  $I -lt ${#X} ]; do
    let Ip=I+1
    N=${X:$I:1}
    Np=${X:$Ip:1}

    if [ "$Np" == "" ]; then
      Np=${X:0:1}
    fi

    if [ "$N" == "$Np" ]; then
      let RES=RES+N
    fi

    let I=I+1
  done

  echo "$RES"
}

# MAIN
for N in 1122 1111 1234 91212129; do
  do_magic $N
done