[Question]
  [
My friend and I were working on a lab in our AP Computer Science class and decided to code golf one one the problems since we still had half the class free after we finished. Here is the question:
> 
> Given a number n, is n divisible by each of its digits?
> 
> 
> 
For example, 128 will pass this test- it is divisible by 1,2, and 8. Any numbers with a zero automatically disqualify the number. While you may use other languages and post solutions with them if you like, we are most interested in seeing how compact people can make the program in Java, as that is the language we use in the class. So far, we both have 51. Here is my current code:
```
public boolean dividesSelf(int n){for(int p=n;n%10>0;)n/=p%(n%10)>0?.1:10;return n<1;}
// 51 characters
// Breakdown:
// for(int p=n;         Saves one semicolon to put declaration into for loop
// n%10>0;)             Basic check-for-zero
// n/=                  Pretty simple, discarding one number off of n at a time
// p%(n%10)>0?          If p (the given value) is not divisible by n%10 (the current digit)...
// .1:10;               Divide by .1 (multiply by 10) so it fails the check next iteration. If it is divisible, divide by 10 to truncate the last digit
// return n<1           If the number was fully divisible, every digit would be truncated, and n would be 0. Else, there would still be non-zero digits.
```
## Requirements
The method signature can be whatever you want. Just count the function body. Make sure, though, that the method returns a boolean value and only passes in *one numeric* parameter (not a string).
The code must be able to pass all of these cases (in order to stay true to the directions of the original question, *only* boolean true and false values count if the language supports booleans. If and only if your language does not have boolean variables you may represent false with 0 and true with any nonzero integer (preferably 1 or -1):
```
128 -> true
 12 -> true
120 -> false
122 -> true
 13 -> false
 32 -> false
 22 -> true
 42 -> false
212 -> true
213 -> false
162 -> true
204 -> false
```
Also, we didn't count whitespace, so feel free to do the same, unless the whitespace is essential to the working of the program (so newlines in Java don't count, but a single space between `int` and `x=1` does count.)
Good luck!
  
[Answer]
# Perl 6, 13
```
sub golf($_) {
   $_%%.comb.all
}
```
Uses the implicit variable `$_` — `$_ %% .comb.all` is equivalent to `$_ %% all($_.comb)`. `%%` is the "is divisible" operator, and `comb` with no additional argument returns a list of the characters in a string. As an example, if the argument is 123, then the function evaluates
```
123 %% all(123.comb)
```
which is
```
123 %% all(1, 2, 3)
```
junction autothreading makes it
```
all(123 %% 1, 123 %% 2, 123 %% 3)
```
which is
```
all(True, False, True)
```
which is false in boolean context because it's an "all" junction and clearly not all of its elements are true.
It should be possible to coerce the return value to `Bool` and hide the junction-ness from callers by making the function signature `sub golf($_ --> Bool())`, but coercions in function signatures don't work yet in Rakudo. The return value is still correctly true or false, it's just not `True` or `False`.
[Answer]
# C# and System.Linq - 26 / 40
Per the rules, not counting the method declaration itself.
```
bool dividesSelf(int i) { 
    return(i+"").All(d=>i%(d-48d)<1);
}
```
Showing that once again, C# is the superior choice when Java is under consideration... I kid, I kid!
Unfortunately, this function (and many in other answers) will not produce correct results for negative input. We can fix this, but the solution loses a lot of its charm (and grows to 46 characters in length):
```
return(i+"").All(d=>d>48&&i%(d-48)==0||d==45);
```
**Edit**: shaved off one character with Tim's suggestion.
**Edit**: with the introduction of [expression-bodied members](https://docs.microsoft.com/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members) in C# 6, we can pare this down further by cutting out the `return`:
```
bool dividesSelf(int i) =>
    (i+"").All(d=>i%(d-48d)<1);
```
for a total of 26 characters (in my opinion, the `=>` should not be included any more than braces would be). The version handling negative numbers can be similarly shortened.
[Answer]
## APL (~~13~~ 11)
 (apparently the brackets don't count)
```
{0∧.=⍵|⍨⍎¨⍕⍵}
```
Explanation:
* `⍎¨⍕⍵`: evaluate each character in the string representation of `⍵`
* `⍵|⍨`: for each of those, find the modulo of it and `⍵`
* `0∧.=`: see whether all of those are equal to `0`
Testcases:
```
      N,[.5] {0∧.=⍵|⍨⍎¨⍕⍵} ¨ N←128 12 120 122 13 32 22 42 212 213 162 204
128 12 120 122 13 32 22 42 212 213 162 204
  1  1   0   1  0  0  1  0   1   0   1   0
```
[Answer]
## Python 2: 43 chars
```
f=lambda n:any(n%(int(d)or.3)for d in`n`)<1
```
Checks whether the number has any nonzero remainders modulo its digits, and outputs the negation of that. Zero digits are handled strangely: since computing `%0` causes an error, digits of `0` are replaced with `.3`, which seems to always give a nonzero result due to floating point inaccuracies.
The function body is 32 chars.
[Answer]
## Perl - 27 bytes
```
sub dividesSelf{
    $_=pop;s/./!$&||$_%$&/ger<1
}
```
Not counting the function signature, as instructed.
**Sample Usage:**
```
use Data::Dump qw(dump);
for $i (128, 12, 120, 122, 13, 32, 22, 42, 212, 213, 162, 204) {
  printf "%3d -> %s\n", $i, dump(dividesSelf $i);
}
```
**Sample Output:**
```
128 -> 1
 12 -> 1
120 -> ""
122 -> 1
 13 -> ""
 32 -> ""
 22 -> 1
 42 -> ""
212 -> 1
213 -> ""
162 -> 1
204 -> ""
```
---
Addressing the problem specification: "Only boolean true and false values count. Truthy/falsey values do *not* count."
```
use Data::Dump qw(dump);
dump(1 == 1);
dump(0 == 1);
```
Outputs:
```
1
""
```
'True' and 'False' are defined as `1` and `""`.
**Erratum:**  
As Brad Gilbert [rightly points out](https://codegolf.stackexchange.com/q/41902#comment97962_41906), perl defines *true* as a scalar which is both the integer `1` and the string `"1"` simultaneously, and *false* as a scalar which is both the integer `0` and the string `""` simultaneously.
[Answer]
# CJam, ~~11~~ 10 bytes
```
{
    _Ab:df%:+!
}:F;
```
This defines a function named `F` and discards the block from the stack.
[Try it online.](http://cjam.aditsu.net/#code=%7B_Ab%3Adf%25%3A%2B!%7D%3AF%3B%20e%23%20Define%20function.%0A%5Bq~%5D%20%20%20%20%20%20%20%20%20%20%20%20e%23%20Read%20input.%0A%7BF%7D%25%20%20%20%20%20%20%20%20%20%20%20%20e%23%20Execute%20F%20for%20each%20integer.%0Ap%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e%23%20Print.&input=128%2012%20120%20122%2013%2032%2022%2042%20212%20213%20162%20204)
### Test cases
```
$ cjam <(echo '{_Ab:df%:+!}:F;[128 12 120 122 13 32 22 42 212 213 162 204]{F}%p')
[1 1 0 1 0 0 1 0 1 0 1 0]
```
### How it works
```
_      " Copy the integer on the stack.                                          ";
Ab     " Push the array of its digits in base 10.                                ";
:d     " Cast each digit to Double.                                              ";
f%     " Take the integer on the stack modulus each of its digits.               ";
:+     " Add the results.                                                        ";
!      " Push the logical NOT of the sum.                                        ";
```
[Answer]
# JavaScript ES6, ~~39~~ ~~32~~ 28 bytes
```
v=>[...""+v].every(x=>v%x<1)
```
Thanks core1024 for the suggestion to replace `(""+v).split("")` with `[...""+v]`, and openorclose for suggesting the use of `every` function.
The answer currently doesn't contain one bit of my code :O
### Previous solution
```
v=>[...""+v].filter(x=>v%x|!+x)==""
```
`==""` is not a valid way to check if an array is empty, since `[""]==""` returns `true`, but the array is guarantee to contain non-empty string, so it works here.
The rest are quite standard shorthand type conversion in JavaScript.
[Answer]
## Java 8, 46 Bytes (method body)
Using [Jeroen Mostert](https://codegolf.stackexchange.com/a/41918/21777)'s converting to double trick.
```
public static boolean dividesSelf(int n) {
    return(""+n).chars().allMatch(x->n%(x-48d)<1);
}
```
[Answer]
# Pyth, 12 bytes
```
!f|!vT%vzvTz
```
This filters the characters in the string for being either zero (`!vT`) or not dividing the input (`%vzvT`), then takes the logical not of the resulting list.
[Try it here.](http://isaacg.scripts.mit.edu/pyth/index.py)
[Answer]
# Ruby, 44 bytes (function body: 37)
Probably has potential to be golfed further.
```
f=->n{n.to_s.chars.all?{|x|x>?0&&n%x.hex<1}}
```
Input taken through function `f`. Example usage:
```
f[128] # => true
f[12]  # => true
f[120] # => false
...
```
[Answer]
# Python - ~~59~~ ~~50~~ ~~49~~ 47 bytes
```
f=lambda n:all(c>'0'and 0==n%int(c)for c in`n`)
```
I'm sure there's a faster way... oh well.
*Edit* - Thanks to FryAmTheEggman for the golfing tips.
*Edit 2* - FryAmTheEggman may as well have written this at this point, oops
*Edit 3* - Hands up if you didn't even know genexps were a thing. ...Just me?
[Answer]
## [Pyth](https://github.com/isaacg1/pyth) 11
```
!f%Q|vT.3`Q
```
This combines [@isaacg's](https://codegolf.stackexchange.com/a/41905/31625) and [@xnor's](https://codegolf.stackexchange.com/a/41915/31625) answers. It filters out digits from the input by checking the value of `input % (eval(current_digit) or .3)`. Then it checks if the resulting string is empty or not.
Came across another couple same-length variants:
```
!f%Q|T.3jQT
!f|!T%QTjQT
```
[Try it online.](http://isaacg.scripts.mit.edu/pyth/index.py)
[Answer]
# Bash + coreutils, 44 bytes
The full function definition is:
```
f()((`tr 0-9 \10<<<$1``sed "s/./||$1%&/g"<<<$1`))
```
I'm not sure how to score this as normally shell functions use a single set of `{}` or `()` to contain the function body. I found here I could also use double `(())` to contain the function body which causes an arithmetic expansion which is what I need here. So for now I am counting just one pair of those brackets - further discussion of this is welcome.
### Output:
```
$ for i in 128 12 120 122 13 32 22 42 212 213 162 204; do f $i; printf "%d " $?; done
1 1 0 1 0 0 1 0 1 0 1 0 $
$
```
[Answer]
# J - 14 char
The function body is the portion after the `=:`. If we want to minimize the character count for the whole function, that's the 15 char `*/@(0=,.&.":|])`.
```
f=:0*/@:=,.&.":|]
```
`,.&.":` is the shortest way in J to expand as number into a list of its decimal digits: convert to string, separate the digits, and convert each digit back into a number. `,.&.":|]` takes the input number (`]`) modulo (`|`) those digits. `0*/@:=` returns true if all the results were 0, else gives a false.
```
   f 162
1
   f every 204 212 213
0 1 0
```
[Answer]
# Java - ~~121~~ ~~102~~ ~~97~~ ~~79~~ 78 bytes
I just *know* this will get clobbered later. Oh well.
```
boolean b(int a){int m=10,j,t=1;for(;m<a*10;m*=10){j=10*(a%m)/m;if(j==0||a%j>0)t=0;}return t>0;}
```
I'll be back.
[Answer]
## Julia 32 25 23
### Improved using digits
Also fixes problem with negative numbers
```
selfDivides(x)=sum(x%digits(x).^1.)==0
```
### Old method
All digits divide if the sum of all the remainders is 0. Like others, has a problem with negative numbers.
```
selfDivides(x)=sum(x.%(Float64["$x"...]-48))==0
```
## Output
```
[selfDivides(x) for x in [128,12,120,122,13,32,22,42,212,213,162,204]]
12-element Array{Any,1}:
  true
  true
 false
  true
 false
 false
  true
 false
  true
 false
  true
 false
```
### Improved method also handles BigInt
```
selfDivides(BigInt(11111111111111111111111111111111111111112))
true
```
however
```
selfDivides(BigInt(11111111111111111111111111111111111111113))
false
```
because 
```
BigInt(11111111111111111111111111111111111111113) %3
1
```
[Answer]
# Haskell - 100 54 38
```
f x=all(\y->y>'0'&&x`mod`read[y]<1)$show x
```
Still learning, critiques appreciated
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/wiki/Commands), 3 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
SÖP
```
Only `1` is [truthy](https://codegolf.meta.stackexchange.com/a/2194/52210) in 05AB1E, so this will output `1` if the input-integer is divisible by each of its digits.
For falsey test cases it either outputs `0`, or a multiple of the input if it contains `0`s (due to division by zero errors). If you want a distinct falsey output of `0`, you can add a trailing `Θ` (`== 1` builtin).
[Try it online](https://tio.run/##MzBNTDJM/f8/@PC0gP//DY0sAA) or [verify all test cases](https://tio.run/##MzBNTDJM/V9Waa@k8KhtkoKSfaXL/@DD0wL@6/yPNjTSMTLSMQRjCx1DMyAXKGRqbm6qY2isY2ykYwKSMdAxMjAByhjrGBoYGMYCAA).
**Explanation:**
```
S    # Convert the (implicit) input-integer to a list of digits
 Ö   # Check for each digit if it evenly divides the (implicit) input-integer
     # (results in 1 for truthy; 0 for falsey; and itself for division by zero errors)
  P  # Take the product of this list to check if all are truthy
     # (after which it is output implicitly as result)
```
[Answer]
# CJam, 15 bytes
```
{_Abf{_g{%}*}:|!}
```
This is a block, the closest thing to a function in CJam. I'm only counting the body (i.e. omitting the braces). You can use it as follows:
```
128{_Abf{_g{%}*}:|!}~
```
Or if you want to test a series of inputs, you can do
```
[128 12 120 122 13 32 22 42 212 213 162 204]{{_Abf{_g{%}*}:|!}~}%
```
The block leaves `0` (falsy) or `1` (truthy) on the stack to indicate the result. (CJam doesn't have a Boolean type.)
[Test it here.](http://cjam.aditsu.net/)
Explanation:
```
_               "Duplicate input.";
 Ab             "Get base-10 digits.";
   f{      }    "This maps the block onto the list of digits, supplying the input each time.";
     _g         "Duplicate digit, get signum S (0 or 1).";
       { }*     "Repeat this block S times.";
        %       "Take input modulo digit.";
                "This leaves an array of zeroes for divisible digits, non-zeroes
                 for non-divisible digits, and non-zero junk for zeroes.";
            :|  "Fold OR onto this list. One could also sum the list with :+";
              ! "Logical NOT. Turns 0 into 1, and non-zero values into 0.";
```
# Alternative, also 15 bytes
```
{:XAb{X\_X)?%},!}
```
Explanation
```
:X              "Store input in X.";
  Ab            "Get base-10 digits.";
    {       },  "Filter this list by the result of the block.";
     X\         "Push another copy of X, swap with digit.";
       _        "Duplicate digit.";
        X)      "Push X+1.";
          ?     "Select digit itself or X+1, depending on whether digit is 0 or not.";
           %    "Take modulo. X%(X+1) will always be nonzero for positive integers.";
              ! "Logical NOT. Turns an empty list into 1 and a non-empty list into 0.";
```
[Answer]
# CJam, 15 bytes
```
{_Abf{_{%}1?}1b!}
```
`{}` is the closest thing to a function in CJam. I am just counting the body of the function
Use it like this:
```
128{_Abf{_{%}1?}1b!}~
```
To get either `1` (if the number is divisible) or `0` (if the number is not divisible by its digits).
[Try it online here](http://cjam.aditsu.net/)
**Explanation**
```
_Ab                "Copy the number and split it to its digits";
   f{      }       "For each digit, run this code block on the number";
     _{%}1?        "If the digit is 0, put 1, otherwise perform number modulus digit";
            1b     "We now have an array of modulus corresponding to each digit. Sum it up";
              !    "Negate the sum. If all digits were divisible, sum of modules will be"
                   "0, thus answer should be 1 and vice versa";
```
[Answer]
# C89, 43 bytes
```
unsigned char d(int n, int c) {
        int a=n%10;return!n||a&&!(c%a)&&d(n/10,c);
}
```
C89 doesn't have a boolean type. Hope that works.
Also I used a second parameter to pass a copy of the original number through the stack, but the definition can be anything. To get the correct result you just have to call the function with the same value for both parameters (`d(128, 128)`).
**EDIT:** Applied suggested edits by an anonymous user
[Answer]
# C11 - 44 Bytes in function body
Another C version, non recursive and without a floating point exception.
```
bool digit_multiple(int i)
{
    for(int n=i;i%10&&n%(i%10)<1;i/=10);return!i;
}
```
This will also work in C++, Java, and most other C-like languages.
Edited to include the improvement of primo's comment.
[Answer]
# C / C++, 58 bytes (44 in body)
**Invokes Undefined Behaviour** (see comments) 
```
int d(int i){int j=i;while(i&&!(j%(i%10)))i/=10;return!i;}
```
`true` and `false` **are** 1 and 0, but feel free to add one character to the signature to return a `bool`.
And for fun, a recursive version which is smaller if you allow calls of the form `r(128,128)`
**Edit**: Now disallowed by the rules:
## C / C++, 53 bytes (33 in body)
```
int r(int i,int j){return!i||!(j%(i%10))&&r(i/10,j);}
```
[Answer]
# PHP: 45 Characters
The character count is for the body of the function.
It is necessary to only pass the first parameter. 
```
function t($n, $k=true, $s='str_split'){foreach($s($n)as$b)$k=$k&&$n%$b===0;return$k;}
```
[Answer]
## R: ~~72~~ ~~67~~ 65
The function
```
f<-function(a)!(anyNA(a%%(d=as.double(strsplit(paste0(a),"")[[1]])))|sum(a%%d))
```
Thanks to @AlexA and @plannapus for the savings
Test run
```
i=c(128,12,120,122,13,32,22,42,212,213,162,204)
for(a in i){print(f(a))}
[1] TRUE
[1] TRUE
[1] FALSE
[1] TRUE
[1] FALSE
[1] FALSE
[1] TRUE
[1] FALSE
[1] TRUE
[1] FALSE
[1] TRUE
[1] FALSE
```
[Answer]
# GNU Awk: 53 characters
The counted part:
```
for(;++i<=split($1,a,//);)r=r||!a[i]||v%a[i];return!r
```
The entire function:
```
function self_divisible(v, i, r)
{
    for (; ++i <= split($1, a, //); )
        r = r || ! a[i] || v % a[i]
    return ! r
}
```
As Awk has no boolean values, returns 1 tor true and 0 for false.
[Answer]
# JavaScript (ES6) 30
Function with one numeric parameter. Using % and subtraction, no need to special case '0' because 0%0 is NaN in JavaScript.
*Edit* Saved 1 char thx DocMax
```
F=n=>[for(d of t=n+'')t-=n%d]&&t==n 
```
Just for fun, abusing the rule about not counting function signature, 4
```
Check=(n,t=n+'',q=[for(d of t)n-=t%d])=>t==n
```
**Test** In FireFox/FireBug console
```
console.log([128, 12, 120, 122, 13, 32, 22, 42, 212, 213, 162, 204]
.map(x=>+x + ' -> ' + F(x)).join('\n'))
```
*Output*
```
128 -> true
12 -> true
120 -> false
122 -> true
13 -> false
32 -> false
22 -> true
42 -> false
212 -> true
213 -> false
162 -> true
204 -> false
```
[Answer]
# PHP: 85 bytes (64 bytes on the body)
For this function to work, simply pass a string or a number.
`0` will correctly return false.
The code:
```
function f($n,$i=0){for($n.='';$n[$i]&&$t=!($n%$n[$i++]););return$t&&$i==strlen($n);}
```
Please, DO NOT SET THE 2ND PARAMETER!
# Javascript: 76 bytes (61 bytes on the body)
This is a rewrite of the previous function.
Not much changed between both versions.
Here is the code:
```
function f(n){for(i=0,n+='';n[i]/1&&(t=!(n%n[i++])););return t&&i==n.length}
```
---
# Polyglot: Javascript+PHP 187 ~~217~~ bytes (~~76~~ 84 bytes without boilerplate):
Why I made it?
Because of reason and maybe because I can!
~~Just ignore the error on PHP: it works anyway!~~  
No longer needed, this was fixed by removing 3 bytes.
Here is the masterpiece:
```
if('\0'=="\0"){function strlen($s){return $s['length'];}}
function toString(){return'';}
function f($n){for($i=0,$n=$n.toString();$n[$i]/1&&($t=!($n%$n[$i++])););return $t&&$i==strlen($n);}
```
You can run this code both on your console and on a PHP interpreter!
---
Old version:
```
if('\0'=="\0"){function strlen($s){return $s['length'];}}
function s($s){return('\0'=="\0")?$s+'':str_replace('','',$s);}
function f($n,$i){for($i=0,$n=s($n);$n[$i]/1&&($t=!($n%$n[$i++])););return $t&&$i==strlen($n);}
```
[Answer]
# Octave, 33 (39 including function setup)
Using numeric-to-matrix conversion:
```
f=@(a)sum(mod(a./(num2str(a)-48),1))==0
```
Divide number elementwise by matrix X, where X is made by converting number to string and subtracting 48 to go from ASCII values to numbers again. Take modulo 1 to get decimal part of each division, confirm that all of these are zero (if any are NaN because of /0, the sum will be NaN and hence not zero).
Sample input using www.octave-online.net:
```
f=@(a)sum(mod(a./(num2str(a)-48),1))==0
for j=[128,12,120,122,13,32,22,42,212,213,162,204]
f(j)
end
```
Output:
```
ans =  1
ans =  1
ans = 0
ans =  1
ans = 0
ans = 0
ans =  1
ans = 0
ans =  1
ans = 0
ans =  1
ans = 0
```
[Answer]
# MATLAB - 39 characters
```
function [b] = dividesSelf(i)
b=all(~mod(i,sscanf(num2str(i),'%1d')))
end
```
]