Post History
Scala, 52 bytes Stream.from(1).filter(x=>x%(x+"":\0)(_+_-48)<1).take Try it in Scastie! Woo, 3 deprecation warnings! (okay, one of them could be fixed but I like to live dangerously) St...
Answer
#2: Post edited
- # Scala, 52 bytes
- ```scala
- Stream.from(1).filter(x=>x%(x+"":\0)(_+_-48)<1).take
- ```
- [Try it in Scastie!](https://scastie.scala-lang.org/oMucQkxdSB23HjP0mYI8Pg)
Woo, 3 deprecation warnings! (okay, one of them could be fixed but I like to live dangerously)
- # Scala, 52 bytes
- ```scala
- Stream.from(1).filter(x=>x%(x+"":\0)(_+_-48)<1).take
- ```
- [Try it in Scastie!](https://scastie.scala-lang.org/oMucQkxdSB23HjP0mYI8Pg)
- Woo, 3 deprecation warnings! (okay, one of them could be fixed but I like to live dangerously)
- `Stream.from(1)` constructs an infinite list of positive integers. Then we `filter` the `x`'s that are Niven numbers. `(x+"":\0)(_+_-48)` finds the sum of the `x`'s digits. A clearer way to write that would be `x.toString.foldRight(0)((sum, char) => sum + char.toInt - '0'.toInt)`. At the end, only the first `n` Niven numbers are `take`n from the infinite list.