插图 引用 同一行两个插图_数学身份的优雅LED插图

插图 引用 同一行两个插图

by Chris Lam

克里斯·林(Chris Lam)

数学身份的优雅LED插图 (An elegant LED illustration of a mathematical identity)

I am a big fan of science toys. I have been looking for one that combines the elegance of math and programming for a while. However, there was not much success in the search. So, I decided to make one myself.

我是科学玩具的忠实粉丝。 我一直在寻找一种结合了数学和编程优雅的软件。 但是,搜索没有太大的成功。 所以,我决定自己做一个。

Here is a demo. The flashing LEDs are used to illustrate a mathematical identity visually.

这是一个演示。 闪烁的LED用于可视地说明数学身份。

数学 (Math)

The mathematical identity is the following. The left side of the equation is an arithmetic sum from 1 to n-1 and the right side of the equation is “n choose 2”, the number of unique ways to choose 2 items from n items.

数学上的恒等式如下。 等式的左侧是从1到n-1的算术和,等式的右侧是“ n select 2 ”,这是从n个项目中选择2个项目的唯一方式的数量。

It is not the identity itself that is elegant, but the visual proof itself. Let’s look at the diagram below. There are n=4 green dots in the illustration.

优雅本身不是身份本身,而是视觉证明本身。 让我们看下面的图。 插图中有n = 4个绿色的点。

For every two green dots on the bottom row, there is always a unique red dot in the triangle above that corresponds to them. That red dot is the tip of an equilateral triangle with the base specified by the green dots.

对于底行的每两个绿点,在上方的三角形中始终存在一个与之对应的唯一红点。 该红点是等边三角形的尖端,其底点由绿点指定。

Therefore, the number of ways to choose 2 green dots out of n green dots is equal to the sum of the red dots, 1 +2 + 3 + … + (n-1).

因此,从n个绿色点中选择2个绿色点的方法数量等于红色点的总和1 +2 + 3 +…+( n -1)。

In this case, it is 1 + 2 + (4 –1) = 6.

在这种情况下,它是1 + 2 +(4 –1)= 6。

This observation was originally made by Loren C. Larson in this article.

此观察最初由Loren C. Larson在本文中进行

程式设计 (Programming)

While it is easy to trace the red dot from the green dots visually, it is more fun and challenging to specify the relationship in code.

虽然很容易在视觉上从绿点中追踪红点,但是在代码中指定关系更加有趣和具有挑战性。

Let us assume that we know the indices of the green dots (say, i and j). The programming challenge is to specify the corresponding index of the red dot that forms the equilateral triangle with the green dots.

让我们假设我们知道绿点的索引(例如,i和j)。 编程上的挑战是指定与绿点形成等边三角形的红点的相应索引。

It looks difficult at first glance.

乍看起来似乎很困难。

But the problem can be simplified a lot when we tweak the way that we label the red dots. We can label the red dots from bottom-up instead of top-down.

但是,当我们调整标记红点的方式时,可以大大简化该问题。 我们可以从下至上而不是从上至下标记红点。

With that indexing scheme, we can then specify the index of the red dots by the following formula.

使用该索引方案,然后可以通过以下公式指定红点的索引。

Here is the complete code used to flash the LEDs using Arduino.

这是用于使用Arduino闪烁LED的完整代码。

电子产品 (Electronics)

I solder the LEDs on a board and connect the LEDs to Arduino output pins through 1k resistors. It is very important to use the resistors because they protect the LEDs.

我将LED焊接在板上,然后通过1k电阻将LED连接到Arduino输出引脚。 使用电阻非常重要,因为它们可以保护LED。

The connection is as follows.

连接如下。

And when you put them together and load the software to Arduino, it will start flashing like below.

当您将它们放在一起并将软件加载到Arduino时,它将开始闪烁,如下所示。

Hope you enjoy this gadget!

希望您喜欢这个小工具!

翻译自: https://www.freecodecamp.org/news/an-elegant-led-illustration-of-a-mathematical-identity-de88ee88c963/

插图 引用 同一行两个插图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值