Last active
May 23, 2023 16:49
-
-
Save drakonstein/cb922d06f8a59b6624a278bfa4c64f53 to your computer and use it in GitHub Desktop.
Birdhunt CFT challenge done in bash and then AWK. Find the coordinates for the birds in the grid and finish all 200 rounds before the timeout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
inround=false | |
exec 5<>/dev/tcp/35.231.207.196/15830 | |
while true; do | |
if $inround; then | |
awk 'BEGIN {coords=""} /B|^$/ { | |
if(NF == 0) | |
exit | |
for(i=2;i<=NF;i++) { | |
if($i == "B") | |
coords = coords";("i-2","$1")" | |
} | |
} END {print substr(coords,2)}' <&5 >&5 && inround=false || echo huh | |
else | |
read row line <&5 || break | |
(( round == 200 )) && echo "$row $line" | grep flag && exit 0 | |
[[ "$row" == "Round:" ]] && inround=true && round=$line | |
fi | |
done | |
echo "Got to round: $round" | |
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
start=false | |
coords= | |
exec 5<>/dev/tcp/35.231.207.196/15830 | |
while read row line; do | |
# Loop through quickly to find the start of the first round | |
if ! $start; then | |
[[ "$row" == "Round:" ]] && start=true && round=$line | |
continue | |
fi | |
# Find the right time to submit the coordinates | |
[[ -z "$row" && ! -z "$coords" ]] && echo ${coords:1} >&5 && coords= && continue | |
# Check for which column the B is in | |
[[ "$line" == *"B"* ]] && column=0 && for line2 in $line; do | |
[[ $line2 == "B" ]] && coords="$coords;($column,$row)" | |
column=$(( column + 1)) | |
done <<< "$line" && continue | |
[[ "$row" == "Round:" ]] && round=$line && continue | |
(( round == 200 )) && echo "$row $line" | grep flag && exit 0 | |
done <&5 | |
echo "Got to round: $round" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment