M+++"=1asmBa++'=0%'Va'a:1a!+|&=%"Vb"a0a0#~a$@"Vb0'
Try it online!Try it online!
Explanation:
M
is similar to python's eval
in recursiva. So, basically. we are building a string and evaluating it using M
. Let's say we input 20
the string(everything following M
) will be: =1a:1!+|&=%20a0a0#~a$@20
.
This is a recursiva function with parameter 20
passed into it and is recursive. The tail condition is given in =1a:1
which is saying for value of 1 simply returns 1. For other conditions we simply add the current number if it perfectly divides 20
(The number we are interested in) else add 0 +|&=%"Vb"a0a0
. The #~a$
part is making a call to the same function but with one decremented value ~a
since ~
is minus-one operator.
smBa++'=0%'Va'a:a!0' - Input to a; 20
s - sum up; 42
m - map with; [1, 0, 3, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]
Ba - Range; [1,2..20]
++'=0%'Va'a:a!0' - function, evaluates to 0 if param cannot divide a; [20]