Comments on Find n Niven Numbers
Parent
Find n Niven Numbers
Challenge
A Niven number is a positive integer which is divisible by the sum of its digits.
For example, 81 -> 8+1=9 -> 81%9=0
.
Your task is to find the first n
Niven numbers, given n
.
Tests
Reference implementation(takes input)
first 16 values:
0 => 1
1 => 2
2 => 3
3 => 4
4 => 5
5 => 6
6 => 7
7 => 8
8 => 9
9 => 10
10 => 12
11 => 18
12 => 20
13 => 21
14 => 24
15 => 27
Scala, 52 bytes ```scala S …
2y ago
Vyxal, 4 bytes ``` ‡∑Ḋȯ ``` …
2y ago
Python, 98 bytes ```python …
2y ago
x86-64 machine code, 36 bytes …
2y ago
Ruby, 56 bytes p (1..).lazy …
2y ago
Factor, 147 bytes ``` USIN …
2y ago
Japt, 10 bytes ÈvXìx}jU …
2y ago
Post
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()
filters out the Niven numbers, -
itertools.islice()
limits the result ton
items, - and
[*...]
collects the numbers in a list.
2 comment threads