1
0
Fork 0
mirror of https://github.com/samsapti/bachelor-project.git synced 2024-11-22 04:47:53 +00:00

Use for + eval

This commit is contained in:
Sam A. 2023-05-06 00:58:28 +02:00
parent 5245ca05f4
commit 8960b9a69c
Signed by: samsapti
GPG key ID: CBBBE7371E81C4EA

View file

@ -1,5 +1,7 @@
#!/usr/bin/env bash
set -eo pipefail
patient_pref() {
printf '%d %d' "-100" "$1"
}
@ -10,22 +12,22 @@ therapist_pref() {
secret_share() {
local secret="$1"
share_0="$(( RANDOM % (secret / 2 + 1) ))"
share_1="$(( RANDOM % (secret / 2 + 1) ))"
share_2="$(( secret - (share_0 + share_1) ))"
export share_0="$(( RANDOM % (secret / 2 + 1) ))"
export share_1="$(( RANDOM % (secret / 2 + 1) ))"
export share_2="$(( secret - (share_0 + share_1) ))"
}
max_index=5
max_case=5
iter="$1"
for _ in $(seq "$iter"); do
rand="$(( (RANDOM % max_index) + 1 ))"
rand="$(( (RANDOM % max_case) + 1 ))"
secret_share "$rand"
p_data_s+=( "$rand" )
p_data_0+=( "$(patient_pref $share_0)" )
p_data_1+=( "$(patient_pref $share_1)" )
p_data_2+=( "$(patient_pref $share_2)" )
for j in $(seq 0 2); do
eval 'p_data_'$j'+=( $(patient_pref "$share_'$j'") )'
done
done
t_data_s=( $(shuf -e "${p_data_s[@]}") )
@ -33,9 +35,9 @@ t_data_s=( $(shuf -e "${p_data_s[@]}") )
for i in $(seq 0 "$(( iter - 1 ))"); do
secret_share "${t_data_s[$i]}"
t_data_0+=( "$(therapist_pref $share_0)" )
t_data_1+=( "$(therapist_pref $share_1)" )
t_data_2+=( "$(therapist_pref $share_2)" )
for j in $(seq 0 2); do
eval 't_data_'$j'+=( $(therapist_pref "$share_'$j'") )'
done
done
for i in $(seq 0 2); do