マニュアル
3ヒートで参加者のバトルが被らないような順序を生成するプログラムを作ってみました。
ChatGPTを使って作成したマニュアルと、ChatGPTを使ってリファクタリングしたプログラムを参考までに公開します。
ご参考ください。
Key feature:
1. Calculates the factorial of a number
2. Calculates the Fibonacci sequence up to a given number
3. Sorts a list of numbers in ascending order
Now, let's break down each of these features and explain how they work.
1. Calculating the Factorial of a Number
The factorial of a number is the product of all positive integers up to and including that number. For example, the factorial of 5 is 5 x 4 x 3 x 2 x 1, which equals 120.
To use this feature of the program, follow these steps:
Enter the number for which you want to calculate the factorial.
Press the "Calculate Factorial" button.
The program will display the factorial of the entered number.
2. Calculating the Fibonacci Sequence
The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding numbers. For example, the first 10 numbers in the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
To use this feature of the program, follow these steps:
Enter the number up to which you want to calculate the Fibonacci sequence.
Press the "Calculate Fibonacci" button.
The program will display the Fibonacci sequence up to the entered number.
3. Sorting a List of Numbers
Sorting is the process of arranging items in a particular order. In this program, you can sort a list of numbers in ascending order.
To use this feature of the program, follow these steps:
Enter the list of numbers you want to sort, separated by commas.
Press the "Sort List" button.
The program will display the sorted list of numbers.
Conclusion
With these three key features, your program can perform a range of useful mathematical functions. By following the steps outlined in this manual, you can easily use the program to calculate factorials, generate Fibonacci sequences, and sort lists of numbers.
ソースコード(Cプログラム)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#define NUM_PLAYERS 12
#define NUM_ROUNDS 3
#define PLAYERS_PER_GAME ((NUM_PLAYERS + NUM_ROUNDS - 1) / NUM_ROUNDS)
void generateNonOverlapRandomNumbers(int* numbers, int count) {
for (int i = 0; i < count; i++) {
int randomNum;
bool foundOverlap;
do {
randomNum = rand() % NUM_PLAYERS;
foundOverlap = false;
for (int j = 0; j < i; j++) {
if (numbers[j] == randomNum) {
foundOverlap = true;
break;
}
}
} while (foundOverlap);
numbers[i] = randomNum;
}
}
void generateBattleOrder(int order[NUM_ROUNDS][3][PLAYERS_PER_GAME]) {
// Round 1
int playerOrder[NUM_PLAYERS];
generateNonOverlapRandomNumbers(playerOrder, NUM_PLAYERS);
for (int i = 0; i < PLAYERS_PER_GAME; i++) {
for (int j = 0; j < NUM_ROUNDS; j++) {
order[0][j][i] = playerOrder[i * NUM_ROUNDS + j];
}
}
// Rounds 2 and 3
for (int round = 1; round < NUM_ROUNDS; round++) {
int numSameOrders;
do {
numSameOrders = 0;
generateNonOverlapRandomNumbers(playerOrder, NUM_PLAYERS);
for (int i = 0; i < PLAYERS_PER_GAME; i++) {
for (int j = 0; j < NUM_ROUNDS; j++) {
order[round][j][i] = playerOrder[i * NUM_ROUNDS + j];
}
}
for (int i = 0; i < PLAYERS_PER_GAME; i++) {
for (int j = 0; j < PLAYERS_PER_GAME; j++) {
bool sameOrder = true;
for (int k = 0; k < NUM_ROUNDS; k++) {
if (order[round][k][i] != order[round - 1][k][j]) {
sameOrder = false;
break;
}
}
if (sameOrder) {
numSameOrders++;
break;
}
}
}
} while (numSameOrders > 0);
}
}
int main(void) {
srand(time(NULL));
int battleOrder[NUM_ROUNDS][3][PLAYERS_PER_GAME];
generateBattleOrder(battleOrder);
// Print the battle order
for (int round = 0; round < NUM_ROUNDS; round++) {
printf("Round %d:\n", round + 1);
for (int i = 0; i < PLAYERS_PER_GAME; i++) {
printf("Game %2d: %2d %2d %2d\n", i + 1, battleOrder[round][0][i]+1,
battleOrder[round][1][i]+1, battleOrder[round][2][i]+1);
}
}
return 0;
}