File tree Expand file tree Collapse file tree 3 files changed +178
-0
lines changed
Expand file tree Collapse file tree 3 files changed +178
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ . ../../misc/vardump
4+
5+ FILE=" $1 "
6+
7+ declare -A graph
8+ declare -A visited
9+
10+ count=0
11+ function dfs() {
12+ local start=$1
13+ local depth=$2
14+ printf " %${depth} s" 1>&2
15+ printf " %s\n" " $start " 1>&2
16+ if [[ " $start " == " out" ]]; then
17+ (( count++ ))
18+ return
19+ fi
20+ local -a conns=(${graph[$start]} )
21+ local i
22+ for (( i= 0 ;i< ${# conns[@]} ;++ i)) ; do
23+ dfs " ${conns[i]} " " $(( depth+ 1 )) "
24+ done
25+ }
26+
27+ load_the_cannon () {
28+ while IFS= read -r line; do
29+ eval " $line "
30+ done
31+ dfs " you" " 0"
32+ echo $count
33+
34+ # while [[ ${#q[@]} -gt 0 ]]; do
35+ # len=${#q[@]}
36+ # next="${q[len-1]}"
37+ # q=("${q[@]:0:len-1}")
38+ # [[ -n "${visited[$next]}" ]] && continue
39+ # echo "visiting $next"
40+ # visited[$next]=1
41+ # q+=(${graph[$next]})
42+ # done
43+ }
44+
45+ cat " $FILE " \
46+ | sed ' s/^/graph[/;s/: /]="/;s/$/"/' \
47+ | load_the_cannon
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ . ../../misc/vardump
4+
5+ FILE=" $1 "
6+
7+ declare -A graph
8+
9+
10+ declare -A c
11+
12+ count=0
13+ function dfs() {
14+ local start=$1
15+ local end=$2
16+ local fft=$3
17+ local dac=$4
18+ # printf "%${depth}s" 1>&2
19+ # printf "%s\n" "$start" 1>&2
20+ if [[ " $start " == " $end " ]]; then
21+ (( count++ ))
22+ # if [[ $fft -eq 1 && dac -eq 1 ]]; then
23+ # ((count++))
24+ # fi
25+ return
26+ fi
27+ if [[ " $start " == " fft" ]]; then
28+ fft=1
29+ fi
30+ if [[ " $start " == " dac" ]]; then
31+ dac=1
32+ fi
33+ local -a conns=(${graph[$start]} )
34+ local i
35+ for (( i= 0 ;i< ${# conns[@]} ;++ i)) ; do
36+ dfs " ${conns[i]} " " $end " $fft $dac
37+ done
38+ }
39+
40+ count_paths () {
41+ local end=$1
42+ shift
43+ local -a starts=($@ )
44+ local total=0
45+ local start
46+ for start in " ${starts[@]} " ; do
47+ count=0
48+ echo dfs " $start " " $end " 0 0
49+ dfs " $start " " $end " 0 0
50+ (( total+= c[$start ]* count))
51+ done
52+ echo $total
53+ }
54+
55+ load_the_cannon () {
56+ while IFS= read -r line; do
57+ eval " $line "
58+ done
59+ c[omn]=1032
60+ c[zyw]=823
61+ c[kzo]=1010
62+ c[ziu]=855
63+ c[fft]=$(( 3 * c[omn]+ 2 * c[zyw]+ 3 * c[kzo]+ 3 * c[ziu]))
64+ # layer 1 bridges
65+ # graph[omn]=
66+ # graph[zyw]=
67+ # graph[kzo]=
68+ # graph[ziu]=
69+
70+ # layer 2 bridges
71+ c[coc]=$(( c[fft]* 2 ))
72+ c[qmi]=$(( c[fft]* 1 ))
73+ c[qia]=$(( c[fft]* 1 ))
74+ c[eiz]=$(( c[fft]* 2 ))
75+ c[ysm]=$(( c[fft]* 2 ))
76+ # graph[coc]=
77+ # graph[qmi]=
78+ # graph[qia]=
79+ # graph[eiz]=
80+ # graph[ysm]=
81+
82+ # layer 3 bridges
83+ # graph[dev]=
84+ # graph[qzd]=
85+ # graph[ksk]=
86+
87+ c[dev]=8507351
88+ c[qzd]=9272289
89+ c[ksk]=9592736
90+
91+ # layer 4 bridges
92+ c[xbq]=3496283510
93+ c[mlu]=3772302084
94+ c[uvw]=4086960364
95+ c[vkk]=5026521305
96+
97+ # layer 5 bridges
98+ graph[qve]=
99+ graph[iix]=
100+ graph[you]=
101+ c[dac]=116011199996
102+ c[out]=$(( 3460 * c[dac]))
103+ echo " ${c[out]} "
104+ }
105+
106+ cat " $FILE " \
107+ | sed ' s/^/graph[/;s/: /]="/;s/$/"/' \
108+ | load_the_cannon
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ . ../../misc/vardump
4+
5+ FILE=" $1 "
6+
7+ declare -A graph
8+
9+ load_the_cannon () {
10+ while IFS= read -r line; do
11+ eval " $line "
12+ done
13+ for key in " ${! graph[@]} " ; do
14+ conns=(${graph[$key]} )
15+ for (( i= 0 ;i< ${# conns[@]} ;++ i)) ; do
16+ echo " $key -> ${conns[i]} "
17+ done
18+ done
19+ }
20+
21+ cat " $FILE " \
22+ | sed ' s/^/graph[/;s/: /]="/;s/$/"/' \
23+ | load_the_cannon
You can’t perform that action at this time.
0 commit comments