本文介绍了高尔夫球代码:将乘法表输出到控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我最近指出了一位有工作经验的学生写了一篇关于将乘法表转储到控制台的文章.它使用了一个嵌套的for循环,并将每个的步长值相乘.

I recently pointed a student doing work experience to an article about dumping a multiplication table to the console. It used a nested for loop and multiplied the step value of each.

这看起来像.NET 2.0方法.我想知道使用Linq和扩展方法,例如,要达到相同的结果需要多少行代码.

This looked like a .NET 2.0 approach. I was wondering, with the use of Linq and extension methods,for example, how many lines of code it would take to achieve the same result.

stackoverflow社区能应对挑战吗?

Is the stackoverflow community up to the challenge?

挑战:在控制台应用程序中,编写代码以生成一个表,如下例所示:

The challenge:In a console application, write code to generate a table like this example:


01 02 03 04 05 06 07 08 09
02 04 06 08 10 12 14 16 18
03 06 09 12 15 18 21 24 27
04 08 12 16 20 24 28 32 36
05 10 15 20 25 30 35 40 45
06 12 18 24 30 36 42 48 54
07 14 21 28 35 42 49 56 63
08 16 24 32 40 48 56 64 72
09 18 27 36 45 54 63 72 81

当这变成了与语言无关的代码争夺战时,我将与社区共同决定哪个是接受答案的最佳解决方案.

As this turned into a language-agnostic code-golf battle, I'll go with the communities decision about which is the best solution for the accepted answer.

关于表格的规范和格式有很多讨论,我故意添加了00格式,但原来只在这里使用双换行符,因为我不知道在创建时如何格式化文本帖子!

There's been alot of talk about the spec and the format that the table should be in, I purposefully added the 00 format but the double new-line was originally only there because I didn't know how to format the text when creating the post!

推荐答案

J -8个字符-24个字符正确的格式

J - 8 chars - 24 chars for proper format

*/~1+i.9

赠予:


1  2  3  4  5  6  7  8  9
2  4  6  8 10 12 14 16 18
3  6  9 12 15 18 21 24 27
4  8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81

此解决方案由@earl找到:

This solution found by @earl:

'r(0)q( )3.'8!:2*/~1+i.9

赠予:


01 02 03 04 05 06 07 08 09
02 04 06 08 10 12 14 16 18
03 06 09 12 15 18 21 24 27
04 08 12 16 20 24 28 32 36
05 10 15 20 25 30 35 40 45
06 12 18 24 30 36 42 48 54
07 14 21 28 35 42 49 56 63
08 16 24 32 40 48 56 64 72
09 18 27 36 45 54 63 72 81

这篇关于高尔夫球代码:将乘法表输出到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:49