且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

您如何找到所有数字的列表,这些数字是2、3和5的幂的倍数?

更新时间:2023-02-10 20:57:19

只有5的幂的原因是Haskell尝试评估a = 2 ^ 0和b = 3 ^ 0的所有可能c,并且仅当完成后,结果为a = 2 ^ 0和b = 3 ^ 1.因此,这种方式只能构造如下这样的有限列表:
[a * b * c |a<-地图(2 ^)[0..n],b<-地图(3 ^)[0..n],c<-地图(5 ^)[0..n]] 代码>
给定n.

The reason why there are only powers of 5 is that Haskell tries to evaluate every possible c for a = 2^0 and b = 3^0 and only when it is finished it goes for a = 2^0 and b = 3^1. So this way you can only construct a finite list like this:
[ a * b * c | a <- map (2^) [0..n], b <- map (3^) [0..n], c <- map (5^) [0..n] ]
for a given n.