#!/bin/bash
-start_password=254032
-end_password=789860
+filename=${1:-input.txt}
+exec 3<"${filename}"
+
+read -u 3 line
+
+start_password=${line%-*}
+end_password=${line#*-}
check_valid_1() {
cur_password=$1
last_val=${cur_password:0:1}
- val=$last_val
got_dupe=0
if [ $cur_password -ge $start_password ] && [ $cur_password -le $end_password ]; then
for (( a=1; a<${#cur_password}; a++ )); do
val=${temp_password:$a:1}
if [ $val -lt $last_val ]; then
val=$last_val
+ for (( b=$a; b<${#temp_password}; b++ )); do
+ new_password+=$val
+ done
+ echo "$new_password"
+ return 0
fi
new_password+=$val
last_val=$val
valid_passwords=0
valid_passwords_2=0
while [ $cur_password -le $end_password ]; do
- echo -n "$cur_password: "
+ #echo -n "$cur_password: "
if ( check_valid_1 $cur_password ); then
- echo -n valid
+ #echo -n valid
valid_passwords=$((valid_passwords+1))
if ( check_valid_2 $cur_password ); then
- echo " valid"
+ #echo " valid"
valid_passwords_2=$((valid_passwords_2+1))
else
- echo " invalid"
+ #echo " invalid"
+ true
fi
else
- echo invalid
+ #echo invalid
+ true
fi
cur_password=$(get_next $cur_password)
done