【问题标题】:Print a chessboard without using loops, is it possible?不使用循环打印棋盘,有可能吗?
【发布时间】:2013-11-21 14:17:07
【问题描述】:

像这样:(理想情况下是 Java、Scala、C#,但任何成熟的计算机语言都可以)所以不是伪代码:

B W B W B W B W
W B W B W B W B
B W B W B W B W
W B W B W B W B
B W B W B W B W
W B W B W B W B
B W B W B W B W
W B W B W B W B

【问题讨论】:

  • printf("B W B W..\nW B...");。可以在 make 期间生成代码。使用循环...

标签: recursion functional-programming


【解决方案1】:

从技术上讲,我认为这很容易(伪代码):

function PrintFields(int index) {
  int x=index % 8;
  int y=index / 8;
  int bw=index % 2;
  print_at(x,y,(bw==0)?'B':'W');
  if (index<63) PrintFields(index+1);
}

问题是,为什么在地球上有人会这样做?

编辑

我忘记了结束条件,现在已经到位

【讨论】:

  • 不确定这是否可行。请仔细查看预期输出。在回答您的问题时,这是一个有趣的问题,所以 为什么在地球上没有
  • 请仔细查看预期输出。
  • 我确实看过预期的输出 - 请详细说明!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-23
  • 2020-09-11
相关资源
最近更新 更多