File tree Expand file tree Collapse file tree 4 files changed +12
-11
lines changed Expand file tree Collapse file tree 4 files changed +12
-11
lines changed Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
- A=($( sort -n 10.txt) )
2
+ A=($( sort -n ${1 :- 10.txt} ) )
3
3
DIFF=(" " " " " " " 1" ) # add 3 for the built-in
4
4
j=0; for i in " ${A[@]} " ; do DIFF[$(( i- j)) ]+=1; j=$i ; done
5
5
echo " 10A: ${# DIFF[1]} *${# DIFF[3]} =$(( ${# DIFF[1]} * ${# DIFF[3]} )) "
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
IFS=$' ,\n '
3
- A=($( sed s/x,//g 13.txt) )
3
+ input=${1:- 13.txt}
4
+ A=($( sed s/x,//g $input ) )
4
5
time=$A ; min=($A 0)
5
6
for i in " ${A[@]: 1} " ; do
6
7
w=$(( i- time% i))
7
8
[ $w -lt $min ] && min=($w $i )
8
9
done
9
10
echo " 13A: $min *${min[1]} = $(( min* ${min[1]} )) "
10
11
11
- A=($( tail -1 13.txt ) )
12
+ A=($( tail -1 $input ) )
12
13
for i in ${! A[@]} ; do [ ${A[i]} != x ] && B[$i ]=${A[i]} ; done
13
14
N=0; step=1
14
15
# echo "${!B[@]} => "${B[@]}""
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
- A=(${ *:- 0 12 6 13 20 1 17} )
3
- GIVEUP=${1 :- 10}
2
+ A=($( < ${1 :- 15.txt} ) )
3
+ GIVEUP=${2 :- 10}
4
4
# A=(0 3 6)
5
- unset B ; i=0; l=" "
5
+ B=() ; i=0; l=" "
6
6
for a in ${A[@]} ; do B[$a ]=$(( ++ i)) ; done
7
7
while [ $i -lt 2020 ]; do
8
8
n=$(( i- ${l:- $i } )) ; l=${B[$n]} ; B[$n ]=$(( ++ i))
@@ -14,8 +14,8 @@ sharded_swap() { # syntax: l=B[$1]; B[$1]=$2
14
14
local x=" B$(( $1 >> 6 )) [$(( $1 & 63 )) ]"
15
15
eval " l=\$ {$x }; $x =$2 "
16
16
}
17
-
18
- i=0; for a in ${A[@]} ; do sharded_swap $a $(( ++ i)) ; done ; l=" " ;
17
+ SECONDS=0
18
+ i=0; for a in ${A[@]} ; do sharded_swap $a $(( ++ i)) ; done ; l=" " ;
19
19
while [[ $i -lt 30000000 && $SECONDS -le $GIVEUP ]]; do
20
20
n=$(( i- ${l:- $i } )) ; sharded_swap $n $(( ++ i))
21
21
[ $(( i% 100000 )) = 0 ] && echo " $i : $SECONDS sec"
@@ -24,7 +24,7 @@ if [ $i = 30000000 ]; then
24
24
echo " 15B: $n "
25
25
else
26
26
# The code above would take days or weeks to run. Switch to awk
27
- echo " $n Gave up after $SECONDS seconds after round ${i} "
27
+ echo " 15B(round $i ): $n ( Gave up after $SECONDS seconds) "
28
28
printf " %s\n" ${A[@]} | awk ' {B[$0]=++i;}
29
29
END {
30
30
while (i<30000000) { n=l?(i-l):0; l=B[n]; B[n]=++i; }
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
- A=${1:- 167248359}
2
+ A=$( < $ {1:- 23.txt} )
3
3
i=0
4
4
for k in {0..99}; do
5
5
c=${A: i: 1}
@@ -13,7 +13,7 @@ while [ ${A:i:1} != $c ]; do [ $((++i)) = 9 ] && i=0; done
13
13
[ $(( ++ i)) = 9 ] && i=0
14
14
done
15
15
echo " 23A: ${A/* 1}${A/ 1* } "
16
- A=167248359
16
+ A=$( < ${1 :- 23.txt} )
17
17
# A=389125467
18
18
printf $A | sed -e " s/\(.\)/\1\n/g" | awk '
19
19
{ if(last){ C[last]=$0 }else{ cup=$0 }; last=$0; ++i; }
You can’t perform that action at this time.
0 commit comments