Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Find n Niven Numbers

Python, 98 bytes from itertools import* f=lambda n:[*islice(filter(lambda k:k%sum(map(int,str(k)))==0,count(1)),n)] itertools.count() generates integer numbers starting from 1, filter() fil...

posted 2y ago by __blackjack__‭  ·  edited 2y ago by __blackjack__‭

Answer
#3: Post edited by user avatar __blackjack__‭ · 2022-08-24T15:04:03Z (over 2 years ago)
`list()` replaced by `[*…]`
  • # Python, 101 bytes
  • ```python
  • from itertools import*
  • f=lambda n:list(islice(filter(lambda k:k%sum(map(int,str(k)))==0,count(1)),n))
  • ```
  • * `itertools.count()` generates integer numbers starting from 1,
  • * `filter()` filters out the Niven numbers,
  • * `itertools.islice()` limits the result to `n` items,
  • * and `list()` collects the numbers in a list.
  • # Python, 98 bytes
  • ```python
  • from itertools import*
  • f=lambda n:[*islice(filter(lambda k:k%sum(map(int,str(k)))==0,count(1)),n)]
  • ```
  • * `itertools.count()` generates integer numbers starting from 1,
  • * `filter()` filters out the Niven numbers,
  • * `itertools.islice()` limits the result to `n` items,
  • * and `[*...]` collects the numbers in a list.
#2: Post edited by user avatar __blackjack__‭ · 2022-08-23T21:31:57Z (over 2 years ago)
Shortened import.
  • # Python, 113 bytes
  • ```python
  • from itertools import count,islice
  • f=lambda n:list(islice(filter(lambda k:k%sum(map(int,str(k)))==0,count(1)),n))
  • ```
  • * `itertools.count()` generates integer numbers starting from 1,
  • * `filter()` filters out the Niven numbers,
  • * `itertools.islice()` limits the result to `n` items,
  • * and `list()` collects the numbers in a list.
  • # Python, 101 bytes
  • ```python
  • from itertools import*
  • f=lambda n:list(islice(filter(lambda k:k%sum(map(int,str(k)))==0,count(1)),n))
  • ```
  • * `itertools.count()` generates integer numbers starting from 1,
  • * `filter()` filters out the Niven numbers,
  • * `itertools.islice()` limits the result to `n` items,
  • * and `list()` collects the numbers in a list.
#1: Initial revision by user avatar __blackjack__‭ · 2022-08-23T14:36:27Z (over 2 years ago)
# Python, 113 bytes

```python
from itertools import count,islice
f=lambda n:list(islice(filter(lambda k:k%sum(map(int,str(k)))==0,count(1)),n))
```

* `itertools.count()` generates integer numbers starting from 1,
* `filter()` filters out the Niven numbers,
* `itertools.islice()` limits the result to `n` items,
* and `list()` collects the numbers in a list.