Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

康威生命游戏 #31893

Open
E0SelmY4V opened this issue Jan 28, 2024 · 1 comment · May be fixed by #31894
Open

康威生命游戏 #31893

E0SelmY4V opened this issue Jan 28, 2024 · 1 comment · May be fixed by #31894
Labels
new-challenge Propose a new challenge, a PR will be auto generated zh-CN 简体中文

Comments

@E0SelmY4V
Copy link
Contributor

E0SelmY4V commented Jan 28, 2024

请按照以下的模版填充相应的内容,一个 PR 会自动生成并保持与本 Issue 的内容同步。

你不需要提供详细的答案或教学,但请保证题目可解。

基本信息

# 题目难度
difficulty: hard # medium / hard / extreme

# 题目标题
title: 康威生命游戏

# 题目标签
# tags: union, array # separate by comma

题目

康威生命游戏是一种有意思的游戏。
它的游戏进行在一个方格布上,每个方格或生或死,根据当前的方格布可推断出下一刻方格布的方格排列,推断规则如下:

  • 如果一个方格是死的,周围八个格有三个是活的,那它下一刻就被救活了;否则这个方格仍然是死的。
  • 如果一个方格是活的,周围八个格有两或三个是活的,那它下一刻就继续活着,否则要么因方格太少抑郁孤独而死,要么因方格太多被挤死。

这个游戏的胜利条件是你开心。只要你看你的方格布看得很开心,你就胜利了。

现在可以在 TS 中表示一盘如此的 $8 \times 8$ 康威生命游戏:

type Status = 'o' | 'x';
type Line = `${Status}${Status}${Status}${Status}${Status}${Status}${Status}${Status}`;
type LifeGame = [Line, Line, Line, Line, Line, Line, Line, Line];
type LifeGame0 = [
  'xxxxxxxx',
  'xxxxoxxx',
  'xxooxxxx',
  'xxoxxoox',
  'xxxxxxxx',
  'xxxxoxxx',
  'xxxooxxx',
  'xxxxxxxx',
];

其中, o 表示活着, x 表示死掉了;一个字符串表示一行,数组中有八个字符串表示有八行。
LifeGame0 表示一盘进行当中的生命游戏。
在本挑战中你不需要考虑边缘外的方格。

现在,希望你能设计一个康威生命游戏的计算器,给定游戏进行的时间和初始的方格布,推算出到时间时的方格布是什么样子。

题目模版

以下是给予挑战者开始做题的代码模版,在大部分情况下你只需要修改类型名称使其符合你的题目与判题测试,实现的部分保持 any 即可。

type Status = 'o' | 'x';
type Line = `${Status}${Status}${Status}${Status}${Status}${Status}${Status}${Status}`;
type LifeGame = [Line, Line, Line, Line, Line, Line, Line, Line];
type GotLifeGame<T extends number, B extends LifeGame> = any

判题测试

请为你的题目提供一些判题测试,你可以使用 @type-challenges/utils 中提供的一些工具进行判断。

import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<GotLifeGame<0, [
    'xxxxxxxx',
    'xxxxoxxx',
    'xxooxxxx',
    'xxoxxoox',
    'xxxxxxxx',
    'xxxxoxxx',
    'xxxooxxx',
    'xxxxxxxx',
  ]>, [
    'xxxxxxxx',
    'xxxxoxxx',
    'xxooxxxx',
    'xxoxxoox',
    'xxxxxxxx',
    'xxxxoxxx',
    'xxxooxxx',
    'xxxxxxxx',
  ]>>,
  Expect<Equal<GotLifeGame<20, [
   'xxxxxxxx',
    'xxoxxxxx',
    'xoxoxxxx',
    'xoxoxxxx',
    'xxoxxxxx',
    'xxxxxoox',
    'xxxxxoox',
    'xxxxxxxx',
  ]>, [
    'xxxxxxxx',
    'xxoxxxxx',
    'xoxoxxxx',
    'xoxoxxxx',
    'xxoxxxxx',
    'xxxxxoox',
    'xxxxxoox',
    'xxxxxxxx',
  ]>>,
  Expect<Equal<GotLifeGame<5, [
    'xxxxxxxx',
    'xxoxxxxx',
    'xxxoxxxx',
    'xoooxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
  ]>, [
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxoxoxxx',
    'xxxooxxx',
    'xxxoxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
  ]>>,
  Expect<Equal<GotLifeGame<3, [
    'xxxxxxxx',
    'xoxxxoxx',
    'xxxxoxxx',
    'xxooxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
  ]>, [
    'xxxxxxxx',
    'xxoooxxx',
    'xxxxxxxx',
    'xxoxoxxx',
    'xxxoxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
  ]>>,
  Expect<Equal<GotLifeGame<2, [
    'xxxxxxxx',
    'xxxxxxxx',
    'xxoxxxxx',
    'xxxoxxxx',
    'xxxooxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
  ]>, [
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxoxxxx',
    'xxoxoxxx',
    'xxoxoxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
  ]>>,
  Expect<Equal<GotLifeGame<10, [
    'xxxxxxxx',
    'xxxxxxxx',
    'xxoxxxxx',
    'xxxoxxxx',
    'xxxooxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
  ]>, [
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
    'xxxxxxxx',
  ]>>,
]
@E0SelmY4V E0SelmY4V added new-challenge Propose a new challenge, a PR will be auto generated zh-CN 简体中文 labels Jan 28, 2024
@github-actions github-actions bot linked a pull request Jan 28, 2024 that will close this issue
Copy link
Contributor

github-actions bot commented Jan 28, 2024

#31894 - PR 已更新

2024-01-28T10:10:40.871Z 在 Playground 中预览

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-challenge Propose a new challenge, a PR will be auto generated zh-CN 简体中文
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant