/** https://www.zhihu.com/question/52895544 */ funcmain() { n := 14 m := 4 nn := 1 mm := 1 nm := 1 for i := 1; i <= n; i++ { nn = nn * i } for i := 1; i <= m; i++ { mm = mm * i } for i := 1; i <= (n - m); i++ { nm = nm * i }
count := 0 for i := 1; i <= 11; i++ { for j := i + 1; j <= 12; j++ { for k := j + 1; k <= 13; k++ { for l := k + 1; l <= 14; l++ { //fmt.Printf("%d -> %d -> %d -> %d\n", i, j, k, l) if i == 11 && j == 12 && k == 13 && l == 14 { continue } all_result[count] = fmt.Sprintf("%d-%d-%d-%d", i, j, k, l) count++ all_result_map[fmt.Sprintf("%d-%d-%d-%d", i, j, k, l)] = count } } } }
chosen_ball := make([]int, 4) for i := 0; i < 4; i++ {
hit := r.Intn(14 - i) chosen_ball[i] = all_ball[hit] index := hit all_ball = append(all_ball[:index], all_ball[index+1:]...)
}
sort.Ints(chosen_ball) result := fmt.Sprintf("%d-%d-%d-%d", chosen_ball[0], chosen_ball[1], chosen_ball[2], chosen_ball[3])
if result == "11-12-13-14" { round-- continue }
result_rank := source_map[all_result_map[result]]
value := hit_map[result_rank] if value == 1 { round-- continue }
if round == 0 { all_hit_result[result_rank-1]++ } if round == 1 { all_hit_result_second_round[result_rank-1]++ } if round == 2 { all_hit_result_third_round[result_rank-1]++ }
hit_map[result_rank] = 1 }
} fmt.Println("第一轮") for i, resut_hit := range all_hit_result { fmt.Printf("%d -> %d\n", i+1, resut_hit) } fmt.Println("第二轮") for i, resut_hit := range all_hit_result_second_round { fmt.Printf("%d -> %d\n", i+1, resut_hit) } fmt.Println("第三轮") for i, resut_hit := range all_hit_result_third_round { fmt.Printf("%d -> %d\n", i+1, resut_hit) }