Am I divisible by double the sum of my digits?
JavaScript (ES6), 31 29 27 bytes
Takes input as a string. Returns zero for truthy and non-zero for falsy.
n=>n%eval([...n+n].join`+`)
Commented
n => n % eval([...n + n].join`+`)
n => // take input string n -> e.g. "80"
n + n // double the input -> "8080"
[... ] // split -> ["8", "0", "8", "0"]
.join`+` // join with '+' -> "8+0+8+0"
eval( ) // evaluate as JS -> 16
n % // compute n % result -> 80 % 16 -> 0
Test cases
let f =
n=>n%eval([...n+n].join`+`)
console.log('[Truthy]');
console.log(f("80"))
console.log(f("100"))
console.log(f("60"))
console.log(f("18"))
console.log(f("12"))
console.log('[Falsy]');
console.log(f("4"))
console.log(f("8"))
console.log(f("16"))
console.log(f("21"))
console.log(f("78"))
console.log(f("110"))
console.log(f("111"))
console.log(f("390"))
Neim, 3 bytes
ᚫ
Explanation:
Implicitly convert to int array and sum the digits
ᚫ Double
Is it a divisor of the input?
Try it online!
Detailed version
C#, 46 bytes
using System.Linq;n=>n%(n+"").Sum(c=>c-48)*2<1
Full/Formatted version:
using System;
using System.Linq;
class P
{
static void Main()
{
Func<int, bool> f = n => n % (n + "").Sum(c => c - 48) * 2 < 1;
Console.WriteLine(f(80));
Console.WriteLine(f(100));
Console.WriteLine(f(60));
Console.WriteLine();
Console.WriteLine(f(16));
Console.WriteLine(f(78));
Console.WriteLine(f(390));
Console.ReadLine();
}
}