Created
May 7, 2023 06:42
-
-
Save KaitoMuraoka/7ae7c1f4bdaeb86e4a994c36d42d6833 to your computer and use it in GitHub Desktop.
アルゴ式:複雑なプログラムを書き直す(Swift版)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 偏差値 (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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
アルゴ式のプログラム技法、「大きなコードを分割する」のSwift版サンプルコード