[Question]
  [
# Challenge description
A **Smith number** is a **composite** number whose sum of digits is equal to the sum of sums of digits of its prime factors. Given an integer `N`, determine if it's a Smith number or not.
The first few Smith numbers are `4`, `22`, `27`, `58`, `85`, `94`, `121`, `166`, `202`, `265`, `274`, `319`, `346`, `355`, `378`, `382`, `391`, `438` (sequence [A006753](https://oeis.org/A006753) in OEIS).
# Sample input / output
```
18: False (sum of digits: 1 + 8 = 9; factors: 2, 3, 3; sum of digits of factors: 2 + 3 + 3 = 8)
22: True
13: False (meets the digit requirement, but is prime)
666: True (sum of digits: 6 + 6 + 6 = 18; factors: 2, 3, 3, 37; sum of digits of factors: 2 + 3 + 3 + 3 + 7 = 18)
-265: False (negative numbers can't be composite)
0: False (not composite)
1: False (not composite)
4937775: True
```
# Notes
* Your code can be a function (method) or a full working program,
* Instead of words like `True` and `False`, you can use any truthy and falsy values, as long as it's clear what they are,
* This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge, so make your code as short as possible!
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~12~~ 11 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
√Üf·∏ü»Ø.DF≈ºDSE
```
Returns **1** for Smith numbers and **0** otherwise. [Try it online!](http://jelly.tryitonline.net/#code=w4Zm4bifyK8uREbFvERTRQ&input=&args=NDkzNzc3NQ) or [verify all test cases](http://jelly.tryitonline.net/#code=w4Zm4bifyK8uREbFvERTRQotMTAwMHI0Mzg7NjY2OzQ5Mzc3NzXDh8OQZkc&input=VGhpcyBmaWx0ZXJzIFstMTAwMCwgLi4uLCA0MzgsIDY2NiwgNDkzNzc3NV0gYnkgdGhlIGxpbmsgb24gdGhlIGZpcnN0IGxpbmUsIGtlZXBpbmcgb25seSBlbGVtZW50cyBmb3Igd2hpY2ggdGhlIGxpbmsgcmV0dXJucyBhIHRydXRoeSB2YWx1ZS4).
### Background
`√Üf` (prime factorization) and `D` (integer-to-decimal) are implemented so that `P` (product) and `·∏å` (decimal-to-integer) constitute left inverses.
For the integers **-4** to **4**, `√Üf` returns the following.
```
-4 -> [-1, 2, 2]
-3 -> [-1, 3]
-2 -> [-1, 2]
-1 -> [-1]
 0 -> [0]
 1 -> []
 2 -> [2]
 3 -> [3]
 4 -> [2, 2]
```
For the numbers **-10, -1, -0.5, 0, 0.5, 1, 10**, `D` returns the following.
```
-11   -> [-1, -1]
-10   -> [-1, 0]
 -1   -> [-1]
 -0.5 -> [-0.5]
  0   -> [0]
  0.5 -> [0.5]
  1   -> [1]
 10   -> [1, 0]
 11   -> [1, 1]
```
### How it works
```
√Üf·∏ü»Ø.DF≈ºDSE  Main link. Argument: n (integer)
√Üf           Yield the prime factorization of n.
  ·∏ü          Filter; remove n from its prime factorization.
             This yields an empty array if n is -1, 0, 1, or prime.
   »Ø.        If the previous result is an empty array, replace it with 0.5.
     D       Convert all prime factors to decimal.
      F      Flatten the result.
        D    Yield n in decimal.
       ≈º     Zip the results to both sides, creating a two-column array.
         S   Compute the sum of each column.
             If n is -1, 0, 1, or prime, the sum of the prime factorization's
             digits will be 0.5, and thus unequal to the sum of the decimal array.
             If n < -1, the sum of the prime factorization's digits will be
             positive, while the sum of the decimal array will be negative.
          E  Test both sums for equality.
```
[Answer]
# Python 2, ~~122~~ ~~115~~ ~~110~~ 106 bytes
```
n=m=input()
s=0
for d in range(2,n):
 while n%d<1:n/=d;s+=sum(map(int,`d`))
print n<m>s==sum(map(int,`m`))
```
Saved 4 bytes thanks to Dennis
[Try it on ideone.com](https://ideone.com/R3ly0w)
### Explanation
Reads a number on stdin and outputs `True` if the number is a Smith number or `False` if it is not.
```
n=m=input()                  # stores the number to be checked in n and in m
s=0                          # initializes s, the sum of the sums of digits of prime factors, to 0
for d in range(2,n):         # checks all numbers from 2 to n for prime factors
 while n%d<1:                # while n is divisible by d
                             #   (to include the same prime factor more than once)
  n/=d                       # divide n by d
  s+=sum(map(int,`d`))       # add the sum of the digits of d to s
print                        # print the result: "True" if and only if
      n<m                    #   n was divided at least once, i.e. n is not prime
      >                      #   and m>s (always true) and
      s==sum(map(int,`m`))   #   s is equal to the sum of digits of m (the input)
```
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), 19 bytes
```
@e+S,?$pPl>1,P@ec+S
```
[Try it online!](http://brachylog.tryitonline.net/#code=QGUrUyw_JHBQbD4xLFBAZWMrUw&input=NjY2)
### Explanation
```
@e+S,                 S is the sum of the digits of the input.
     ?$pP             P is the list of prime factors of the input.
        Pl>1,         There are more than 1 prime factors.
             P@e      Split each prime factor into a list of digits.
                c     Flatten the list.
                 +S   The sum of this list of digits must be S.
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~11~~ 17 bytes
```
X‚Ä∫0si¬π√íSO¬πSOQ¬πp_&
```
**Explanation**
```
X‚Ä∫0si              # if input is less than 2 then false, else
       SO          # sum of digits
     ¬π√í            # of prime factors with duplicates
            Q      # equal to
          SO       # sum of digits
         ¬π         # of input
                &  # and
             ¬πp_   # input is not prime
```
[Try it online!](http://05ab1e.tryitonline.net/#code=WOKAujBzacK5w5JTT8K5U09RwrlwXyY&input=LTI1Ng)
[Answer]
## PowerShell v3+, 183 bytes
```
param($n)$b=@();for($a=$n;$a-gt1){2..$a|?{'1'*$_-match'^(?!(..+)\1+$)..'-and!($a%$_)}|%{$b+=$_;$a/=$_}}$n-notin$b-and(([char[]]"$n")-join'+'|iex)-eq(($b|%{[char[]]"$_"})-join'+'|iex)
```
No built-in prime checking. No built-in factoring. No built-in digit-sum. Everything's hand made. :D
Takes input `$n` as an integer, sets `$b` equal to an empty array. Here, `$b` is our collection of prime factors.
Next is a `for` loop. We first set `$a` equal to our input number, and the conditional is until `$a` is less-than-or-equal-to 1. This loop is going to find our prime factors.
We loop from `2` up to `$a`, uses `Where-Object` (`|?{...}`) to pull out [primes](https://codegolf.stackexchange.com/a/57636/42963) that are also factors `!($a%$_)`. Those are fed into an inner-loop `|%{...}` that places the factor into `$b` and divides `$a` (thus we'll eventually get to `1`).
So, now we have all of our prime factors in `$b`. Time to formulate our Boolean output. We need to verify that `$n` is `-notin` `$b`, because if it is that means that `$n` is prime, and so isn't a Smith number. Additionally, (`-and`) we need to make sure that our two sets of [digit sums](https://codegolf.stackexchange.com/a/81071/42963) are `-eq`ual. The resulting Boolean is left on the pipeline and output is implicit.
**NB** - Requires v3 or newer for the `-notin` operator. ~~I'm still running the input for `4937775` (this is *slow* to calculate), so I'll update this when that finishes.~~ After 3+ hours, I got a stackoverflow error. So, there's some upper-bound somewhere. Oh well.
This will work for negative input, zero, or one, because the right-hand of the `-and` will barf out an error while it tries to calculate the digit sums (shown below), which will cause that half to go to `$false` when evaluated. Since STDERR is [ignored by default](https://codegolf.meta.stackexchange.com/a/4781/42963), and the correct output is still displayed, this is fine.
---
### Test cases
```
PS C:\Tools\Scripts\golfing> 4,22,27,58,85,94,18,13,666,-265,0,1|%{"$_ -> "+(.\is-this-a-smith-number.ps1 $_)}
4 -> True
22 -> True
27 -> True
58 -> True
85 -> True
94 -> True
18 -> False
13 -> False
666 -> True
Invoke-Expression : Cannot bind argument to parameter 'Command' because it is an empty string.
At C:\Tools\Scripts\golfing\is-this-a-smith-number.ps1:1 char:179
+ ... "$_"})-join'+'|iex)
+                    ~~~
    + CategoryInfo          : InvalidData: (:String) [Invoke-Expression], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.InvokeExpressionCommand
-265 -> False
Invoke-Expression : Cannot bind argument to parameter 'Command' because it is an empty string.
At C:\Tools\Scripts\golfing\is-this-a-smith-number.ps1:1 char:179
+ ... "$_"})-join'+'|iex)
+                    ~~~
    + CategoryInfo          : InvalidData: (:String) [Invoke-Expression], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.InvokeExpressionCommand
0 -> False
Invoke-Expression : Cannot bind argument to parameter 'Command' because it is an empty string.
At C:\Tools\Scripts\golfing\is-this-a-smith-number.ps1:1 char:179
+ ... "$_"})-join'+'|iex)
+                    ~~~
    + CategoryInfo          : InvalidData: (:String) [Invoke-Expression], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.InvokeExpressionCommand
1 -> False
```
[Answer]
# MATL, 17 bytes
```
YftV!UsGV!Us=wnqh
```
Outputs [truthy or falsey](http://matl.tryitonline.net/#code=YGkgICAgICAgICAgJSBMb29wIHRocm91Z2ggYWxsIGlucHV0cwo_J1RSVUUnICAgICAlIElmIHRydXRoeSwgcHJpbnQgVFJVRQp9J0ZBTFNFJyAgICAlIEVsc2UsIHByaW50IEZBTFNFCl1EVCAgICAgICAgICUgQ29udGludWUgdW50aWwgd2UgcnVuIG91dCBvZiBpbnB1dHM&input=MQowClsxIDFdClsxIDBdClsxIDJdClsxIC0xXQ) arrays where a truthy output requires that *all* elements be non-zero.
[**Try it online**](http://matl.tryitonline.net/#code=WWZ0ViFVc0dWIVVzPXducWg&input=NDkzNzc3NQ)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~27 25~~ 23 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
(further golfing ~~probably~~ [definitely](https://codegolf.stackexchange.com/a/92059/53748) possible)
```
·∏¢DS√ó
√ÜF√á‚Ç¨S·∏¢
DS=√áa<2o√ÜP¬¨
```
Returns `0` for False or `1` for True
All test cases at [**TryItOnline**](http://jelly.tryitonline.net/#code=4biiRFPDlwrDhkbDh-KCrFPhuKIKRFM9w4dhPDJvw4ZQwqwKw4figqw&input=&args=WzE4LDIyLDEzLDY2NiwtMjY1LDAsMSwtMSw0OTM3Nzc1XQ)
How?
```
DS=√áa<2o√ÜP¬¨ - main link takes an argument, n
DS          - transform n to a decimal list and sum up
   √á        - call the previous link (√ÜF√á‚Ç¨S·∏¢)
  =         - test for equality
     <2     - less than 2?
    a       - logical and
        √ÜP  - is prime?
       o    - logical or
          ¬¨ - not
            - all in all tests if the result of the previous link is equal to the digit
              sum if the number is composite otherwise returns 0.
√ÜF√á‚Ç¨S·∏¢ - link takes an argument, n again
√ÜF     - list of list of n's prime factors and their multiplicities
  √á‚Ç¨   - apply the previous link (·∏¢DS√ó) for each
    S  - sum up
     ·∏¢ - pop head of list (there will only be one item)
·∏¢DS√ó - link takes an argument, a factor, multiplicity pair
·∏¢    - pop head, the prime factor - modifies list leaving the multiplicity
 DS  - transform n to a decimal list and sum up
   √ó - multiply the sum with the multiplicity
```
[Answer]
# Actually, 18 bytes
Unfortunately, Actually doesn't have a factorization builtin that gives a number's prime factors to multiplicity, so I had to hack one together. Golfing suggestions welcome. [Try it online!](http://actually.tryitonline.net/#code=O3dgaSRuYE3Oo-KZguKJiM6jQCTimYLiiYjOoz0&input=Mjc)
```
;w`i$n`MŒ£‚ôÇ‚âàŒ£@$‚ôÇ‚âàŒ£=
```
**Ungolfing**
```
         Implicit input n.
;w       Duplicate n and get the prime factorization of a copy of n.
`...`M   Map the following function over the [prime, exponent] lists of w.
  i        Flatten the list. Stack: prime, exponent.
  $n       Push str(prime) to the stack, exponent times.
            The purpose of this function is to get w's prime factors to multiplicity.
Œ£        sum() the result of the map.
          On a list of strings, this has the same effect as "".join()
‚ôÇ‚âàŒ£      Convert every digit to an int and sum().
@        Swap the top two elements, bringing other copy of n to TOS.
$‚ôÇ‚âàŒ£     Push str(n), convert every digit to an int, and sum().
=        Check if the sum() of n's digits is equal 
          to the sum of the sum of the digits of n's prime factors to multiplicity.
         Implicit return.
```
[Answer]
# Octave, ~~80~~ 78 bytes
```
t=num2str(factor(x=input('')))-48;disp(any(t<0)&~sum([num2str(x)-48 -t(t>0)]))
```
Explanation:
```
factor(x=input(''))                 % Take input, store as x and factor it
num2str(factor(x=input('')))-48     % Convert it to an array (123 -> [1 2 3]) 
                                    % and store as t
any(t<0)                            % Check if there are several prime factors
                                    % [2 3] -> [2 -16 3]
sum([num2str(x)-48 -t(t>0)])        % Check if sum of prime factor
                                    % is equal the sum of digits
```
Try it [online](https://ideone.com/kMVzhE).
[Answer]
# Pyth, 21 bytes
```
&&>Q1!P_QqsjQTssmjdTP
```
A program that takes input of an integer and prints `True` or `False` as relevant.
[Try it online](https://pyth.herokuapp.com/?code=Q%26%26%3EQ1%21P_QqsjQTssmjdTP&test_suite=1&test_suite_input=18%0A22%0A13%0A666%0A-265%0A0%0A1%0A4937775&debug=0)
**How it works**
```
&&>Q1!P_QqsjQTssmjdTP  Program. Input: Q
           jQT         Yield digits of the base-10 representation of Q as a list
          s            Add the digits
                    P  Yield prime factors of Q (implicit input fill)
                mjdT   Map base-10 representation across the above, yielding digits of each
                       factor as a list of lists
               s       Flatten the above
              s        Add up the digits
         q             Those two sums are equal
&                      and
  >Q1                  Q>1
 &                     and
     !P_Q              Q is not prime
                       Implicitly print
```
[Answer]
# [Perl 6](http://perl6.org/), ~~92~~ ~~88~~ 87 bytes
```
{sub f(\i){my \n=first i%%*,2..i-1;n??n~f i/n!!i}
!.is-prime&&$_>1&&.comb.sum==.&f.comb.sum}
```
```
{sub f(\i){my \n=first i%%*,2..^i;n??[n,|f i/n]!!|i}
$_>.&f>1&&.comb.sum==.&f.comb.sum}
```
An anonymous function that returns a Bool.
* Now does 100% manual factorization and primality checking.
* Saved some bytes by testing both "input > 1" and "number of factors > 1" with one chained comparison, since m > [Œ©(m)](https://en.wikipedia.org/wiki/Prime_factor#Omega_functions).
([try it online](https://glot.io/snippets/ei6u5x8unj))
*EDIT: -1 byte thanks to b2gills*
[Answer]
# [Brachylog (newer)](https://github.com/JCumin/Brachylog), 11 bytes
```
¬¨·πó&·∫π+.&·∏ãc·∫π+
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pf/ahtw6Ompkcdy5VKikpTlfRqQMy0xJziVKXa04vK/x9a83DndLWHu3Zq66k93NGdDGL9/x9taKFjZKRjaKxjZmamE29kZqpjoGOoY2JpbG5ubhoLAA "Brachylog ‚Äì Try It Online")
Predicate succeeds if the input is a Smith number and fails if it is not.
```
               The input
¬¨·πó             is not prime,
  &            and the input's 
   ·∫π           digits
    +          sum to
     .         the output variable,
      &        and the input's 
       ·∏ã       prime factors' (getting prime factors of a number < 1 fails)
        c      concatenated
         ·∫π     digits
          +    sum to
               the output variable.
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~14~~ 11 bytes
```
√¨x ¬•Uk x_√¨x
```
*-3 bytes thanks to @Shaggy*
[Try it online!](https://tio.run/##y0osKPn///CaCoVDS0OzFSrigcz//42MAA "Japt ‚Äì Try It Online")
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), ~~36~~ 29 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
This answer owes its golfiness to Extended's `‚ç≠` monad for returning the prime factors of a number, and that `‚ä§` is better at base-conversion than in Dyalog Unicode.
Edit: -7 bytes thanks to dzaima.
```
{2>‚çµ:0‚ãÑ(‚äÉ=+/-‚äÉ√ó2<‚â¢)+‚åø10‚ä§‚çµ,‚ç≠‚çµ}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/v9rI7lHvViuDR90tGo@6mm219XWB1OHpRjaPOhdpaj/q2W9o8KhrCVCNzqPetUCq9n/ao7YJj3r7HvVN9fQHqj203vhR20QgLzjIGUiGeHgG/087tMLQQsHISMHQWMHMzEzh0HojM1MFAwVDBRNLY3Nzc1MA)
**Explanation**
```
{1‚ãÑ(3)2}  A dfn, a function in brackets. ‚ãÑ is a statement separator.
          The numbers signify the sections in the order they are explained.
2>‚çµ:0  If we have a number less than 2,
       we immediately return 0 to avoid a DOMAIN ERROR.
+‚åø10‚ä§‚çµ,‚ç≠‚çµ
        ‚ç≠‚çµ  We take the factors of ‚çµ, our input as our right argument,
      ‚çµ,    and append it to our input again.
   10‚ä§      before converting the input and its factors into a matrix of their base-10 digits
            (each row is the places, units, tens, hundreds, etc.)
+‚åø         And taking their sum across the columns of the resulting matrix,
            to give us the sum of their digits, their digit-sums.
(‚äÉ=+/-‚äÉ√ó2<‚â¢)  We run this section over the list of sums of digits above.
 ‚äÉ=+/-‚äÉ       We check if the main digit-sum (of our input)
               Is equal to the sum of our digit-sums
               (minus our main digit-sum that is also still in the list)
        √ó2<‚â¢   The trick here is that we can sneak in our composite check
               (if our input is prime there will be only two numbers, 
               the digit-sum of the prime,
               and the digit-sum of its sole prime factor, itself)
               So if we have a prime, we zero our (minus our main sum)
               in the calculation above, so that primes will not succeed in the check.
               We return the result of the check.
```
[Answer]
# JavaScript (ES6), ~~¬†87 86¬†~~ 84 bytes
```
m=>(i=2,S=0,g=n=>([...i+''].map(v=>s-=v,s=S),i-m?n%i?g(n,i++):g(n/i,S=s):s==2*S))(m)
```
[Try it online!](https://tio.run/##HYvBDkNAFEX3vuJtykyNqUi6oY@PsBQJ0dInvBGjNk2/XSd25@TeM7Z7a7uVli1i83wdPR4z5oIwUSXGakB2VmmtKQyCWs/tInbMbYS7slhKRdFc8IWKQbCiMJSpgxu51srUIibXUkoxy6M3q2BASBRMZDdHVZ0BwwPucezApfD1AHrBEnz/POnlY9/OM@/ndYatmV56MoM4t9EQN6qR2fEH "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# Haskell, ~~120~~ 105 bytes
```
1%_=[];a%x|mod a x<1=x:div a x%x|0<1=a%(x+1)
p z=sum[read[c]|c<-show z]
s x|z<-x%2=z<[x]&&sum(p<$>z)==p x
```
[Answer]
# [Rutger](https://github.com/cairdcoinheringaahing/Rutger), 504 bytes
```
x=$Input;
t=Not[IsPrime[$x]];
c=();
d=p=0;
i=IfElse[{l=LessThan[$x];l[1]}];
i=i[{t=0;}];
i=i[{s=Array[Str[$x]];e=Each[$s];e=e[@i];e=e[{a=Add[$d];d=a[Integer[$i]];}];Do[$e];r=2;w=While[{Decrement[$x];}];w=w[{i=IfElse[{m=Modulo[$x];Not[m[$r]];}];i=i[{a=Append[$c];v=Divide[$x];x=Integer[v[$r]];c=a[Array[Str[$r]]];}];i=i[{r=Increment[$r];}];Do[$i];}];Do[$w];h=Each[$c];h=h[@k];h=h[{l=Each[$k];l=l[@n];l=l[{a=Add[$p];p=a[Integer[$n]];}];Do[$l];}];Do[$h];}];
Do[$i];
z=Times[$t];
e=Equal[$d];
Print[z[e[$p]];
```
[Try it online!](https://tio.run/##TVFNa8MwDL37d/iw3fZJGUbQQnsIbGOwwg7ChxB7i5njZLbTdA377ZkSt2lPepKlp6dn38Yv7YdhDzxzTRsFi/BaR8zCmzeVRr6XUrACrq4FU9DAjWAGss@NDRp7C886hG2Zu7FPWLyVf3JsMNhHap2TACvv8198jz4xatjkRYk8jFDj0qTY57BSCrmSQkGOmYua1CE3NEJk6xq5lsLDnejgozSWJta68LrSLk4SqKmDDvuzxgpeatXaenoeL6uQ@0Q3SaONTaMdLS2k2MHa7IyazhZ7OO3fpZGCJF3cQaUzjafmWYif1ZoZdVKUx6OLEZa4/E6RbEx1yi1YXLoUT2Y0UjSXZrizGXZG5YTYcSc7wJZ@LyCPlJDZP21uJ1sZfStJPKAeiaUYhoen@8Vi8fgP "Rutger ‚Äì Try It Online")
Rutger isn't a particularly short language, and doesn't excel at having to split an integer into its constituent digits.
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 26 bytes
```
(√ó/‚â°‚ç•(+/‚ç£‚â°10‚ä§‚ä¢)‚ä¢√ó1<‚â¢)‚ç≠‚ç§‚åà‚àò2
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/X@PwdP1HnQsf9S7V0NZ/1LsYyDY0eNS15FHXIk0gPjzd0OZRJ5DZu/ZR75JHPR2POmYY/U971DbhUW/fo76pnv6PupoPrTd@1DYRyAsOcgaSIR6ewf@BtHOkenFiTom6wqPuFoXUvMSknNRgR58Qrtik/IrMvHSF/DyutEMrDC0UjIwUDI0VzMzMFA6tNzIzVTBQMFQwsTQ2Nzc3BQA "APL (Dyalog Extended) ‚Äì Try It Online")
A golfed version of [Sherlock9's solution](https://codegolf.stackexchange.com/a/180810/78410). A nice use case for Over `f‚ç•g`, which performs `g` on both sides and combines the two with `f`.
### How it works
```
(√ó/‚â°‚ç•(+/‚ç£‚â°10‚ä§‚ä¢)‚ä¢√ó1<‚â¢)‚ç≠‚ç§‚åà‚àò2  ‚çù Input: n
                       ‚åà‚àò2  ‚çù max(n,2)
                     ‚ç≠‚ç§     ‚çù Prime factorization of above
(              ‚ä¢√ó1<‚â¢)       ‚çù Side 1: if n is not composite, multiply ^ with zero
 √ó/                         ‚çù Side 2: multiply all primes to get original number
    ‚ç•(        )  ‚çù Operate on each side..
          10‚ä§‚ä¢   ‚çù Base-10 digits of each number
      +/‚ç£‚â°       ‚çù Sum all of them
   ‚â°             ‚çù Check equality of the two sides
```
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), 131 bytes
```
(load library
(d F(q((X)(*(*(not(prime? X))X)(e(sum(to-base 10 X))(sum(map(q((X)(s X 48)))(chars(join(map string(prime-factors X))(
```
[Try it online!](https://tio.run/##LYzbDoIwDIbveYpediYazuKVdzwDtwMmzuyA3dDw9DiGadIv/dq/XppVSTdvGyrLR1CyJ05rgiO0@EbsGJ5CGetxJqnFHTrGghToFo3ennvuBGTprqPSfP7nHHRQNiz44cnJ4ctKs6/BeZJmOv6dH3zwllzMb9hC1rAkIM8jsiKirutINGKCvK5YnNLjJPTBai2MhzCWt@J6rRj4p3TwlUoBLQYelsRH0IUl2w8 "tinylisp ‚Äì Try It Online")
An unintentional golf at `join` which through some weird behaviour ends up producing the right thing. Rest of it is just the formula given in the question.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 63 [bitsv2](https://github.com/Vyxal/Vyncode/blob/main/README.md), 7.875 bytes
```
‚Çç‚Ä°«êvff·π†·π†‚âà
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyI9IiwiIiwi4oKN4oChx5B2ZmbhuaDhuaDiiYgiLCIiLCIyOCJd)
Bitstring:
```
110001111001001111101010000010100001001101010011001110100101010
```
```
‚Çç‚Ä°«êvff·π†·π†‚âà¬≠‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å°‚Å™‚Äè‚Å†‚Å™‚Å™‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å£‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å§‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å§‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå¬≠
‚Çç          # ‚Äé‚Å°Wrap the next to items in a list
 ‚Ä°«êvf      # ‚Äé‚Å¢list of digits for each prime factor
     f     # ‚Äé‚Å£list of digits of original number
      ·π†·π†   # ‚Äé‚Å§vectorised sum twice (quirk of list depth from digit lists)
        ‚âà  # ‚Äé‚Å¢‚Å°are they equal
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
## Pyke, 16 bytes
```
Pm[`mbs(sQ[qRlt*
```
[Try it here!](http://pyke.catbus.co.uk/?code=Pm%5B%60mbs%28sQ%5BqRlt%2a&input=22)
[Answer]
# Java 7, ~~509~~ ~~506~~ ~~435~~ ~~426~~ ~~419~~ 230 bytes
```
boolean c(int n){return n<2|p(n)?0>1:d(n)==f(n);}int d(int n){return n>9?n%10+d(n/10):n;}int f(int n){int r=0,i;for(i=1;++i<=n;)for(;n%i<1;n/=i,r+=i>9?d(i):i);return r;}boolean p(int n){int i=2;while(i<n)n=n%i++<1?0:n;return n>1;}
```
I should have listened to *@BasicallyAlanTuring*'s comment..
> 
> This is one of those questions where I thought "Java+this=no", I upvoted for the idea though :P
> 
> 
> 
Ah well.. Some programming languages use a single byte for the prime-factors or prime-check, but Java is certainly not one of them.
EDIT: Halved the amount of bytes now that I had some time to think about it.
**Ungolfed (sort-off..) & test cases:**
[Try it here.](https://ideone.com/1ihqJd)
```
class M{
  static boolean c(int n){
    return n < 2 | p(n)
            ? 0 > 1 //false
            : d(n) == f(n);
  }
  // Sums digits of int
  static int d(int n) {
    return n > 9
            ? n%10 + d(n/10)
            : n;
  }
  // Convert int to sum of prime-factors
  static int f(int n) {
    int r = 0,
        i;
    for(i = 1; ++i <= n; ){
      for( ; n % i < 1; n /= i,
                        r += i > 9 ? d(i) : i);
    }
    return r;
  }
  // Checks if the int is a prime
  static boolean p(int n){
    int i = 2;
    while(i < n){
      n = n % i++ < 1
           ? 0
           : n;
    }
    return n > 1;
  }
  public static void main(String[] a){
    System.out.println(c(18));
    System.out.println(c(22));
    System.out.println(c(13));
    System.out.println(c(666));
    System.out.println(c(-256));
    System.out.println(c(0));
    System.out.println(c(1));
    System.out.println(c(4937775));
  }
}
```
**Output:**
```
false
true
false
true
false
false
false
true
```
[Answer]
# [J](http://jsoftware.com/), ~~31~~ 30 bytes
```
0&p:*](=+/)&(1#."."0@":)q: ::1
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DdQKrLRiNWy19TXVNAyV9ZT0lAwclKw0C60UrKwM/2sqcHGlJmfkA3XYKqQpGCBzDFE4Fig8Y2RevJGZKRfUHEOwiJERMs/MzAyZa2JpbG5ubsr1HwA "J ‚Äì Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~139~~ 136 bytes
```
S(m,i,t,h,_){t=m=m<2?2:m;for(_=h=i=1;m>1;h=1){while(m%++h);for(m/=h;i+=h%10,h/=10;);}while(t%++h);for(m=t;_+=m%10,m/=10;);m=t-h?i==_:0;}
```
[Try it online!](https://tio.run/##TcrBCsIwEATQu18RhEJiU2w89OC69iM8qoQStRtwq4Sgh9Jvj2314JyGmeeK1rmUDpK111GTtqqPyMi7Tb3ZMtweQVok9GiA9wYIjerf5O9XyVmek5oFr5HA50iZKTWt0ZSgYPiy@Mcwgs2RJ8U/NW4F1R7RbksYku@i4MZ3cipNaJ0WjpogVmN/Hc@qX4gxzzDeN7nMLqduqcVBNvHh5UzMWSkFiyGlqqo@ "C (gcc) ‚Äì Try It Online")
-3 bytes thanks to ceilingcat
Explanation:
```
/* 
 * Variable mappings:
 *  is_smith      => S
 *  argument      => m
 *  factor_digits => i
 *  arg_copy      => t
 *  least_factor  => h
 *  digit_sum     => _    
 */
int is_smith(int argument){                     /* S(m,i,t,h,_){ */
    int factor_digits;
    int arg_copy;
    int least_factor;
    int digit_sum;
    /* 
     * The cases of 0 and 1 are degenerate. 
     * Mapping them to a non-degenerate case with the right result.
     */
    if (argument < 2) {                         /* t=m=m<2?2:m; */
        argument = 2;
    }
    arg_copy = argument;
    /* 
     * Initializing these to 1 instead of zero is done for golf reasons.
     * In the end we just compare them, so it doesn't really matter.
     */
    factor_digits = 1;                          /* for(_=h=i=1; */
    digit_sum = 1;
    /* Loop over each prime factor of argument */
    while (argument > 1) {                      /* m>1; */
        /*
         * Find the smallest factor 
         * Note that it is initialized to 1 in the golfed version since prefix
         * increment is used in the modulus operation.
         */
        least_factor = 2;                       /* h=1){ */
        while (argument % least_factor != 0)    /* while(m% */
            least_factor++;                     /* ++h); */
        argument /= least_factor;               /* for(m/=h; */
        /* Add its digit sum to factor_digits */
        while (least_factor > 0) {
            factor_digits += least_factor % 10; /* i+=h%10, */
            least_factor /= 10;                 /* h/=10;) */
        }                                       /* ; */
    }                                           /* } */
    /* In the golfed version we get this for free in the for loop. */
    least_factor = 2;
    while (arg_copy % least_factor != 0)        /* while(t% */
        least_factor++;                         /* ++h); */
    /* Restore the argument */
    argument = arg_copy;                        /* for(m=t; */
    /* Compute the arguments digit sum */
    while (argument > 0) {
        digit_sum += argument % 10;             /* _+=m%10, */
        argument /= 10;                         /* m/=10;) */
    }                                           /* ; */
    /* This return is done by assigning to first argument when golfed. */
                                                /* m= */
    if (arg_copy == least_factor) {             /* t==h? */
        return 0; /* prime input */             /* 0 */
    } else {                                    /* : */
        return digit_sum == factor_digits;      /* i == _ */
    }                                           /* ; */
}                                               /* } */
```
[Answer]
# Racket 176 bytes
```
(define(sd x)(if(= x 0)0(+(modulo x 10)(sd(/(- x(modulo x 10))10)))))
(require math)(define(f N)
(if(=(for/sum((i(factorize N)))(*(sd(list-ref i 0))(list-ref i 1)))(sd N))1 0))
```
Returns 1 if true and 0 if false: 
```
(f 27)
1
(f 28)
0
(f 85)
1
(f 86)
0
```
Detailed version: 
```
(define (sd x)   ; fn to find sum of digits
  (if (= x 0)
      0
      (+ (modulo x 10)
         (sd (/ (- x (modulo x 10)) 10)))))
(require math)
(define (f N)
  (if (= (for/sum ((i (factorize N)))
           (* (sd (list-ref i 0))
              (list-ref i 1)))
         (sd N)) 1 0))
```
[Answer]
# Rust - 143 bytes
```
fn t(mut n:u32)->bool{let s=|k:u32| (2..=k).fold((0,k),|(a,m),_|(a+m%10,m/10));s(n).0==(2..n).fold(0,|mut a,d|{while n%d<1{n/=d;a+=s(d).0};a})}
```
borrowed python solution by @levitatinglion ... at least this is shorter than Java...
[degolfed at play.rust-lang.org](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e2a467d637f009f3bea17115fae119aa)
[Answer]
# C (gcc), 177 Bytes
Defines a function `Q` that returns 0 for smith numbers and nonzero for non-smith numbers
```
#define r return
O(D,i){for(i=0;D>0;i+=D%10,D-=D%10,D/=10);r i;}D(O,o){for(o=1;o<O;)if(O%++o<1)r o;r O;}Q(p,q,i,j){if(p^(q=D(i=p))){for(j=0;p>1;q=D(p/=q))j+=O(q);r j^O(i);}r 1;}
```
[Try it online!](https://tio.run/##fc5Bb4MgGAbgu7/iSxcTvohRdNNulJ68kyY7Lk02RYfJUKk7GX@7E9vr5PISeOD9yrApy2V5qlStjQILVo2/1niSFFTjVHeWaBHz4hxzHYjCZzEtwkdGgsXILWg@F0TS7s47wXh3khx1TaQfBN2JoYVudZLPF9LTgWra4rRe91cyiGIt6BHvj9u1qz8z7o77SAyIbSAkGVxNe5VEI58tMD57UQTv6jZq08CXarS5wbeyyvv51Ibg5MG6eqvNWJODX8Eb@NWHOVBgRwoXwo6I/F@TJM4kyZ5h6fZPumeyLHNojT0VJtmLYy73XOxQvDvTNtKeeH5N8zzf6h5bp2dvWf4A "C (gcc) ‚Äì Try It Online")
Explanation:
```
// Return the sum of digits of D if D > 0, otherwise 0
O(D,i){
    // While D is greater than 0:
    // Add the last digit of D to i, and remove the last digit from D
    for(i=0;D>0;i+=D%10,D-=D%10,D/=10);
    return i;
}
// Return the smallest prime factor of O if O>1 else O
D(O,o){
    // Iterate over numbers less than O
    for(o=1;o<O;)
        // If O is divisible by o return o
        if(O%++o<1)
            return o;
    // Otherwise return O
    return O;
}
Q(p,q,i,j){
    // Set q to D(p) and i to p
    // If p != D(p) (i.e, p is composite and > 0)
    if(p^(q=D(i=p))){
        // Iterate over the prime factors of p and store their digit sum in j
        for(j=0;p>1;q=D(p/=q))
            j+=O(q);
        // i is the original value of p. If O(i)^j == 0, O(i) == j
        return j^O(i);
    }
    // If p was composite or < 0, return 1
    return 1;
}
```
[Answer]
## [C# (Visual C# Interactive Compiler)](https://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 122 bytes
```
n=>{int m=n,b=0,a=$"{n}".Sum(x=>x-'0');for(int i=2;i<m;i++)if(n%i==0){b+=$"{i}".Sum(x=>x-'0');n/=i;i=1;}return n>0&&a==b;}
```
[Try it online!](https://tio.run/##ZczBCoJAFIXhfU8xROkMao1aYzFel63atWitonAhrzAqCOKzmy7V7cf5T954eYPTq6M8RmrdrK5/CSsZTATJMAurgNwMpJvC6TjQeLx8uor3kPSeLW2hy9rwZYYQaIwrjY4jsOR0RgAphsxZMtxldAXUCL4eTdF2hhgl0rJSgEyPkz58DbbFG6ngJfcfQqwlCLbih1tRSm3JC9R9a3L3NANbye0ZRlG0lNMf)
[Answer]
# APL(NARS), 39 chars, 78 bytes
```
{‚çµ‚â§0:0‚ãÑ0œÄ‚çµ:0‚ãÑ(2√ó‚Üëa)=+/a‚Üê+/¬®{‚çé¬®‚çï‚çµ}¬®‚çµ,œÄ‚çµ}
```
test:
```
  f‚Üê{‚çµ‚â§0:0‚ãÑ0œÄ‚çµ:0‚ãÑ(2√ó‚Üëa)=+/a‚Üê+/¬®{‚çé¬®‚çï‚çµ}¬®‚çµ,œÄ‚çµ}
  f¬®0..10
0 0 0 0 1 0 0 0 0 0 0 
  ‚éïfmt {‚çµ,f‚çµ}¬®18,22,13,666,¬Ø265,0,1,4937775
‚îå8‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îê
‚îÇ‚îå2‚îÄ‚îÄ‚îÄ‚îÄ‚îê ‚îå2‚îÄ‚îÄ‚îÄ‚îÄ‚îê ‚îå2‚îÄ‚îÄ‚îÄ‚îÄ‚îê ‚îå2‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îê ‚îå2‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îê ‚îå2‚îÄ‚îÄ‚îÄ‚îê ‚îå2‚îÄ‚îÄ‚îÄ‚îê ‚îå2‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îê‚îÇ
‚îÇ‚îÇ 18 0‚îÇ ‚îÇ 22 1‚îÇ ‚îÇ 13 0‚îÇ ‚îÇ 666 1‚îÇ ‚îÇ ¬Ø265 0‚îÇ ‚îÇ 0 0‚îÇ ‚îÇ 1 0‚îÇ ‚îÇ 4937775 1‚îÇ‚îÇ
‚îÇ‚îî~‚îÄ‚îÄ‚îÄ‚îÄ‚îò ‚îî~‚îÄ‚îÄ‚îÄ‚îÄ‚îò ‚îî~‚îÄ‚îÄ‚îÄ‚îÄ‚îò ‚îî~‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îò ‚îî~‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îò ‚îî~‚îÄ‚îÄ‚îÄ‚îò ‚îî~‚îÄ‚îÄ‚îÄ‚îò ‚îî~‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îò2
‚îî‚àä‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îò
```
]