Creating Set in F# with elements from 1111 to 6666

风格不统一 提交于 2019-12-25 18:54:27

问题


How do i create a Set in F# with elements from 1111 to 6666 without any values being 0, 7 or higher.

E.g. [1111,1112,1113,1114,1115,1116,1121] I'd like to make it a set.

Thanks in advance


回答1:


You can use a sequence comprehension:

let values = seq {
    for i in 1110 .. 10 .. 6660 do
      for j in 1 .. 6 do
        yield i + j
    }

and create a set using Set.ofSeq e.g.

let s = Set.ofSeq values



回答2:


There must be an easier way than:

let values = seq {
for a in 1000 .. 1000 .. 6000 do
for b in 100 .. 100 .. 600 do
for c in 10 .. 10 .. 60 do
for d in 1 .. 6 do
    yield a + b + c + d
}


来源:https://stackoverflow.com/questions/40469424/creating-set-in-f-with-elements-from-1111-to-6666

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!