Skip to content

Latest commit

 

History

History
57 lines (37 loc) · 1.65 KB

day6.md

File metadata and controls

57 lines (37 loc) · 1.65 KB

Challenge 6 (26/04/2020): Niven Numbers

Specification

A niven number is a non-negative number that is divisible by the sum of its digits.

Write a function/method named niven which prints all the niven numbers from 0 to 100 inclusive, each on their own line. The function needs to compute the solution, i.e., it is not acceptable to use any pre-computed data structure or solution.

Source: https://code-golf.io/niven-numbers

Solutions

(21) APL by Hugo

niven0=|110¯1

You can read about this here or try it online.

(31) APL by Rui

niven{/0=|{+/¨}¨}100

(54) JavaScript by Restivo

niven=_=>{for(n=0;n<101;n++)n%(n/10+n%10|0)||print(n)}

try it online

(62) Python by Mafalda

def niven():[print(n)for n in range(1,101)if n%(n//10+n%10)<1]

(66) Haskell by Mafalda

niven=[x|x<-[1..100],x`mod`(sum(map(\x->read[x]::Int)(show x)))<1]

(72) Python by António

def niven():[print(i)for i in range(1,101)if not i%sum(map(int,str(i)))]

(73) Python by Duarte

def niven():[print(i)for i in range(1,101)if i%sum([*map(int,str(i))])<1]

Try it online!