LoginSignup
1
0

More than 3 years have passed since last update.

俺とお前と大五郎

Posted at

これは何?

つまり

  • お前大五郎をランダムで出力して、俺とお前と大五郎になったら終了する。
  • 今回はTypeScriptで書いてみる。TypeScript要素無かった。
const words: Array<string> = ['', 'お前', '大五郎'];
const getWord = (): string => words[Math.floor(Math.random() * 3)];

const values: Array<string> = [];
let count: number = 0;

while (true) {
  values.push(getWord());
  if (values.length === 3) {
    count++;
    console.log(`${count}\t${values.join('')}`);
    if (JSON.stringify(values) === JSON.stringify(words)) {
      break;
    } else {
      values.splice(0, values.length);
    }
  }
}

実行結果


1       大五郎とお前と大五郎
2       俺と俺とお前
3       俺と俺と俺
4       大五郎と大五郎とお前
5       お前と大五郎と俺
6       お前とお前と俺
7       俺と大五郎と俺
8       大五郎と俺と俺
9       大五郎とお前と大五郎
10      俺と俺とお前
11      大五郎と俺とお前
12      俺とお前と俺
13      お前とお前と俺
14      大五郎と大五郎とお前
15      俺と俺と大五郎
16      お前とお前と大五郎
17      お前と俺とお前
18      大五郎と大五郎とお前
19      大五郎と俺と大五郎
20      大五郎とお前と俺
21      お前と俺とお前
22      俺とお前と大五郎

結局のところ、これは何?

懐かしいですよね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0