Skip to content

Instantly share code, notes, and snippets.

@KaitoMuraoka
Created May 7, 2023 06:42
Show Gist options
  • Save KaitoMuraoka/7ae7c1f4bdaeb86e4a994c36d42d6833 to your computer and use it in GitHub Desktop.
Save KaitoMuraoka/7ae7c1f4bdaeb86e4a994c36d42d6833 to your computer and use it in GitHub Desktop.
アルゴ式:複雑なプログラムを書き直す(Swift版)
// 偏差値 (Z score) を計算する
def float: calc_zscore(int: N, float[]: scores, float score)
float: average = 0.0
for (初期値: index = 0, 条件: index < N, 更新: index += 1)
average += scores[index]
endfor
average = average ÷ N の値
float: sd = 0.0
for (初期値: index = 0, 条件: index < N, 更新: index += 1)
sd += (scores[index] - average) * (scores[index] - average)
endfor
sd = sd ÷ N の値
sd = sqrt(sd)
float: z_score = 50 + 10 * (score - average) ÷ sd の値
return z_score
// 生徒の人数
int: N = 5
// 試験の点数
float[]: scores = [70, 50, 85, 69, 63]
// $1$ 番目の生徒の点数の偏差値を計算する
float: z_score = calc_zscore(N, scores, scores[0])
print(z_score)
@KaitoMuraoka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment