Get list of elements that are divisible by 3 or 5 from 1 - 1000

后端 未结 6 572
北海茫月
北海茫月 2021-01-14 12:30

I\'m trying to write a functional approach in scala to get a list of all numbers between 1 & 1000 that are divisible by 3 or 5

Here is what I have so far :

6条回答
  •  鱼传尺愫
    2021-01-14 13:12

    (Range(3, 1000, 3) ++ Range(5, 1000, 5)).toSet.toList.sorted
    

    Sorted can be omitted.

提交回复
热议问题