text:
Find the nearest biquadratic number
A biquadratic number is a number that is the fourth power of another integer, for example: 3^4 = 3*3*3*3 = 81
Given an integer as input, output the closest biquadratic number.
Here are the first 15 double-squares:
1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 10000, 14641, 20736, 28561, 38416, 50625

This is code-golf so fewest bytes in each language wins
This is OEIS A000583

Interesting to note that this will never tie, as the sequence alternates odd and even numbers.

you could change the name to "Find the nearest zenzizenzic". https://en.wiktionary.org/wiki/zenzizenzic

@Okx oh good point, I didn't even think about ties, but you're right, it does seem to alternate parity

@Mayube It necessarily does, because the sequence is just n^4 and n alternates in sign.

That nomenclature of biquadratic is confusing: before seeing the question contents, I thought it were the 2 x n² numbers: 2, 8, 18, 32, 50, 72, 98, ...

Isn't that called "quartic"? (Merriam-Webster, Wiktionary)

I think it would be beneficial to include some test cases.

Python 3, 35 bytes
lambda n:int((n**.5-.75)**.5+.5)**4

Try it online!
How it works
The value n at which the output switches from (k − 1)4 to k4 satisfies √(√n − 3/4) + 1/2 = k, or n = ((k − 1/2)2 + 3/4)2 = (k2 − k + 1)2 = ((k − 1)4 + k4 + 1)/2, which is exactly the first integer that’s closer to k4.
(Works for all n ≤ 4504699340341245 = (81924 + 81934 − 7)/2 > 252, after which floating-point roundoff starts to break it, even though it works mathematically for all n.)

You can save a byte with round if you switch to Python 2 which rounds all .5's up.

Octave, 35 bytes
This challenge needed a convolution-based approach.
@(n)sum(n>conv((1:n).^4,[1 1]/2))^4

Try it online!
Explanation
The expression (1:n).^4 produces the row vector [1 16 81 256 ... n^4].
This vector is then convolved with [1 1]/2, which is equivalent to computing the sliding average of blocks of size 2. This implicitly assumes that the vector is left- and right-padded with 0. So the first value in the result is 0.5 (average of an implicit 0 and 1), the second is 8.5 (average of 1 and 16), etc.
As an example, for n = 9 the result of conv((1:n).^4,[1 1]/2) is
0.5 8.5 48.5 168.5 440.5 960.5 1848.5 3248.5 5328.5 3280.5

The comparison n>... then yields
1 1 0 0 0 0 0 0 0 0 0

and applying sum(...) gives 2. This means that n exceeds exactly 2 of the mid-points betwen biquadratic numbers (including the additional mid-point 0.5). Finally, ^4 raises this to 4 to yield the result, 16.

It is even golfier!

Haskell, 51 49 bytes
Function monad ftw!
f n=snd.minimum$(abs.(n-)<$>)>>=zip$(^4)<$>[1..n]

Try it online!
Explanation:
                                (^4)<$>[1..n] -- creates a list of fourth powers
            (abs.(n-)<$>)>>=zip               -- creates a list of |n-(4th powers)| and
                                              -- zips it with the 4th powers list
    minimum                                   -- finds the minimum
                                              -- (only first tuple entry matters)
snd                                           -- exctracts the second entry (the 4th power)

MATL, 6 bytes
t:4^Yk

Try it online!
Explanation
Consider input 9 as an example.
t    % Implicitly input n. Duplicate
     % STACK: 9, 9
:    % Range [1 2 ... n]
     % STACK: 9, [1 2 3 4 5 6 7 8 9]
4^   % Raise to 4, element-wise
     % STACK: 9, [1 16 81 256 625 1296 2401 4096 6561]
Yk   % Closest element. Implicitly display
     % STACK: 16

Excel, 25 bytes
=INT((A1^.5-3/4)^.5+.5)^4

Excel updates this to =INT((A1^0.5-3/4)^0.5+0.5)^4

Just a note on convention for excel: it is the de facto standard that Excel and Excel VBA function that take input from the Excel.ActiveSheet object take them from cell A1

@TaylorScott, thanks for pointing that out.  Have updated.

Neim, 5 bytes
4S

Explanation:
       Inclusive range [1 .. input]
      Raise to the  v  power
 4                   4th
       Select the value closest to
    S   the input

Try it online!

This programming language seems to use Unicode characters ("" and ""). Such characters typically require more than one byte. Are you sure the 5 characters can be stored using only 5 bytes?

@MartinRosenau Neim uses a custom codepage

Brachylog, 9 bytes
;I≜+.~^₄∧

Try it online!
Explanation
;I≜          I = 0 / I = 1 / I = -1 / I = 2 / etc. on backtracking
   +.        Output = Input + I
    .~^₄     Output = Something to the power 4
        ∧

Mathematica, 21 bytes
Nearest[Range@#^4,#]&

Jelly, 6 bytes
R*4ạÐṂ

A monadic link returning a list of one item, or a full program that prints the result (using an inefficient method).
Try it online!
How?
R*4ạÐṂ - Link: number, n
R      - range(n) -> [1,2,3,...,n]
 *4    - raise to the fourth power -> [1,16,81,...,n**4]
    ÐṂ - filter keep those (only ever one) minimal:
   ạ   -   absolute difference (with n)
       - if a full program: implicit print (one item lists print their content).

05AB1E, 6 bytes
LnnI.x

Try it online!
Explanation
LnnI.x
L      # Push [1 .. input]
 nn    # Raise every element to the 4th power
   I   # Push input
    .x # Closest element in the array to input

JavaScript (ES7), 42 bytes
x=>(n=x**.25|0,x-(k=n**4)<++n**4-x?k:n**4)

Recursive version, 44 bytes
f=(x,k,b)=>(a=k**4)>x?a-x>x-b?b:a:f(x,-~k,a)

Demo

let f =

x=>(n=x**.25|0,x-(k=n**4)<++n**4-x?k:n**4)

console.log(f(16))
console.log(f(48))
console.log(f(49))

Octave, 37 bytes
@(n)interp1(t=(1:n).^4,t,n,'nearest')

Anonymous function that uses nearest-neighbour interpolation.
Try it online!

@flawr Does this make you feel better?

It does very much so!

APL, 22 bytes
{o/⍨p=⌊/p←|⍵-⍨o←4*⍨⍳⍵}

Try it online!
How?
o←4*⍨⍳⍵ - o = range(⍵)4 [vectorize]
p←|⍵-⍨o - p = abs(o - ⍵)  [vectorize]
o/⍨ - take the o element at the index where ...
p=⌊/p - the p minimum element is

Husk, 10 7 bytes
Edit: -3 bytes thanks to Razetime
◄≠¹m^4ḣ

Try it online!
◄≠¹m^4ḣ
◄               # minimum element based on
 ≠¹             # difference to input,
      ḣ         # of series from 1 up to input
   m^4          # to the power of 4

min by

@Razetime Will you post that separately, or should I update my (now significantly outgolfed) answer?

By the way: thanks!  That's the second time you've improved on my answer using minby/maxby... so I guess I should remember them soon...

go ahead, edit it in

R, 47 44 37 35 bytes
n=scan();which.min(((1:n)^4-n)^2)^4

Try it online!

you can return an anonymous function (removing f=) and instead of x[which.min((x-n)^2)] use which.min((x-n)^2)^4, and then put f= into the header of the TIO link for testing like here :)

@Giuseppe Oh, there is no need to define x at all. Thank you!

ah, then the only other improvement is taking the input from stdin, n=scan();which.min(((1:n)^4-n)^2)^4 and the input goes into the footer section on TIO.

@Giuseppe Thanks again! Useful to know for future answers in R.

PHP, 33 bytes
<?=(($argn**.5-.75)**.5+.5^0)**4;

Try it online!
PHP, 56 bytes
<?=2*$argn-($x=($f=$argn**.25^0)**4)>($y=++$f**4)?$y:$x;

Try it online!

C++, 96 bytes
int Q(int N){int i=1;while (pow(i,4)<N){i++;}if (pow(i,4)-N>N-pow(i-1,4)){i--;}return pow(i,4);}

Full version:
int Q(int N)
{
    int i = 1;

    while (pow(i, 4) < N)
    {
        i++;
    }

    if (pow(i, 4)-N > N-pow(i - 1, 4))
        i--;

    return pow(i,4);
}

LINK to try

Haskell, 35 bytes
f n=(floor$(n**0.5-3/4)**0.5+0.5)^4

Port of Anders' Python3 answer.

Pyth, 9 bytes
.maQb^R4S

Try it online!

Pyth, 17 bytes
A full program that uses the same arithemtic approach as in @AndersKaseorg's answer:
K.5^s+^-^QK.75KK4

Try it online!

Stax, 10 bytes
Ç∞§δo╧╖s►M

Run and debug it

C#, 95 bytes
namespace System.Linq{n=>new int[940].Select((_,i)=>i*i*i*i).OrderBy(i=>Math.Abs(i-n)).First()}

We use 940 as a set value as any larger value will overflow the int.
Full/Formatted Version:
namespace System.Linq
{
    class P
    {
        static void Main()
        {
            Func<int, int> f = n => new int[940].Select((_, i) => i * i * i * i).OrderBy(i => Math.Abs(i - n)).First();

            for (int i = 1; i <= Int32.MaxValue; ++i)
                Console.WriteLine($"{i} = {f(i)}");

            Console.ReadLine();
        }
    }
}

QBIC, 38 bytes
{p=q^4~p>:|~p-a>a-o|_Xo\_Xp]\o=p┘q=q+1

Explanation
{           DO infinitely
p=q^4       Set p to q quad (q starts out as 1)
~p>:|       IF p exceeds the input THEN
~p-a>a-o    check the distance to p and to o (the last quad) and
|_Xo        PRINT o, or
\_Xp        PRINT p accordingly
]           END IF
\o=p        ELSE  ( p <= input) store p in o to keep track of this quad
┘q=q+1      and raise q for the next iteration

Java (OpenJDK 8), 64 bytes
n->{int i=0,q,Q=0;while((q=i*i*i*i++)<n)Q=q;return q-n<n-Q?q:Q;}

Try it online!

Ruby, 23 34 bytes
I have no idea why 0.75 is such an important number for this, but hey, whatever works.
->n{((n**0.5-0.75)**0.5).round**4}

Try it online!

This will not give the closest biquadratic. E.g. it will return 256 for 151.

Common Lisp, 50 bytes
(lambda(x)(expt(floor(+(sqrt(-(sqrt x).75)).5))4))

Try it online!

Japt -g, 20 8 7 bytes
This feels far too long! I was right!
Ç²²ÃñaU

Try it
Ç²²ÃñaU     :Implicit input of integer U
Ç           :Map the range [0,U)
 ²²         :  Square twice
   Ã        :End map
    ñ       :Sort by
     aU     :  Absolute difference with U
            :Implicit output of first element

Without flag, 8 bytes
È¬¬v1}cU

Try it
È¬¬v1}cU     :Implicit input of integer U
È            :Function taking an integer X as argument
 ¬           :  Square root
  ¬          :  Square root
   v1        :  Divisible by 1?
     }       :End function
      cU     :Return the first X in the sequence [U,U-1,U+1,U-2,U+2,U-3,...] that returns true


text:
House of cards (version 1)

Version 2 here.

Simple challenge: given an integer, draw a house of cards with the given number of stories. If the number is negative, draw the house upside-down. Examples:
Input: 2
Output:

 /\
 --
/\/\

Input: 5
Output:

    /\
    --
   /\/\
   ----
  /\/\/\
  ------
 /\/\/\/\
 --------
/\/\/\/\/\

Input: 0
Output: <empty, whitespace or newline>

Input: -3
Output:

\/\/\/
 ----
 \/\/
  --
  \/

Input can be numeric or a string. Output must be exactly as shown, with leading and/or trailing spaces and newlines allowed.
This is code-golf, so may the shortest program/function for each language win!

This comes from the sandbox.

Are leading newlines allowed?

@Shaggy yes, you can also have leading whitespaces and newlines, as long as you draw the house of cards exactly as shown. I don't mind if it is not aligned to the left of the screen.

Can we thrown and error on input=0?

@Rod If that produces empty output it's allowed by default

@Rod if it's allowed by default, I won't complaint then.

@CarlosAlejo managed to work around it c:

Radiohead song...

Python 2, 97 95 94 92 bytes
-2 bytes thanks to Luka
This version produces an exception  on n=0,but without printing anything

n=input()*2
m=abs(n)
for i in range(2,m+1)[::n/m]:print(i/2*'/-\-'[i%2::2][::n/m]).center(m)

Try it online!
Non-error version, Python 2, 94 bytes
n=input()*2
x=n>0 or-1
for i in range(2,x*n+1)[::x]:print(i/2*'/-\-'[i%2::2][::x]).center(n*x)

Try it online!

x=n>0 or-1 => x=n>0or-1

@Zacharý doesn't work, 0or will be interpreted as an octa number

Cut 2 more bytes: m=abs(n). Then, instead of x put n/m, instead of x*n put m

05AB1E, 30 29 24 bytes
ÄF„--N×„/\N>×}).C∊2ä¹0‹è

Try it online!
Explanation
ÄF                         # for N in [0 ... abs(input-1)] do:
  „--N×                    # push the string "--" repeated N times
       „/\N>×              # push the string "/\" repeated N+1 times
             }             # end loop
              )            # wrap stack in a list
               .C          # pad strings on both sides to equal length
                 ∊         # vertically mirror the resulting string
                  2ä       # split in 2 parts
                    ¹0‹    # push input < 0
                       è   # index into the the list with the result of the comparison

PHP, 125 bytes
input negative leading newline
input positive trailing newline

for($s=str_pad;++$i<$b=2*abs($argn);)$t.=$s($s("",2*ceil($i/2),["-","/\\"][1&$i]),$b," ",2)."
";echo$argn>0?$t:$t=strrev($t);

Try it online!
PHP, 130 bytes
for(;++$i<$b=2*abs($a=$argn);)echo($s=str_pad)($s("",2*abs(($a<0?$a:$i&1)+($i/2^0)),["-",["/\\","\/"][0>$a]][1&$i]),$b," ",2)."
";

Try it online!

MATL, 39 bytes
|:"G|@-:~'/\'G0<?P]@E:)htg45*c]xXhG0<?P

Try it online!
Explanation
|         % Implicitly input, N. Absolute value
:"        % For k from 1 to that
  G|      %   Push absolute value of N again
  @-      %   Subtract k
  :       %   Range [1 2 ... N-k]
  ~       %   Convert to vector of N-k zeros
  '/\'    %   Push this string
  G0<     %   Is input negative?
  ?       %   If so
    P     %     Reverse that string (gives '\/')
  ]       %   End
  @E      %   Push 2*k
  :       %   Range [1 2 ... 2*k]
  )       %   Index (modularly) into the string: gives '/\/\...' or '\/\/...'
  h       %   Horizontally concatenate the vector of zeros and the string. Zeros
          %   are implicitly converted to char, and will be shown as spaces
  t       %   Duplicate
  g       %   Convert to logical: zeros remain as 0, nonzeros become 1
  45*c    %   Multiply by 45 (ASCII for '=') and convert to char
]         % End
x         % Delete (unwanted last string containing '=')
Xh        % Concatenate into a cell array
G0<       % Is input negative?
?         % If so
  P       %   Reverse that cell array
          % Implicit end. Implicit display

Man, that was fast!! I hope version 2 won't be so easy... :-)

Charcoal, 31 28 27 bytes
ＦＩ⊟⪪θ-«←ι↓→/…\/ι↙»‖Ｍ¿‹Ｎ⁰‖Ｔ↓

Try it online! Link is to verbose version of code. I had about 4 different 32 byte answers then found this. Edit: Saved 3 4 bytes by performing the abs using string manipulation. Explanation:
   ⪪θ-                          Split the input (θ = first input) on -
  ⊟                             Take the (last) element
 Ｉ                              Convert it to a number i.e. abs(θ)
Ｆ     «                         Repeat that many times
       ←ι                       Print half of the -s
         ↓                      Position for the /\s
          →/                    Print the first /
            …\/ι                Print half of any remaining \/s
                ↙               Position for the next row of -s
                 »              End of the loop
                  ‖Ｍ            Mirror everything horizontally
                    ¿‹Ｎ⁰        If the input was negative
                        ‖Ｔ↓     Reflect everything vertically

I knew that a Charcoal answer would end with ¿‹θ⁰‖Ｔ↓. :-)

When Charcoal is beaten by 05AB1E on an ASCII-art challenge O_o

@Gryphon I don't have a one-byte abs...

True, it's just weird to see this though.  Makes you wonder what the world's coming to.

Yeah, this'd be 23 bytes with an abs builtin. (Congrats on 48K, btw)

@ETHproductions I can't see how it would be less than 24; for (Abs(InputNumber)) { could only be 4 bytes shorter at best.

C (gcc), 169 171 173 160 164 bytes
#define F(A,B,C)for(i=A;B--;)printf(C);
#define P puts("");F(y,i," ")F(abs(n)-y
s,i,x,y;f(n){x=n<0;for(s=x?1-n:n;s--;){y=x?-n-s:s;P,i,x?"\\/":"/\\")y+=x;P,s>x&&i,"--")}}

+13 bytes for negative case bug.
Try it online!
Ungolfed (207 bytes after removing all spaces and newline):
s, i, x, y;
f(n) {
  x = n < 0;
  for (s = x ? 1 - n : n; s--;) {
    y = x ? - n - s : s;
    puts("");
    for (i = y; i--;) printf(" ");
    for (i = abs(n) - y; i--;) printf(x ? "\\/" : "/\\");;
    y += x;
    puts("");
    for (i = y; i--;) printf(" ");
    for (i = abs(n) - y; s > x && i--;) printf("--");;
  }
}

@officialaimm fixed! thanks

Suggest L"尯⽜"+x instead of x?"\\/":"/\\"

Gaia, 21 bytes
:┅“/\\“--”×¦¦_€|ḣ¤ọ×ṣ

Explanation
:                      Push 2 copies of the input
 ┅                     Get the range to the input. If positive: [1 .. n]. If negative:
                       [-1 .. n]. If zero: [0].
  “/\\“--”             Push ["/\", "--"]
          ×¦¦          Repeat both of those strings by each number in the range. Strings go
                       in reverse order when repeated a negative number of times.
             _         Flatten the list
              €|       Centre-align the rows of the list
                ḣ      Remove the last row (the "--"s on the bottom)
                 ¤     Swap (bring input back to the top)
                  ọ    Sign: -1 for negative, 0 for 0, 1 for positive
                   ×   Repeat the list that many times; (-1 × list) reverses it
                    ṣ  Join with newlines and implicitly output

Japt, 40 38 bytes
-2 bytes thanks to @Shaggy
o½½@aXc)ç +"--/\\\\/"ò gYv *Ug)pXc aÃ·

Try it online!
Explanation
o½½@aXc)ç +"--/\\\\/"ò gYv *Ug)pXc aÃ·              // implicit: U = input integer
o.5,.5,XYZ{UaXc)ç +"--/\\\\/"ò gYv *Ug)pXc a} qR    // ungolfed
o.5,.5,                                             // array [.5,U] with step size .5
       XYZ{                                 }       // mapped by the function: (X = value, Y = index)
           UaXc)                                    //   absolute diff between U and ceil(X)
                ç                                   //   " " times that value
                  +"--/\\\\/"ò g      )             //   plus ["--","/\","\/"].get(...
                                Yv                  //     if Y is even, 1, else 0
                                   *Ug              //     times sign(U)
                                       pXc a        //   repeated abs(ceil(X)) times
                                              qR    // all that joined with newlines

38 bytes.

Mathematica, 140 bytes
(T=Table;z=Column;B[a_]:=""<>"/\\"~T~a;If[#>0,m=0,m=Pi];z[Join[z/@T[{B@i,""<>"--"~T~i},{i,Abs@#-1}],{B@Abs@#}],Alignment->Center]~Rotate~m)&

Retina, 116 111 105 bytes
this got way too long :/
\d+
$*
+`^~?( *1*)1
 $1¶$&¶_$&
.*$

+`(_.*)1
$1--
1
/\
Ts`/\\`\\/`.*~.*
+`(.*)¶((.*¶)*)(~.*)
$2$4¶$1
~|_

Try it online!
negative input is denoted as ~n

Perl 5, 100 + 1 (-n) = 101 bytes
$/=$_>0?'/\\':'\\/';push@r,$_=$"x--$q.$/x$_,y|/\\|-|r for 1..($q=abs);pop@r;say for$_<0?reverse@r:@r

Try it online!

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Is it a Chen prime?
A number is a Chen prime if it satisfies two conditions:

It is prime itself
Itself plus two is either a prime or a semi-prime.

A prime is a number where it has exactly two divisors and those divisors consist of itself and one.
A semi-prime is a number which is the product of two primes. (Note that 12 = 2*2*3 is not semi-prime, but 25 = 5*5 is).
Your task is to determine if a number is a Chen prime. You should output any truthy value for yes and any falsy value for no.
The input will be any integer greater than or equal to one. It may also be taken as a string, character array, or an array or digits.
Examples:
101 -> truthy
223 -> falsy
233 -> truthy
1 -> falsy

This is OEIS A109611.
This is, in part, inspired by Am I a Sophie Germain prime? which, unfortunately, got closed as a duplicate, so I'm posting a somewhat related challenge which isn't a duplicate.

Can we return True for truthy and 2 or False for falsy (inconsistent falsy values)?

@Mr.Xcoder Never said you couldn't

For a semi-prime, does "exactly two prime factors" count multiplicity? Is 2 * 2 * 2 * 3 * 3 a semi-prime? What about 5 * 5?

@Notatree 5*5 is semi-prime, 2*2*2*3*3 is not. I said exactly two.

So it does count multiplicity, then? (You could argue that 2*2*2*3*3 has exactly two prime factors, namely 2 and 3, and 5*5 has one prime factor, namely 5.) Maybe you could edit that into the question?

Can I use 0 for truthy and anything else for falsy?

@Titus Is it truthy in your language?

Is 2 falsy? (Mr. Xcoder)

@Titus No. (Sorry, late response)

Brachylog, 7 bytes
ṗ+₂ḋl≤2

Try it online!
Explanation
ṗ         Input is prime
   ḋ      The prime factorization of…
 +₂       … Input + 2…
    l≤2   … has 2 or less elements

I caught Neil at exactly 48,000 rep, and now you at exactly 22,222 :P

05AB1E, 8 bytes
p¹ÌÒg3‹*

Try it online!
Explanation
p¹ÌÒg3‹*   Argument n
p          Push isPrime(n)
 ¹ÌÒ       Push list of prime factors of (n+2)
    g3‹    Length of list is lower than 3
       *   Multiplication of boolean values, 0 if either is 0 (false)

Pyth, 10 bytes
&P_Q>3lP+2

Try it online!
How?
&P_Q>3lP+2  # input: Q
        +2  # Q + 2
       P    # prime factors
    >3l     # length lower than 3?
 P_Q        # Q is prime?
&           # and both results

.< Outgolfed >.<

@Mr.Xcoder actually, I posted mine 5 minutes before

Yeah, didn't see it because of the poor internet connection

ArnoldC, 1339 bytes
LISTEN TO ME VERY CAREFULLY q
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE p
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE c
YOU SET US UP 0
HEY CHRISTMAS TREE d
YOU SET US UP 0
HEY CHRISTMAS TREE l
YOU SET US UP p
STICK AROUND l
GET TO THE CHOPPER d
HERE IS MY INVITATION p
I LET HIM GO l
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE d
BULLSHIT
GET TO THE CHOPPER c
HERE IS MY INVITATION c
GET UP 1
ENOUGH TALK
YOU HAVE NO RESPECT FOR LOGIC
GET TO THE CHOPPER l
HERE IS MY INVITATION l
GET DOWN 1
ENOUGH TALK
CHILL
I'LL BE BACK c
HASTA LA VISTA, BABY
IT'S SHOWTIME
HEY CHRISTMAS TREE p
YOU SET US UP 0
GET YOUR ASS TO MARS p
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
HEY CHRISTMAS TREE n
YOU SET US UP 0
GET YOUR ASS TO MARS n
DO IT NOW q p
HEY CHRISTMAS TREE g
YOU SET US UP 42
GET TO THE CHOPPER g
HERE IS MY INVITATION n
YOU ARE NOT YOU YOU ARE ME 2
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE g
GET TO THE CHOPPER p
HERE IS MY INVITATION p
GET UP 2
ENOUGH TALK
GET YOUR ASS TO MARS n
DO IT NOW q p
GET TO THE CHOPPER g
HERE IS MY INVITATION 5
LET OFF SOME STEAM BENNET n
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE g
TALK TO THE HAND "t"
BULLSHIT
TALK TO THE HAND "f"
YOU HAVE NO RESPECT FOR LOGIC
BULLSHIT
TALK TO THE HAND "f"
YOU HAVE NO RESPECT FOR LOGIC
YOU HAVE BEEN TERMINATED

Try it online!
(This is my first post on codegolf.SE, please let me know if this is formatted incorrectly. I realize this byte count is not competitive, this is just for fun.)

Jelly, 10 bytes
+2ÆfL<3aÆP

Try it online!

Pari/GP, 29 bytes
The 3*isprime(n) trick is stolen from Jonathan Allan 's answer.
n->bigomega(n+2)<3*isprime(n)

Try it online!

Python with sympy,  69  56 bytes
-13 bytes thanks to alephalpha (by upgrading to sympy 1.1 and using primeomega(n+2) to replace sum(factorint(n+2).values()))
...taking over from Gryphon's deleted submission.
from sympy import*
lambda n:primeomega(n+2)<3*isprime(n)

An unnamed function returning True for Chen primes and False otherwise.
Counts the factors of n+2 by summing its prime factor's multiplicities.
Note that 3 is multiplied by isprime(n) before the < comparison is made, so for non-prime n the code tests if n+2 has less than 0 factors (always yielding False), while for prime n it checks whether n+2 is prime or semi-prime.

@Gryphon - I took over, it may be beatable without any imports however.

I've been outgolfed! The 3*isprime(n) trick is what I was looking for in cleaning up the conditional statement.

Ah, @icosahedron, I had not noticed yours, sorry - this is so similar I would have just commented to help you to improve yours. Feel free to treat this answer as such, just let me know and I'll delete this one.

I think sympy has a primeomega function.

@alephalpha Thanks, just upgraded to 1.1 to see it, that'll save bytes!

Java 8, 85 84 83 bytes
n->{int a=n+2,b=0,c=0,i=1;for(;i++<n;b+=n%i<1?1:0)c+=a%i<1?1:0;return n>1&b<2&c<3;}

-1 bytes thanks to @OlivierGrégoire by using an iterative approach instead of recursive.
Explanation:
Try it here.
n->{            // Method with integer parameter and boolean return-type
  int a=n+2,    //  Start `a` at the input + 2
      b=0,c=0,  //  Start `b` and `c` at 0
      i=1;      //  Start `i` at 1
  for(;i++<n;   //  Loop from 1 to `n` (and raise `i` immediately by 1)
    b+=n%i<1?   //   If the input is divisible by `i`
        1       //    Raise `b` by 1
       :        //   Else:
        0)      //    Leave `b` as is
    c+=a%i<1?   //   If the input + 2 is divisible by `i`:
        1       //    Raise `c` by 1
       :        //   Else:
        0;      //    Leave `c` as is
                //  End of loop (implicit / single-line body)
  return n>1    //  Return if the input is larger than 1
         &b<2   //   And `b` is now smaller than 2
         &c<3;  //   And `c` is now smaller than 3
}               // End of method

The iterative version is just a byte shorter: n->{int N=n+2,f=0,F=0,d=1;for(;d++<n;f+=n%d<1?1:0)F+=N%d<1?1:0;return n>1&f<2&F<3;}.

JavaScript (ES6), 63 61 bytes

g=(e,i=e)=>i--<3?1:e%i?g(e,i):g(i)+1
f=e=>e>1&g(e)<2&g(e+2)<3
Test cases:
<textarea id=i rows=6 oninput="go()">101
223
233
1</textarea>

Defines a function f that takes n as argument and returns the result. Im very happy with how g turned out; it counts the number of prime factors in a number.
2 bytes saves thanks to Kevin Cruijssen's & trick.
Ungolfed
Ω = (n,          // Ω(n) = number of n's prime factors, n > 1.
    i = n) =>    // Start iterating from i = n - 1. Since we'll immediately
                 // decrement i, n is used here.
    --i          // Immediately decrement i.

    < 2          // If i = 0 or i = 1, n is a prime at this point.
    ? 1 :        // Therefore Ω(n) = 1.

    n % i != 0 ? // If n is not divisible by i,
    Ω(n, i)      // try again with i := i - 1 (immediately decremented, so use i).

    : Ω(i) + 1   // n is divisible by i. Since we're counting down from n - 1
                 // and i is the first such number, i is n's largest non-trivial
                 // divisor, and thus n/i is a prime.
                 // Therefore Ω(n) = Ω(i) + Ω(n/i) = Ω(i) + 1.

is_chen = n =>     // An integer n ≥ 1 is a Chen prime if and only if:
    n > 1          // n > 1,
    & Ω(n) < 2     // Ω(n) = 1 < 2, i.e. n is a prime, and
    & Ω(n + 2) < 3 // Ω(n + 2) < 3, i.e. n + 2 is a prime or a semiprime.

Can't you change both && to &? Since 0/1 are truthy/falsey values in JS as well?

@KevinCruijssen That seems to work. Too bad | and & don't short-circuit, that might save even more bytes in g.

Japt, 22 20 19 13 12 bytes
U°j ©2¨°Uk l

6 bytes saved thanks to obarakon's suggestion of a different method.

Test it

Mathematica, 28 bytes
PrimeQ@#&&PrimeOmega[#+2]<3&

PHP, 64 bytes
for($i=$n=$argn+2;--$i;$argn%$i?:$q++)$n%$i?:++$p;echo$p<4^--$q;

prints 0 for truthy, other integers for falsy. Run as pipe with -nR or try it online.
breakdown
for($i=$n=$argn+2;--$i; # loop $i from N+1 to 1
    $argn%$i?:$q++)         # if $i divides N, increment $q
    $n%$i?:++$p;            # if $i divides N+2, increment $p
echo$p<4                # $p is 1 for a prime, 3 for a semiprime
    ^--$q;              # $q is 2 for prime; so this is 1^1 (==0) for a Chen Prime

consistent falsy value, 65 bytes:
for($i=$n=2+$k=$argn;--$i;$k%$i?:$q++)$n%$i?:++$p;echo$p<4&$q==2;

prints 1 for truthy and 0 for falsy.

Regex (ECMAScript), 31 bytes
^(?!((xx+)(\2(xx))*)(\1\4)+$)xx

Try it online! (showing all Chen primes ≤ 1000)
Given a string of n xs this regex will match if and only if n is a Chen prime.
It asserts that n is greater than 2 and that the string is not of the form ((xx+)(\2(xx))*)(\1\4)+
This regex has two meanings, depending on how many times (\2(xx)) is repeated.
When it is repeated 0 times, the regex can be simplified to (xx+)\1+, which matches composite numbers.
When it is repeated a positive number of times, the regex is equivalent to ((xx+)(\2xx)+)(\1xx)+
That regex requires some explanation, however, I will provide little insight.
If you go through the algebra you find that ((xx+)(\2xx)+)(\1xx)+ matches numbers of the form a*b*c-2 where a≥4,b≥2,c≥2.
So it will match (almost) whenever n+2 has more than 2 prime factors. (i.e neither prime nor semi-prime)
Note that it doesn't match 6, 10, 16 or 25, but that this doesn't matter, because they are all composite.
So (?!((xx+)(\2(xx))*)(\1\4)+$) will match as long as n is not composite, and n+2 is either prime or semi-prime.
Unfortunately this includes 1 (and 0), so we then check that n is at least 2 with xx
A couple of different "31-byters" are:
^xx(?!((x*)(\2xx)+)\1?(\1xx)*$)
^(?!(xx((x*)(\3xx)+))\2?\1*$)xx

Python 3 with SymPy, 73 71 bytes
lambda n:(sum(factorint(n+2).values())<3)&isprime(n)
from sympy import*

Try it online!

This is a more-golfed version of an answer posted here earlier, but it seems to have been deleted.

Thanks to @JonathanAllan for saving 2 bytes!

...also note that you do not need f=, creating an unnamed function is fine for code-golf.

PHP, 87 bytes
for($b=($a=$argn)+$i=2;2<$a+$b;)$a%$i?$b%$i?$i++:++$d*$b/=$i:++$c*$a/=$i;echo$c<2&$d<3;

Try it online!
PHP, 87 bytes
for(;$n<2;)for($a=$argn+$n++*$i=2;1<$a;)$a%$i?$i++:++$r[$n]*$a/=$i;echo$r[1]<2&$r[2]<3;

Try it online!

APL NARS, 23 chars
{1≥⍵:0⋄(1=⍴π⍵)∧3>⍴π⍵+2}

Here π⍵ return the array of factors of ⍵ different from 1; some test:
  f←{1≥⍵:0⋄(1=⍴π⍵)∧3>⍴π⍵+2}
  f 101
1
  f 223
0
  f 233
1
  f 1
0
  f ¯10
0

Ruby, 49 41 bytes
->n{/^(.?|((..+)\3+))(\2+|..)$/!~?l*n+=2}

Try it online!
Thanks H.PWiz for -8 bytes
How?
First thing, get a string of 'l' repeated n+2 times. Then apply a regex to check if:

Length is 2 or 3 (.?)(..)
Length is a composite number plus 2 ((..+)\1)(..)
Length is a product of at least 3 numbers ((..+)\2)\1+

The 2 regex parts generate a fourth case which doesn't make sense and is safe to ignore: (.?)\2+, that resolves to empty string or a single character because \2 is empty.

You can merge the two halves of your | closer together: ^((..+)\2+)(\1+|..)$. Also, a neat coincidence that you attempted this problem with regex at a similar time to me :)

I believe that you can use . instead of .? since the input is always at least 1

Husk, 9 bytes
&<3Lp+2¹ṗ

Try it online!
Explanation
&<3Lp+2¹ṗ
        ṗ input is prime?
&         and
   L      Length of
    p     prime factorization of
     +2¹  input + 2
 <3       less than 3?

Julia, 59 bytes
x->((0∉x%(2:x-1))&(length(find(x->x==0,(x+2)%(2:x)))<=2))

Pyt, 11 bytes
3*isprime(x) stolen from Jonathan Allan's answer
←Đṗ3*⇹2+ḋŁ>

Haskell, 163 bytes
p k=last$(not$elem 0(map(mod k)[2..k-1])):[1>2|k<=1]
r=round
s n=p(r n)||any(\(a,b)->p(r a)&&p(r b))[(n/x,x)|x<-[2..n],n/x==(fromIntegral.r)n/x]
c n=p(r n)&&s(n+2)

Try it online!

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Finite Element Grid I
Introduction
Don't worry - no knowledge in mathematics is needed. It is possible to just skip the motivation part, but I think it is nice if a puzzle has a background story. Since the title contains the number I there will be more puzzles of this kind, if you like them. Feedback is highly appreciated. I hope you have fun with this puzzle! :)
Sandbox-Answer

Motivation
Many processes in the real life can be modelled with differential equations.
A differential equation is an equation contain some differential expression, e.g.
x'(t) = λx(t)

This is a ordinary (= 1D) differential equation (ODE). And the solution to this is simply x(t) = x₀e^{λt} for any x₀∈ℝ. This ODE can be used as model for population growth (rabbits multiplying exponentially) or radiation decay. In both cases x̧₀ is the initial population / initial amount of material.
Now not everything in the world of physics can be modelled with ODEs. Since we live in a multidimensional world there should be differential equations with more than just one component, right?
These equations are named partial differential equations (PDE).
For example flow fields can (in some cases) be modelled using the Stokes Equation:
-Δv + ∇p = f in Ω
     ∇∘v = 0 in Ω

where v is the velocity and p is the pressure of the flow. And Ω⊂ℝ² is just the geometry on which the equation is solved - e.g. a tube.
Now if you want to solve these equations there is a method called Finite Element Method. And this method requires a grid of your geometry. In most cases these grids contain quadrilaterals or triangles.
For this code-golf we will use a very simple grid:
(0,1)                     (1,1)
  x-----x-----x-----x-----x
  |     |     |     |     |
  |  1  |  2  |  3  |  4  |
  |     |     |     |     |
  x-----x-----x-----x-----x
  |     |     |     |     |
  |  5  |  6  |  7  |  8  |
  |     |     |     |     |
  x-----x-----x-----x-----x
  |     |     |     |     |
  |  9  | 10  | 11  | 12  |
  |     |     |     |     |
  x-----x-----x-----x-----x
  |     |     |     |     |
  | 13  | 14  | 15  | 16  |
  |     |     |     |     |
  x-----x-----x-----x-----x
(0,0)                     (1,0)

This 2D-grid consists of 5x5 points in (2D) unit cube [0,1]×[0,1]⊂ℝ². Therefore we have 16 cells. The four Cartesian coordinates and the numbers in the cells are not part of the grid. They are just to explain the Input/Output.
There is a connection between the grid-size and the accuracy of the solution - the finer the grid the higher the accuracy. (Actually that is not always true.)
But a finer grid also has a draw-back: The finer the grid the higher the computation cost (RAM and CPU). So you only want to refine your grid at some locations. This idea is called adaptive refinement and is usually based on the behaviour of the solution - e.g. thinking about the flow problem above: refine that part of the grid, where the solution is turbulent, don't refine if the solution is boring.
Task
The task is to implement this adaptive refinement in a general way.
Since we don't solve any PDE in this code-golf the criteria to refine grid cells is based on a circle disk. This circle disk is simply defined by the midpoint p=[p0,p1]∈[0,1]² and the radius r ∈ [0,1].
Every cell intersecting with that disk (including boundaries - see Example 1) will be refined.
The output is the 5x5 grid above with the refined cells.
Asked Questions
What is the purpose of 'x'?
'x' represents nodes/vertices,  '-' and '|' edges.
Refinement of a cell means, that you split one cell into 4:
  x-----x       x--x--x
  |     |       |  |  |
  |     |   >   x--x--x
  |     |       |  |  |
  x-----x       x--x--x

Examples
Input: p=[0,0] r=0.5
Output:
  x-----x-----x-----x-----x
  |     |     |     |     |
  |     |     |     |     |
  |     |     |     |     |
  x--x--x-----x-----x-----x
  |  |  |     |     |     |
  x--x--x     |     |     |
  |  |  |     |     |     |
  x--x--x--x--x-----x-----x
  |  |  |  |  |     |     |
  x--x--x--x--x     |     |
  |  |  |  |  |     |     |
  x--x--x--x--x--x--x-----x
  |  |  |  |  |  |  |     |
  x--x--x--x--x--x--x     |
  |  |  |  |  |  |  |     |
  x--x--x--x--x--x--x-----x

The midpoint is located in (0,0) with radius 0.5.

Cell 13: Completely inside the cell.
Cell 9 : Intersects, since lower left corner has coords (0,0.25).
Cell 14: Intersects, since lower left corner has coords (0.25,0).
Cell 5 : Intersects, since lower left corner has the coordinates (0, 0.5).
Cell 15: Intersects, since lower left corner has the coordinates (0.5, 0).
Cell 10: Intersects, since lower left corner has the coordinates (0.25, 0.25).
The distance from (0,0) to that corner is √(0.25²+0.25²) < 0.36 < 0.5.

Cell 11:  Does not intersect, since the closest point is the lower left
corner with coordinate (0.5,0.25), so the distance is
√(0.5² + 0.25²) > √(0.5²) = 0.5

Input: p=[0.5,0.5] r=0.1
Output:
  x-----x-----x-----x-----x
  |     |     |     |     |
  |     |     |     |     |
  |     |     |     |     |
  x-----x--x--x--x--x-----x
  |     |  |  |  |  |     |
  |     x--x--|--x--x     |
  |     |  |  |  |  |     |
  x-----x--x--x--x--x-----x
  |     |  |  |  |  |     |
  |     x--x--x--x--x     |
  |     |  |  |  |  |     |
  x-----x--x--x--x--x-----x
  |     |     |     |     |
  |     |     |     |     |
  |     |     |     |     |
  x-----x-----x-----x-----x

The midpoint is located in (0.5,0.5) with radius 0.1.
Therefore the circle is completely inside the union of cells 6,7,10 and 11.
It does not touch any 'outer' boundaries of these four cells.
So the only refined cells are these four.

Input: p=[0.35,0.9] r=0.05
Output:
  x-----x--x--x-----x-----x
  |     |  |  |     |     |
  |     x--x--x     |     |
  |     |  |  |     |     |
  x-----x--x--x-----x-----x
  |     |     |     |     |
  |     |     |     |     |
  |     |     |     |     |
  x-----x-----x-----x-----x
  |     |     |     |     |
  |     |     |     |     |
  |     |     |     |     |
  x-----x-----x-----x-----x
  |     |     |     |     |
  |     |     |     |     |
  |     |     |     |     |
  x-----x-----x-----x-----x

Cell 2: Intersecting with the circle.
Cell 1: Not refined, since the right edge has x-coordinate 0.25 < 0.35-0.05 = 0.3.
Cell 3: Not refined, since the left edge has x-coordinate 0.5 > 0.35+0.05 = 0.4.
Cell 6: Not refined, since the top edge has y-coordinate 0.75 < 0.9 - 0.05 = 0.85.

Rules
Since this is my first puzzle / golf help is appreciated.

code-golf: Smallest byte size wins.
Trailing / Leading whitespaces are allowed.
The Cartesian coordinates are not part of the grid, and should not be seen in the output.
Only allowed chars are '-', '|', 'x' and ' '
Input: All three numbers will be floats. It does not matter if your input is a tuple (p0,p1) and a number r, or three numbers, or one array - just be reasonable.

What does the circle have to do with the adaptivity? Do we always use a 5x5 grid? where do we use x-es and where don't we use them? Also I think the whole motivation part could be omitted, as it does not help understand the the challenge itself.

@flawr 1) "The task is to implement this adaptive refinement in a general way". With other words to implement the general concept of refining this grid in a specific region. For this golf it is a simple circle. Usually in numerics this region would depend on the solution. // 2) Yes only this grid, I will edit the question about what each char stands for.  3) Yes, it could be omitted. But I don't like that, in the same way I wouldn't have read Lord of the Rings on only one page.

@flawr : I am really sorry. There has been a mistake in the examples, it is corrected and should be clear now.

I think following needs clarification: What does "cell touching the circle" mean? Do one (or more?) corner points have to be within the circle? Or is it about the center? Or is it enough if one edge of a cell gets crossed? Please include the exact specs to that in the challenge. Then I think it should be good to go.

@flawr Changed "touching" to "intersecting". So if there is any common point of (cell + cell boundary)  and (circle disk + circle)  the cell will be refined.  I added explanations to the output examples. Thanks for your remark.

Charcoal, 107 105 106 bytes
Ｆ²«x⁵↷²x³↷»Ｆ³«Ｃ⁰±⁴Ｃ⁶¦⁰»Ｆ⁴«Ａ⁻×⁴ＩθιεＦ⁴«Ａ⁻×⁴Ｉηκδ¿¬›⁺Ｘ⎇›ε¹⁻ε¹∧‹ε⁰ε²Ｘ⎇›δ¹⁻δ¹∧‹δ⁰δ²Ｘ×⁴Ｉζ²«Ｊ⁺³×⁶ι⁻²×⁴κＰ|x|xＰ-x--x

Try it online! Link is to verbose version of code, not that it helps. Edit: Saved 2 bytes by handling the reversed sense of the Y-axis in a different way, but added a byte to handle a clarification in the question. Explanation:
Ｆ²«x⁵↷²x³↷»

Prints a cell. It does this by printing an x, then printing 5 (which expands to ----- because the default cursor direction is right), then it rotates downwards, prints another x, prints 3 (which now expands to three |s downwards), then rotates left. Doing all that twice completes the cell.
Ｆ³«Ｃ⁰±⁴Ｃ⁶¦⁰»

There are four cells horizontally and vertically, so the cell needs to be copied horizontally and vertically three times. The vertical copy is done upwards to simplify the calculation below.
Ｆ⁴«Ａ⁻×⁴ＩθιεＦ⁴«Ａ⁻×⁴Ｉηκδ

The 16 cells are now looped over using a four by four nested loop. The coordinates of the midpoint are multiplied by 4, scaling them from 0 to 4, which corresponds to our loop indices which are subtracted, so the resulting variables are now relative to the cell's bottom left corner.
¿¬›⁺Ｘ⎇›ε¹⁻ε¹∧‹ε⁰ε²Ｘ⎇›δ¹⁻δ¹∧‹δ⁰δ²Ｘ×⁴Ｉζ²«

The variables are now compared to the range 0 to 1 that represents the relative quadrupled cell coordinates. If they lie outside this range it means that the midpoint lies outside the cell, so the distance to the range is squared and the sum of the squares compared to the square of the quadrupled radius. If it is not greater, then the cell needs to be refined.
Ｊ⁺³×⁶ι⁻²×⁴κＰ|x|xＰ-x--x

The cursor is moved to the centre of the cell to be refined. The string x|x is printed vertically (both up and down), while the string x--x is printed horizontally (both left and right). (The middle xs overlap.)

Although, there's not a huge difference, You are drawing '+' instead of 'x' at the inner vertices.

I am sorry, but I made a mistake in the examples, see the "Asked Questions" part :/

@officialaimm What a silly oversight. Fortunately the fix is just to change the + at the end to x.

@P.Siehr I have updated the code and it should now match the updated examples.

Great, but sadly the question is still on hold. I think everything is clear now.


text:
Greek Syllabication (Simplified)
INTRO
Let's say you write a passage and you are close to the end of the line wanting to write down a large word. In most languages, you just leave some blank and move to the next line, like a sir.

Example - English:

blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah   blah this man is      unaccountable
But if you are (un)lucky enough to be Greek, when you are close to terminate a line, you cannot just move to the next one. Everything must look nice and in balance, so you SEPARATE the word

Example - Greek:

μπλα μπλα μπλα μπλα μπλα μπλα μπλα μπλα μπλα μπλα μπλα μπλα αυτός ο άνδρας είναι ανεξή-
γητος
Of course this separation is not done randomly, but instead there is a complicated set of rules, as to how & when to separate, which is actually an entire learning chapter back in primary school that every kid hates.
OBJECTIVE
You are given a greek word (just a string of greek letters). You need to do a greek syllabication, i.e. separate the greek word in syllabes, according to the set of rules given below, so that the user will have the option to separate the word in the end of the line correctly.
Examples:
1) αγαπη (love) = α-γα-πη
2) ακροπολη (acropolis) = α-κρο-πο-λη
3) βασικα (basically) = βα-σι-κα
ALPHABET & SIMPLIFIED RULES
consonants: β,γ,δ,ζ,θ,κ,λ,μ,ν,ξ,π,ρ,σ,τ,φ,χ,ψ
vowels: α,ε,η,ι,ο,υ,ω
rule 0) Every vowel defines a different syllable, unless rule 4
rule 1) When there is consonant between two vowels, it goes with the second vowel
(ex. γ --> α-γα-πη)
rule 2) When there are two consonants between two vowels, they go with the second vowel, if there is a greek word starting from these two consonants (we assume that that's always the case in our exercise)
(ex. βλ --> βι-βλι-ο)
rule 3) When we have 3 consonants between two vowels-->same as rule 2
rule 4) Following configurations are considered as "one letter" and are never separated: ει, οι, υι, αι, ου, μπ, ντ, γκ, τσ, τζ
(ex. α-γκυ-ρα)
rule 5) Always separate same consonants
(ex. αλ-λη)
YOUR TASK
Your code should take as input string (or some other format you wish) a greek word and return the same word, with dashes in between, determining the points where the word can be separated, i.e. do a greek syllabication.
TestCases:

[πολη (city)] --> [πο-λη]
[τρεχω (run)] --> [τρε-χω]
[αναβαση (climbing)] --> [α-να-βα-ση]
[οαση (oasis)] --> [ο-α-ση]
[ουρα (tail)] --> [ου-ρα]
[μπαινω (enter)] --> [μπαι-νω]
[εχθροι (enemies)] --> [ε-χθροι]
[ελλαδα (greece)] --> [ελ-λα-δα]
[τυροπιτα (cheese pie)] --> [τυ-ρο-πι-τα]
[αρρωστη (sick)] --> [αρ-ρω-στη]

Shortest code wins, but every effort is appreciated :)

(Loosely) Related

Did the greeks change the monotonic system to a-tonic due to economic crisis?

Mathematica has a syllabication/hyphenation built-in that only works for English words. 25 bytes: #~WordData~"Hyphenation"&

with dashes in between -- Is returning an array of strings okay?

It seems like it's possible to scrap part of rule 4, is there a missing test case?

@bartavelle your code should not only work for the given testcases, but for all cases that can be created according to the rules. It would be a lot of work to generate a testcase for every configuration of the 4th rule.

@ovs I understand, but as they are consonants only, I don't see how removing them changes the algorithm

Perhaps with somethingl like "μππ" ?

@Jenny_mathy:i didn't include tones, for simplicity, otherwise it gets really complicated
@ JungHwan Min: Yes, format output is up to you
@ bartavelle: Rule 4 is put mainly for the vowels. In practice it is used for consonants as well (if in rule 2,3 there is no greek work), but in our simplified version, it wont be needed.

@koita_pisw_sou oh wow, this really looks complicated!

@bartavelle: yeah and there are also some rules on top of that including special cases and tones. but for simplicity as i said, i have removed all those restrictions and assumed there is always a greek word in case of conflict

Haskell, 222 201 bytes
s""=[]
s x|c?"ειοιυιαιου"=(a++c):s d|h:e:f:g<-b,e==f=(a++[h,e]):s(f:g)|e:f<-b=(a++[e]):s f|2>1=[a]where(a,b)=break(`elem`"αεηιουω")x;(c,d)=splitAt 2 b
i?(x:y:z)=i==[x,y]||i?z
i?""=1>2

Try it online!

Python, 183 bytes
def f(s,r=''):
 for p,c in zip(' '+s,s):
  if p in'αεηιουω'and(p+c)not in 'ει,οι,υι,αι,ου,μπ,ντ,γκ,τσ,τζ'or p==c:yield r+p;r=''
  elif p>' ':r+=p
 yield r+c

Try it online!

Bash + sed, 188 187 bytes
sed -re $(echo 's/([^@\1/\1-\1/g;s/[εουα]ι|ου|μπ|ντ|γκ|τσ|τζ|./-&/g;s/!(!)?(!)?([@/\1\3\5\6/g;s/-([^@(-|$)/\1/g;s/-+/-/g;s/.//'|sed 's/!/([^-@-/g;s/@/αεηιουω])/g')

Try it online!
Uses a sed program compressed with... sed. The actual sed program looks like this:
# replace consecutive consonants: αρρωστη -> αρ-ρωστη
s/([^αεηιουω])\1/\1-\1/g
# separate "letters": αρ-ρωστη -> -α-ρ---ρ-ω-σ-τ-η
s/[εουα]ι|ου|μπ|ντ|γκ|τσ|τζ|./-&/g
# attach preceding consonants to vowels: -α-ρ---ρ-ω-σ-τ-η -> -α-ρ---ρω-στη
s/([^-αεηιουω])-(([^-αεηιουω])-)?(([^-αεηιουω])-)?([αεηιουω])/\1\3\5\6/g
# attach lone consonants to previous vowel: -α-ρ---ρω-στη -> -αρ--ρω-στη
s/-([^αεηιουω])(-|$)/\1/g
# remove extra dashes: -αρ--ρω-στη -> -αρ-ρω-στη
s/-+/-/g
# remove initial dash: -αρ-ρω-στη -> αρ-ρω-στη
s/.//


text:
Subtract my odds from my evens
Given a non-negative integer, return the absolute difference between the sum of its even digits and the sum of its odd digits.
Default Rules

Standard Loopholes apply.

You can take input and provide output by any standard Input / Output method.

You may take input as a String, as an Integer or as a list of digits.

This is code-golf, so the shortest code in bytes in every language wins!

Test Cases

Input ~> Output

0 ~> 0 (|0-0| = 0)
1 ~> 1 (|1-0| = 1)
12 ~> 1 (|2-1| = 1)
333 ~> 9 (|0-(3+3+3)| = 9)
459 ~> 10 (|4-(5+9)| = 10)
2469 ~> 3 (|(2+4+6)-9| = 3)
1234 ~> 2 (|(2+4)-(1+3)| = 2)

May we take input as list of ints?

@Mr.Xcoder That wouldn't be too trivial. It makes the challenge unnecessarily complicated and is an arbitrary requirement that adds bytes.

@Mr.Xcoder Don't make chameleon challenges. The most important sentence you might want to look at here is Combining two or more unrelated core challenges into one — consider splitting the challenge up into separate challenges or dropping unnecessary parts

I have changed the rules @Okx. Taking as a list of digits is now allowed. I still don't think it would make it to fluffy though.

333 ~> 9 (|(3+3+3)-0| = 9) should be 0-(3+3+3), though the outcome is the same.

@MagicOctopusUrn Ok, fixed

Jelly, 6 bytes
-*æ.¹A

Try it online!
How it works
-*æ.¹A  Main link. Argument: A (digit array)

-*      Raise -1 to A's digits, yielding 1 for even digits and -1 for odd ones.
    ¹   Identity; yield A.
  æ.    Take the dot product of the units and the digits.
     A  Apply absolute value.

You can save 1 byte by taking input as a list.

I am taking input as a list.

I'm talking about revision 2.

Raise -1 to A's digits, yielding 1 for even digits and 0 for odd ones. umm, I think you messed something a little bit or something...

@EriktheOutgolfer Darn off-by-one errors.

you're probably thinking too binary...at least it was only off by a bit...or two, maybe :)

SHENZHEN I/O MCxxxx scripts, 197 (126+71) bytes
Chip 1 (MC6000):

x0: Input as list
x2: Chip 2 x1
x3: MC4010

mov 0 dat
j:
mov x0 acc
mov 70 x3
mov -1 x3
mov acc x3
mul x3
mov acc x2
mov dat acc
add 1
tlt acc 3
mov acc dat
+jmp j
slx x0

Chip 2 (MC4000):

p0: Output
x0: MC4010
x1: Chip 1 x2

mov x1 acc
add x1
add x1
mov 30 x0
mov 0 x0
mov acc x0
mov x0 p0
slx x1

(You can us a <!-- --> comment to get code right after a list, instead of filler text. Or indent the code with 4 more spaces.)

Python 2, 39 bytes
Takes integer as list. Try it online
lambda A:abs(sum((-1)**i*i for i in A))

-3 bytes thanks to @Mr.Xcoder
-1 byte thanks to @ovs

Use [i,-i][i%2] instead of i%2and i or -i for 40 bytes.

(-1)**i*i for 39 bytes

TI-Basic, 18 9 bytes
abs(sum((-1)^AnsAns

Explanation
Multiplies each digit in the list by -1 to its power, negating each odd digit, before summing them.

Mathematica, 20 bytes
Abs@Tr[(-1)^(g=#)g]&

takes as input a list of digits
special thanx to @LLlAMnYP for letting me know about the "new rules"

beat me to it! :) You probably don't need the *.

now that OP has relaxed the requirements your code can be trivially much shorter. +1

C (gcc), 59 58 57 bytes
i;f(char*v){for(i=0;*v;v++)i+=*v%2?*v-48:48-*v;v=abs(i);}

Try it online!

If it helps, I have changed the rules and you are now able to take input as a list. Hopefully that would save bytes. I don't know C, so it's just a suggestion.

R, 30 29 bytes
abs(sum((d=scan())-2*d*d%%2))

d = scan() takes the input number by one digit after the other.
-1 byte thanks to @Giuseppe!

This is quite excellent! There's a 1 byte saving to be made, though: abs(sum((d=scan())-2*d*d%%2))

@Giuseppe Thanks, good tip, edited!

C#, 57 bytes
namespace System.Linq{i=>Math.Abs(i.Sum(n=>n%2<1?n:-n))}

Takes input as i and sums the integers by turning the odds to negative.

First answer here. No clue if I need to wrap this whole thing into a actual C# program and count those bytes too.

You have to include the boilerplate namespace System.Linq{ and make an actual function. See the other C# answer for reference

@Mr.Xcoder Thanks for the info. Think I got. Almost doubled my byte count  =(  lol

Yeah, C# is not really the best golfing language

@Mr.Xcoder Nope, but I thought the rules got relaxed because I saw a slim version on the first page without the namespace stuff and didn't see a Main. Only reason I thought I'd answer with it. Oh wells.

And by the way, Welcome to PPCG!

EDIT: A more golf-centered approach:
EXCEL, 42 36 29 bytes
Saved 6 bytes thanks to Magic Octopus Urn
Saved 7 bytes by using Dennis' -1^ approach (which, I just learned, works on arrays in excel)
=ABS(SUMPRODUCT(A:A,-1^A:A))

Takes a list of integers in A column for input.  Probably can be golfed further, or by using the string version, taking a string in A1 for input.
EXCEL, 256 bytes
=ABS(LEN(SUBSTITUTE(A1,1,""))-2*LEN(SUBSTITUTE(A1,2,""))+3*LEN(SUBSTITUTE(A1,3,""))-4*LEN(SUBSTITUTE(A1,4,""))+5*LEN(SUBSTITUTE(A1,5,""))-6*LEN(SUBSTITUTE(A1,6,""))+7*LEN(SUBSTITUTE(A1,7,""))-8*LEN(SUBSTITUTE(A1,8,""))+9*LEN(SUBSTITUTE(A1,9,""))-5*LEN(A1))

disclaimer, only works for numbers less than 100 in length

Switching to A:A saves 6 bytes and removes that problem.

Wow, rarely does my constructive criticism save bytes, +1 for your Excel knowledge sir.

Also, due to You may take input as a String, as an Integer or as a list of digits. your 42 byte answer should be the answer you use.

The first was a humorous attempt, but I'll switch them around.

I'm bad enough at excel that the humor was lost on me ;).

JavaScript (ES6), 43 38 bytes
Takes input as a string an array of digits.
a=>a.map(d=>s+=d&1?d:-d,s=0)&&s>0?s:-s

Test cases

let f =

a=>a.map(d=>s+=d&1?d:-d,s=0)&&s>0?s:-s

console.log(f([1]))     // ~> 1 ( |1-0| = 1)
console.log(f([0]))     // ~> 0 ( |0-0| = 0)
console.log(f([1,2]))    // ~> 1 ( |1-2| = 1)
console.log(f([4,5,9]))   // ~> 10 ( |4-(5+9)| = 10)
console.log(f([2,4,6,9]))  // ~> 3 ( |(2+4+6)-9| = 3)
console.log(f([3,3,3]))   // ~> 9 ( |(3+3+3)-0| = 9)

Japt, 8 bytes
x_*JpZÃa

Test it online!
Explanation
 x_  *JpZÃ a
UxZ{Z*JpZ} a
                Implicit: U = list of digits
UxZ{     }      Take the sum of each item Z in U mapped through the following function:
      JpZ         Return (-1) ** Z
    Z*            times Z. This gives Z if even, -Z if odd.
           a    Take the absolute value of the result.
                Implicit: output result of last expression

APL, 8 bytes
|⊢+.×¯1*⊢

Try it online!
How?
¯1*⊢ - -1n for n in ⍵
[4 5 9 → 1 ¯1 ¯1]
⊢+.× - verctorized multiplication with o, then sum
[+/ 4 5 9 × 1 ¯1 ¯1 → +/ 4 ¯5 ¯9 → ¯10]
| - absolute value

Can you please provide a testing environment?

@Mr.Xcoder added

|⊢+.×¯1*⊢ with the new input spec.

@Adám thanks. can't believe I missed product.

can you provide more detail in the explanation?  can this method be ported to J?  i'm currently using key (see my answer) but this method might shave off a few bytes...

@Jonah does this edit makes it any clearer?

@Jonah [:|]+/ .*_1^] or [:|[:+/]*_1^]

ty @Adám and Uriel

You mean to say that APL doesn't have an operator to do this?  I'm extremely disappointed...

Husk, 7 bytes
≠0ṁṠ!¡_

Try it online!
Takes a list of digits as input.
Still missing an "abs" builtin, but a good result all the same :)
Explanation
Ṡ!¡_ is a function that takes a number n and then applies n-1 times the function _ (negation) to n. This results in n for odd n or -n for even n.
ṁ applies a function to each element of a list and sums the results.
≠0 returns the absolute difference between a number and 0.

Neim, 7 bytes
ΓDᛃΞ}

Explanation:
Γ        Apply the following to each element in the input array
 D         Duplicate
  ᛃ        Modulo 2, then perform logical NOT
   Ξ       If truthy, then:
            Multiply by -1
      }  Close all currently running loops/conditionals etc
        Sum the resulting array

Who doesn't have a builtin that mods by 2 then logically NOTs the result?

@cairdcoinheringaahing It's basically 'check if even'

Mathematica, 67 bytes
(s=#;Abs[Subtract@@(Tr@Select[IntegerDigits@s,#]&/@{EvenQ,OddQ})])&

Julia 0.5, 19 bytes
!x=(-1).^x⋅x|>abs

Try it online!

PHP, 54 bytes
for(;~$n=$argn[$i++];)${eo[$n&1]}+=$n;echo abs($e-$o);

Try it online!
PHP, 57 bytes
store the even and odd sums in an array

for(;~$n=$argn[$i++];)$r[$n&1]+=$n;echo abs($r[0]-$r[1]);

Try it online!
PHP, 57 bytes
store the even and odd sums in two variables

for(;~$n=$argn[$i++];)$n&1?$o+=$n:$e+=$n;echo abs($e-$o);

Try it online!

54 bytes: odd sum in ${1} and even sum in ${0}: while(~$n=$argn[$i++])${$n&1}+=$n;echo abs(${1}-${0});

@Titus nice I think  for(;~$n=$argn[$i++];)${eo[$n&1]}+=$n;echo abs($e-$o); is also a nice variant. Or we can do it more nathematical for(;~$n=$argn[$i++];$s+=$n)$u+=($n&1)*$n;echo abs($s-2*$u); and for(;~$n=$argn[$i++];)$u+=(($n&1)-.5)*2*$n;echo abs($u); is an interesting way

Haskell, 47 42 39 38 26 25 bytes
-1 thanks to nimi
-12 thanks to Bruce
-1 thanks to xnor
abs.sum.map(\x->x*(-1)^x)

Try it online!

You can inline s: ((*)=<<((-1)^)).

It's one byte shorter to just write (\x->x*(-1)^x).

05AB1E, 6 bytes
Thanks to Dennis for the -1 power trick. Takes input as a list of digits
®sm*OÄ

Try it online!
Explanation
®sm*OÄ                                               Example [4, 5, 9]
®      # Push -1                                   % STACK: -1
 sm    # Take -1 to the power of every number      % STACK: [1, -1, -1]
         in the input list
   *   # Multiply with original input              % Multiply [1, -1, -1] with [4, 5, 9] results in STACK: [4, -5, -9]
    O  # Sum them all together                     % STACK: -10
     Ä # Absolute value                            % STACK: 10
       # Implicit print

I can´t follow the explanation. Would you add an example please.

@Titus there you go. Hope it helps :)

And here I was with È2*<*O like a filthy casual.

PHP, 51 bytes
while(~$n=$argn[$i++])$s+=$n&1?$n:-$n;echo abs($s);

adds digit to $s if odd, subtracts if even. Run as pipe with -nR.
or
while(~$n=$argn[$i++])$s+=(-1)**$n*$n;echo abs($s);

using Dennis´ -1 power trick.

K (ngn/k), 18 15 12 bytes
#!+/{x-:/x}'

Try it online!
Takes input as a list of digits.

{x-:/x}' negate each digit of the input that many times (e.g., negate 4 four times, and 9 nine times). this makes odd digits negative, leaving even digits positive
+/ take the sum
#! take the absolute value (and implicitly return)

TI-BASIC, 11 6 bytes
abs(sum(Anscos(πAns

Takes input as a list. i²^Ans saves two bytes over (-1)^Ans because we don't need the parentheses.
abs(sum(Anscos(πAns
           cos(πAns                  1 for evens, -1 for odds
        Ans                          Multiply by original list
abs(sum(                             Sum the list and take absolute value, which also
                                     fixes rounding errors from cos(.

Pyth, 16 12 11 10 8 bytes
.asm*^tZ

Try it online!

How?

.asm*^tZ – Full program. Q = input.
   m*^tZ – Raise -1 to the power of each d in Q and multiply by d.
  s      – Sum.
.a       – Absolute value.

><>, 32 bytes
00\~:00@(?$-n;
(?\c%:0@2%?$-+i:0

Try it online!

Java (OpenJDK 8), 55 bytes
a->{int s=0;for(int d:a)s+=d%2<1?-d:d;return s<0?-s:s;}

Try it online!
Naive implementation.

C#, 67 bytes
namespace System.Linq{a=>Math.Abs(a.Sum(n=>n%2<1)-a.Sum(n=>n%2>1))}

J, 14 bytes
|-/(2&|+//.[),

Try it online!
explanation
|                absolute value of
 -/              the difference between
                 the items on the list returned by this fork
   (2&|          is an item odd? (1 for yes, 0 for no)
       +//.      the "key" verb /. which partitions on above (even / odd) then sums
           [)    identity, ie, the list of digits passed
             ,   turn it into a list (to handle 1 element case)

Perl 6, 28 bytes
{abs sum $_ Z*.map(*%2*2-1)}

Try it online!
Takes a list of digits as input.

$_ is the input argument.
.map(* % 2 * 2 - 1) maps each digit to either 1 or -1 depending on whether the digit is odd or even, respectively.
Z* zips the original list of digits with the even/odd list using multiplication.

Bash 141 139 99 Bytes
while read -n1 a; do
[ $[a%2] = 0 ]&&e=$[e+a]||o=$[o+a]
done
(($[e-o]>0))&&echo $[e-o]||echo $[o-e]

Try it online!

R, 72 43 bytes
b=(d=scan())%%2<1;abs(sum(d[b])-sum(d[!b]))

First, d = scan() takes the number as input, one digit after the other (thanks to @Giuseppe comment !)
Then, b = d %% 2 <1 associates to b a TRUE or FALSE value at each index depending on the digits' parity.
Therefore, b values are TRUE for even numbers, and !b are TRUE for odd values.
Finaly, abs(sum(d[b]) - sum(d[!b])) does the job.

<1 is one byte shorter than ==0, but note that you may take input as a list of digits as well.

@Giuseppe Well spotted ! Thanks !

Braingolf, 18 bytes
{.2%?M|}&+v&+c-!s*

Try it online!
Takes input as a list of digits
Explanation
{.2%?M|}&+v&+c-!s*  Implicit input from commandline args
{......}            Foreach loop, runs on each item in the stack..
 .2%                ..Parity check, push 1 if odd, 0 if even
    ?               ..If last item != 0 (pops last item)..
     M              ....Move last item to next stack
      |             ..Endif
        &+          Sum entire stack
          v&+       Switch to next stack and sum entire stack
             c-     Collapse into stack1 and subtract
               !s   Sign check, push 1 if last item is positive, -1 if last item is
                    negative, 0 if last item is 0
                 *  Multiply last item by sign, gets absolute value
                    Implicit output

x86-64 Machine Code, 30 bytes
31 C0 99 8B 4C B7 FC F6 C1 01 74 04 01 CA EB 02 01 C8 FF CE 75 ED 29 D0 99 31 D0 29 D0 C3

The above code defines a function that accepts a list/array of integer digits and returns the absolute difference between the sum of its even digits and the sum of its odd digits.
As in C, assembly language doesn't implement lists or arrays as first-class types, but rather represents them as a combination of a pointer and a length. Therefore, I have arranged for this function to accept two parameters: the first is a pointer to the beginning of the list of digits, and the second is an integer specifying the total length of the list (total number of digits, one-indexed).
The function conforms to the System V AMD64 calling convention, which is standard on Gnu/UNIX systems. In particular, the first parameter (pointer to the beginning of the list) is passed in RDI (as this is 64-bit code, it is a 64-bit pointer), and the second parameter (length of the list) is passed in ESI (this is only a 32-bit value, because that's more than enough digits to play with, and naturally it is assumed to be non-zero). The result is returned in the EAX register.
If it's any clearer, this would be the C prototype (and you can use this to call the function from C):
int OddsAndEvens(int *ptrDigits, int length);

Ungolfed assembly mnemonics:
; parameter 1 (RDI) == pointer to list of integer digits
; parameter 2 (ESI) == number of integer digits in list (assumes non-zero, of course)
OddsAndEvens:
   xor  eax, eax              ; EAX = 0 (accumulator for evens)
   cdq                        ; EDX = 0 (accumulator for odds)
.IterateDigits:
   mov  ecx, [rdi+rsi*4-4]    ; load next digit from list
   test cl, 1                 ; test last bit to see if even or odd
   jz   .IsEven               ; jump if last bit == 0 (even)
.IsOdd:                       ; fall through if last bit != 0 (odd)
   add  edx, ecx              ; add value to odds accumulator
   jmp  .Continue             ; keep looping
.IsEven:
   add  eax, ecx              ; add value to evens accumulator
.Continue:                    ; fall through
   dec  esi                   ; decrement count of digits in list
   jnz  .IterateDigits        ; keep looping as long as there are digits left

   sub  eax, edx              ; subtract odds accumulator from evens accumulator

   ; abs
   cdq                        ; sign-extend EAX into EDX
   xor  eax, edx              ; XOR sign bit in with the number
   sub  eax, edx              ; subtract sign bit

   ret                        ; return with final result in EAX

Here's a brief walk-through of the code:

First, we zero out the EAX and EDX registers, which will be used to hold the sum totals of even and odd digits. The EAX register is cleared by XORing it with itself (2 bytes), and then the EDX register is cleared by sign-extending the EAX into it (CDQ, 1 byte).
Then, we go into the loop that iterates through all of the digits passed in the array. It retrieves a digit, tests to see if it is even or odd (by testing the least-significant bit, which will be 0 if the value is even or 1 if it is odd), and then jumps or falls through accordingly, adding that value to the appropriate accumulator. At the bottom of the loop, we decrement the digit counter (ESI) and continue looping as long as it is non-zero (i.e., as long as there are more digits left in the list to be retrieved).
The only thing tricky here is the initial MOV instruction, which uses the most complex addressing mode possible on x86.* It takes RDI as the base register (the pointer to the beginning of the list), scales RSI (the length counter, which serves as the index) by 4 (the size of an integer, in bytes) and adds that to the base, and then subtracts 4 from the total (because the length counter is one-based and we need the offset to be zero-based). This gives the address of the digit in the array, which is then loaded into the ECX register.
After the loop has finished, we do the subtraction of the odds from the evens (EAX -= EDX).
Finally, we compute the absolute value using a common trick—the same one used by most C compilers for the abs function. I won't go into details about how this trick works here; see code comments for hints, or do a web search.

__
* The code can be re-written to use simpler addressing modes, but it doesn't make it any shorter. I was able to come up with an alternative implementation that dereferenced RDI and incremented it by 8 each time through the loop, but because you still have to decrement the counter in ESI, this turned out to be the same 30 bytes. What had initially given me hope is that add eax, DWORD PTR [rdi] is only 2 bytes, the same as adding two enregistered values. Here is that implementation, if only to save anyone attempting to outgolf me some effort :-)
                    OddsAndEvens_Alt:
31 C0                   xor    eax, eax
99                      cdq
                    .IterateDigits:
F6 07 01                test   BYTE PTR [rdi], 1
74 04                   je     .IsEven
                    .IsOdd:
03 17                   add    edx, DWORD PTR [rdi]
EB 02                   jmp    .Continue
                    .IsEven:
03 07                   add    eax, DWORD PTR [rdi]
                    .Continue:
48 83 C7 08             add    rdi, 8
FF CE                   dec    esi
75 ED                   jne    .IterateDigits
29 D0                   sub    eax, edx
99                      cdq
31 D0                   xor    eax, edx
29 D0                   sub    eax, edx
C3                      ret

05AB1E, 7 bytes
È2*<*OÄ

Try it online!
        # Input              | 1234567
È       # Is Even?           | [0,1,0,1,0,1,0]
 2*<    # (a * 2) - 1        | [-1,1,-1,1,-1,1,-1]
    *   # Multiply w/ input. | [-1,2,-3,4,-5,6,-7]
     O  # Sum.               | -10
      Ä # Absolute value of. | 10

2* can be ·

Tcl, 55 bytes
lmap e $V {incr s [expr $e*-1**$e]}
puts [expr abs($s)]

Try it online!

Ruby, 45 bytes
Function; Full number
->n{s=0
n.digits.map{|x|s+=x%2>0?x:-x}
s.abs}

Try it online!
Ruby, 38 bytes
Function; List of digits
->n{s=0
n.map{|x|s+=x%2>0?x:-x}
s.abs}

Try it online!

Rust, 73 bytes
fn f(mut a:i32)->i32{let mut s=0;while a>0{s+=a%10*(a%2*2-1);a/=10}s.abs()}

Try it online!
Rust, 68 bytes
This takes a slice of digits rather than an integer.
fn z(a:&[i32])->i32{a.iter().map(|x|x*(x%2*2-1)).sum::<i32>().abs()}

Try it online!

J, 11 bytes
Credit to Uriel’s APL solution
1|@#.[*_1^]

Try it online!

Vyxal, 6 bytes
u$eÞ•ȧ

Try it Online!
Port of Jelly.
u$eÞ•ȧ
u$e     # Raise -1 to the power of each
   Þ•   # Dot product with the input
     ȧ  # Absolute value

Ly, 24 bytes
0spSy[f:2%2*,*l+sp,]lar-

Try it online!
This is pretty brute force, it just adds or subtracts each number to an accumulator depending on whether it's odd or even.  The post-loop bit is the shortest way to get an abs() in Ly I could think of.
0sp                       - initialize the backup cell to 0, clear stack
   S                      - convert the number on STDIN to digits on the stack
    y                     - push the number of digits onto the stack
     [f           ,]      - loop decrementing the digit count, stop on 0
       :                  - duplicate the next digit
        2%                - modulo by 2 to get odd/even
          2*,             - do "(x*2)-1" to map 1 to 1, and 0 to -1
             *            - multiple the digit by that 1/-1
              l+sp        - add to backup cell, pop from stack
                    l     - load the final difference from accumulator
                     a    - sort stack (has a 0 and the accumulator val)
                      r   - reverse stack
                       -  - subtract to flip the sign if difference was <0

The programs with a positive number on the stack, which is printed automatically.

Desmos, 24 bytes
f(l)=abs(total(l(-1)^l))

Input as a list of digits.
Try It On Desmos!
Try It On Desmos! - Prettified

Nibbles, 6 bytes (12 nibbles)
!=+$*+|$%$~~

Calculates the absolute difference between the sum of all digits and twice the sum of the odd digits.
!=+$*+|$%$~~
!=              # absolute difference between
  +             #   sum of
   $            #   input
                # and
     +          #   sum of
       $        #   input
      |         #   filtered for nonzero when
        %$      #     modulo
          ~     #     2 (default for modulo)
    *           #   multiplied by
           ~    #   2 (default for multiplication)

MathGolf, 6 bytes
b▬m*Σ±

Port of @Dennis' Jelly answer.
Input as a list of digits.
Try it online.
Explanation:
b      # Push -1
 ▬     # Take -1 to the power of each integer in the (implicit) input-list
  m*   # Multiply the values at the same positions of this list and the (implicit) input
    Σ  # Sum this list together
     ± # Get its absolute value
       # (after which the entire stack is output implicitly as result)

Japt, 8 bytes
üv mx ra

Try it
Takes input as a digit array
üv mx ra     :Implicit input of digit array
ü            :Group by
 v           :  Divisible by 2?
   m         :Map
    x        :  Sum
      r      :Reduce by
       a     :  Absolute difference

Fig, \$6\log_{256}(96)\approx\$ 4.939 bytes
AS*^N1

Try it online!
Port of MathGolf. Surprisingly, beats Jelly.
AS*^N1 # Input as list of digits
    N1 # -1
   ^   # To the power of each in the input
  *    # Multiply the list of 1s and -1s by each digit
 S     # Sum
A      # Absolute value

J-uby, 33 bytes
:partition+:odd?|:*&:sum|+:-|:abs

Attempt This Online!

Pip, 9 bytes
AB$+g*vEg

Try It Online!

Arturo, 26 bytes
$=>[abs∑map&'x->x*^0-1x]

Try it

Thunno, \$ 9 \log_{245}(96) \approx \$ 7.41 bytes
D1n@z*SZA

Attempt This Online! or
verify all test cases.
Explanation
D1n@z*SZA  # Implicit input        [1, 2, 3, 4]
D          # Duplicate             [1, 2, 3, 4], [1, 2, 3, 4]
 1n@       # Push -1 ** each       [1, 2, 3, 4], [-1, 1, -1, 1]
    z*     # Multiply elementwise  [-1, 2, -3, 4]
      S    # Sum this list         2
       ZA  # Absolute value        2
           # Implicit output

x86-16 machine code, 18 bytes
00000000: 33d2 ada8 0174 02f7 d803 d0e2 f579 02f7  3....t.......y..
00000010: dac3                                     ..

Listing
33 D2       XOR  DX, DX         ; result in DX
        IN_LOOP:
AD          LODSW               ; next digit
A8 01       TEST AL, 1          ; odd or even?
74 02       JZ   EVEN           ; jump if even
F7 D8       NEG  AX             ; complement to subtract odd digit
        EVEN:
03 D0       ADD  DX, AX         ; add to running result
E2 F5       LOOP IN_LOOP        ; next digit
79 02       JNS  DONE           ; jump if result is positive
F7 DA       NEG  DX             ; complement for absolute value
        DONE:
C3          RET                 ; return to caller

Callable function, input list of digits at DS:SI, length in CX. Output to DX.

Common Lisp, 52 bytes
(defun f(x)(abs(loop as i in x sum(*(expt -1 i)i))))

Try it online!
Translation of Dead Possum answer.

C#, 59 bytes
Math.Abs(a.Where(x=>(x%2<1)).Sum()-a.Where(x=>x%2>0).Sum())

You may want to add some kind of explanation for this.  Just for the people who don't know C.  As it is, it's kind of just the code.

Java (OpenJDK 8), 64 bytes
Takes n as int input, uses mod 10 and div 10 to sum from least significant digit and return Absolute value when done.
n->{int r=0;for(;n>0;n/=10)r+=n%2>0?-n%10:n%10;return r<0?-r:r;}

Try it online

Welcome to PPCG! Your TIO link doesn't seem to match your code, would you mind updating it?

That TIO is actually my answer, but to another question! O_o

Fixed! and thanks for the welcome...

CJam, 16 14 Bytes
q{si_W\#*}%:+z

Try it online
q{si_W\#     e# Take -1 to power of digit
*}%          e# Multiply result by digit
:+z          e# Sum altered digits and return the absolute value

java , 314 bytes
public  static int f (String s)
{
    char [] m =s.toCharArray();
    int o=0 ,e=0;
    for(int i =0 ;i<m.length;i++)
    { int n=(int)m[i]-48;
    if(n%2==0)
        e+=n;
    else
        o+=n;
    }
    return abs(e-o);

   }

Bash, 51 bytes
Full program; Full number
Or "bash with awk" for the pedantics.
grep -o .|awk '{a+=$0%2?$0:-$0}END{print a<0?-a:a}'

Try it online!
Explanation
grep -o .| # every /./ on a new line
awk '{
            // a is initialized to 0 cuz awk lol
  a+=$0%2   // Is odd?
    ?$0:-$0 // true -> add +, false -> add -
}
END{
  print a<0?-a:a // to absolute value
}'

AWK, 35 bytes
Full program; List of digits
{a+=$0%2?$0:-$0}END{print a<0?-a:a}

Try it online!
Technically not the same as my other answer. I still think that one is better because using a list of digits feels cheap.

APL NARS 26 chars
{∣(+/-a)+2×+/(2∣a)/a←⍎¨⍕⍵}

test
  f←{∣(+/-a)+2×+/(2∣a)/a←⍎¨⍕⍵}
  f¨0 1 12 333 459 2469 1234
0 1 1 9 10 3 2

Thunno 2, 6 bytes
u@$Ø.A

Attempt This Online!
Port of Dennis's Jelly answer.
Explanation
u@$Ø.A  # Implicit input
u@      # Take -1 to the power of
        # each of the digits
  $     # Push the input again
   Ø.   # Take the dot product
     A  # Absolute value
        # Implicit output

Vyxal 3, 3 bytes
ṂḋȦ

Try it Online!
Port of Dennis's Jelly answer.
Certified Vyxal Moment, -1^n and dot product are now one byte builtins.
Input is a list of digits

Uiua, 17 bytes
⌵-∩/+∩▽¬,,◿2.∵⋕°⋕

Test pad
Explanation
⌵-∩/+∩▽¬,,◿2.∵⋕°⋕
             ∵⋕°⋕  # Parse integer into digits
          ◿2.      # Get each digit mod 2
        ,,         # Copy the digits and the mask over
       ¬           # Invert the mask
     ∩▽            # Filter for both masks and arrays
  ∩/+              # Sum both results up
⌵-                 # Get the absolute difference

Created with the help of Luminespire.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Trigger the chutes and protect the jackpot
You are going to participate in a gameshow. One of the challenges works as follows:

The first room contains a large number of identical balls.
The second room contains a series of chutes, each of which has a sensor which counts how many balls have been placed in it. A ball which is placed in a chute cannot then be recovered.
Each chute will trigger after a certain number of balls (its trigger count) have been placed into it. When it triggers it flashes lights, makes a noise, and leaves you in no doubt that it has triggered.
You must trigger N chutes to continue to the next challenge.
You know the trigger counts, but not the correspondence between count and chute.
You have one opportunity to take balls from the first room into the second. Once you put a ball into a chute, you cannot go back for more balls.
Each ball which you take deducts money from the jackpot.

Obviously you want to ensure that you will pass the challenge, but you want to minimise the jackpot money loss. Write a program, function, verb, etc. to tell you how many balls you need.
Example
Suppose the trigger counts are 2, 4, and 10, and you need to trigger 2 chutes to pass. There is a strategy to pass with 10 balls: place up to 4 balls in the first chute, up to 4 balls in the second chute, and up to 4 balls in the third chute. Since one of the three chutes will trigger after only 2 balls, you only use a total of 10. There is no strategy which is guaranteed to work with fewer than 10, so that is the correct output.
Input
The input consists of an array of integer trigger counts and a integer giving the number of chutes to trigger. You may take the two inputs in either order, and if needed you may take a third input with the length of the array.
You may assume that all of the inputs are greater than zero, and that the number of chutes which must be triggered does not exceed the number of chutes.
You may also assume that the counts are sorted (ascending or descending), as long as you state that clearly in your answer.
Output
The output should be a single integer, giving the number of balls required by the optimum strategy.
Test cases
Format: N counts solution
1 [2 4 10] 6
2 [2 4 10] 10
3 [2 4 10] 16
1 [3 5 5 5 5 5 5 5 5 5] 5
2 [1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 8 11] 8
2 [1 2 6 6 6 6 6 6 6 10] 16
2 [1 2 3 3 4 4 6 6 6 11] 17
3 [1 2 3 4 5 5 6] 16
3 [2 4 7 7 7 7 7 7 7] 21
5 [1 2 2 3 3 3 3 3 5 9 9 11] 27
2 [5 15 15] 25
1 [4 5 15] 10
3 [1 4 4 4] 10
2 [1 3 4] 6
2 [1 3 3 8] 8

Warning: don't attempt to ninja!

Can you please explain why the last test case gives 10? Shoudn't one place at least 4 in each in order to make sure at least one triggers? I'm probably too dumb and didn't read the question well enough, but I don't get it.

Place up to 5 in each of them

@H.PWiz 5 * 3 - 1 gives 14 to me :/

@Rod You would only need to place 5 in two of them before one was guaranteed to trigger, 5*2 = 10

@H.PWiz Thanks, now got it. The challenge seems far more complicated now....

If one places 5 two times, but one triggers at 4, you actually use 5+4=9 balls, right?

@Mr.Xcoder, yes, but you have to be certain of succeeding in the worst case.

@Mr.Xcoder: if the first one you try is the 15, you need 5 balls to find that out. That leaves you the 5 and the 4 so you need another 5 balls to guarantee that your next pick will be triggered.

@H.PWiz That's not why 10 are required.  Suppose we start by adding balls to chutes one at a time, and also suppose that whenever we might finish earlier by guessing the right chute, we always guess the wrong one.  We start by putting 2 in each, since we know one chute will trigger after 2.  But we happen to pick the 2 chute last.  When it triggers, we know that one of the remaining chutes only needs 2 more.  So we put 2 more in the 10, because we guess wrong.  Then we put 2 more in the 4, and it triggers.  So (2+2+2)+(2+2) = 10 total balls in the worst case.

I understand, I think I just didn't explain my thoughts correctly, thanks for the detailed explanation anyway. I thought of it as add 5 to one, if it doesn't trigger, add 5 to one of the others causing it to trigger. Or, if the first one triggers after adding 5, you are already done.

Python, 222 198 bytes
def S(G,P,T=0):
 T=T or[0]*len(P);r=[0]*(sum(t>=p for t,p in zip(T,P))>=G)
 for i,t in enumerate(T):
    if t<max(P):a=next(p for p in P if p>t)-t;T[i]+=a;r+=[a+S(G,P,sorted(T))];T[i]-=a
 return min(r)

Usage is S(2, (2, 4, 10)).
In order to test this program at any decent speed, add memoization by putting this after the function definition:
old_s = S
mem = {}
def S(G, P, T=0):
    k = (G, tuple(P), T and tuple(T) or 0)
    if k in mem: return mem[k]
    r = old_s(G, P, T)
    mem[k] = r
    return r

We do dynamic programming on an array T that contains the number of balls we've thrown into each chute, initially all zeroes. Without providing a rigorous proof, I claim that we can keep T sorted at all times, that is, assume we always throw the most balls into the last chute, which in turn we will assume was the largest chute.
If then T, when matched element for element with P (which is our problem input), has at least G (which is our goal) elements bigger, we've found a solution, and we return 0, because we need to throw 0 more balls to find a solution. This means that if G is 1 our least thrown into chute must contain an equal or more amount of balls than the smallest chute requirement, and so on for bigger G.
Otherwise, for each position we throw in enough balls to upgrade to the next chute requirement (anything in between would never be observable) and recurse. We then return the minimum of these recursive calls.

215 bytes by removing continue.

195 bytes by removing enumerate

Haskell, 124 117 100 98 91 80 78 bytes
Saved 11 bytes thanks to @Peter Taylor
0#_=0
n#a=minimum$zipWith(\x y->x*y+(n-1)#(snd.splitAt y$a))a[1..length a-n+1]

Try it online!
(#) takes an integer and a list of integers in descending order as arguments
Usage is 1#[10,4,2]
Explaination:
For each value, x, in position i (1-idexed) in the list, the best tactic to remove that element (or some amount of elements less than or equal to x) is to pour x balls into i chutes.
For each element, x, in position i in the list, (n#) calculates x*i + ((n-1)#) of the list beyond position i (until n is 0). Then it takes the minimum of all the possibilities checked.

Haskell, 54 bytes
(%)0
(p%l)n|h:t<-l=p+min(p%t$n)(h%t$n-1)|n<1=p|1>0=1/0

Try it online!
Takes the list in ascending order.

Note to self: next time insist that the output should be an integer type.

I don't know enough Haskell to figure this one out, could you add an explanation?

Python, 73 bytes
f=lambda n,c:n and min(c[i]*-~i+f(n-1,c[-~i:])for i in range(len(c)-n+1))

Port of H.PWiz's Haskell answer. Requires the input to be in descending order.

CJam (35 bytes)
{:A,,e!f<{$__(;A,+.-\Af=.*1bz}%:e<}

Online demo
Takes input as N counts assuming that counts is sorted in ascending order.
Dissection
Denote the counts in descending order as a 1-indexed array C (so the second element of C is the second largest count). Suppose that we end up winning by triggering chutes C[a_0], C[a_1], ... C[a_{N-1}]. Then in the worst case, for each C[a_i] we have put at least C[a_i] balls into each of chutes 1 to a_i. So we put C[a_{N-1}] balls into a_{N-1} chutes, an additional C[a_{N-2}] balls into a_{N-2} of them, ...
Over each subset of N counts, which gives us the smallest sum? Then we should aim to win with that subset of counts.
NB The code actually uses the counts in ascending order, but I think descending order is more intuitive.
{         e# Define a block
  :A      e#   Store the sorted counts as A
  ,,e!f<  e#   Get all N-element subsets of A's indices
  {       e#   Map over these subsets S:
    $__   e#     Sort the subset and get a couple of copies
    (;A,+ e#     Remove the first element from one copy and append len(A)
    .-    e#     Pointwise subtraction, giving [S[0]-S[1] S[1]-S[2] ...]
    \Af=  e#     Get the counts [A[S[0]] A[S[1]] ...]
    .*    e#     Pointwise multiplication
    1bz   e#     Sum and take absolute value, giving the worst case score
  }%
  :e<     e#   Select the minimum worst case score
}


text:
Create unique ids
You are to write a program that takes a list of strings as input.  For every string in the list you are to determine the smallest N such that no other string in the list begins with the same N characters as the string in question.  Now compose a new list with all these strings.  Here is an example, on the left we have the input and on the right we have the output
aba                   aba
aababba               aa
abbaaabbb          -> abba
bbbbbbabababaaab      b
abbbabbaa             abbb

If a there is a string that is also the beginning of another string you should append a $ to the end to represent the end of the string.  Here is an example where that is the case
ababababbabab         abababa
ababbbaabababa        ababbb
ababb                 ababb$
bababba            -> bababb
bbbabababab           bb
bababababbabab        bababa
abababbababa          abababb

Rules

Input will only contain alphabetic characters.
You will not receive a list with the same entry twice.
You take input in any ordered container.
This is code-golf, you should aim to minimize the byte size of your program.

Isn't there already a challenge like this?

Related.

Related.

Also related. This may have been the one you guys were thinking of, though it's not really a dupe (the "ID"s only have to be unique up to that point in the list)

Is something like ["ba,"baa","bab"] a valid input? It does not have the same entry twice, but there is no N defined for the first string. If it is a valid input should it return ["ba$","baa","bab"], ["b$","baa","bab"], ["ba$$","baa","bab"], ["b$$","baa","bab"], any of the above, or something else?

Sorry I don't see why this is undefined. $ represents an EOF so it should be ba$. b$ doesn't make sense because the string goes on after b and thus you can't put a $ after b. b$$ doesn't make sense for the same reason. ba$$ doesn't make sense because by the time you have reached one $ it's already differentiated from everything else (Nothing else begins with ba$).  It also doesn't make a lot of sense for there to be characters after an EOF even if they are more EOFs. If you could point out where the confusion is coming from or explain your reasoning, that would be helpful

Husk, 14 13 12 bytes
Ṡzo↑▲‡Ṫ≠TT'$

Try it online!
Less than half the length of the previous best solution!
Explanation
Ṡzo↑▲‡Ṫ≠TT'$
        TT'$     Pad all strings to equal length by appending dollar signs

     ‡Ṫ≠         Create a 2D matrix with all pairwise differences between
                 strings. ≠ returns the smallest index at wich two lists differ
                 (or 0, if they are equal)

Ṡzo↑▲            For each string, take as many characters as the maximum number
                 in its row of the table.

Since my explanation may not be that clear, here's a small worked example:
Starting list: ["abc","abd","b","bcd"]
Table of differences:
     abc abd  b  bcd     max
 abc  0   3   1   1       3
 abd  3   0   1   1       3
 b    1   1   0   2       2
 bcd  1   1   2   0       2

So we take from each string (with added trailing '$') as many characters as stated in the "max" column.
Final result: ["abc","abd","b$","bc"]

Haskell, 83 79 bytes
f l|let h=map(++"$")l;w x|y<-init x,2>sum[1|z<-h,y<=z,y++"{">z]=w y|1<3=x=w<$>h

Try it online! Example usage: f ["abcd","abh","ab","bacd"] yields ["abc","abh","ab$","b"].
Given a list of strings, the function f appends a trailing $ and applies w to each string, where w iteratively drops the last character of the string (with init) until the next application of init would lead to the string now longer being a unique prefix.
Edit: Three bytes off thanks to Ørjan Johansen's shorter prefix test!

Good point, looks like I can't count.

y<=z,y++"{">z is a shorter prefix test.

Jelly,  28 26  16 bytes
-10 bytes by implementing the algorithm found by Leo in their brilliant Husk answer.
i€0Ṁḣ@
;€”$µ=þç"

or...
;€”$µ=i0µþ⁸Ṁ€⁸ḣ"

A monadic link taking and returning lists of lists of characters.
Try it online! (the footer makes a full program which prints the result split by newlines.)
How?
i€0Ṁḣ@ - helper link, create an entry of the output: equality row, string with trailing '$'
i€0    - first index of zero in €ach entry of the row
   Ṁ   - maximum
    ḣ@ - head to index with swapped @rguments (the prefix of the string)

;€”$µ=þç" - link: list of lists of characters (list of "strings")
  ”$      - literal '$'
;€        - concatenate for €ach
    µ     - monadic chain separation (call that x)
      þ   - table of (with x on the left and, implicitly, on the right):
     =    -   equals? (vectorises)
        " - zip with (with the table on the left and, implicitly, x on the right)
       ç  - call the last link as a dyad

My original:
-2 bytes thanks to Erik the Outgolfer (replace ḣJ$ with ;\ and ẎċÐ€Ð€$ with ċ@€€Ẏ$)
NMḢ⁹ḣ;⁸Ṃẋ@”$¤Ṗ
;\€ċ@€€Ẏ$ç"

A monadic link taking and returning lists of lists of characters.
Try it online! (the footer makes a full program which prints the result split by newlines.)
I'm almost certain this is beatable, and probably by a decent margin! (although I have attempted to golf the method.)
The same byte count may be achieved without a helper link too, with:
ḣJ$€ẎċÐ€Ð€$ðNMḢ⁹ḣ;⁸Ṃẋ@”$¤Ṗð"

How?
Note: the reusable link is the second line of code, so start there.
NMḢ⁹ḣ;⁸Ṃẋ@”$¤Ṗ - helper link, create an entry of the output: prefix counts, string
               -   ("prefix counts" should be counts of the prefixes of the "string" in
                    the totality of prefixes of *all* the strings)
N              - negate the counts
 M             - maximal indexes (lengths of prefixes appearing least often, ascending)
  Ḣ            - head (finds the minimal length required), call that ml
   ⁹           - chain's right argument (prefixes)
    ḣ          - head (string) to index ml (gets the minimal length prefix)
            ¤  - nilad followed by links as a nilad:
      ⁸        -   chain's left argument (prefix counts)
       Ṃ       -   minimum (this will either be 1 or 2)
          ”$   -   literal '$'
        ẋ@     -   repeat with swapped @rguments (either "$" or "$$")
     ;         - concatenate
             Ṗ - pop (remove the last "$" - leaving one where the prefix occurs in another
               -      string's prefixes, and none otherwise)

;\€ċ@€€Ẏ$ç" - link: list of lists of characters (list of "strings")
  €         - for €ach string
 \          -   cumulative reduce with:
;           -     concatenation
            - (gets a list of lists of prefixes)
        $   - last two links as a monad:
       Ẏ    -   tighten (flatten by one to make a single list of all prefixes)
    @       -   swap arguments
     €€     -     for each prefix in each list of prefixes
   ċ        -       count occurrences in the tightened list (>=1 since it counts itself)
          " - zip with the dyad (right argument is this link's argument):
         ç  -   last link (helper) as a dyad

There's ;\ which you can use instead of ḣJ$ for -1.

You can replace ẎċÐ€Ð€$ with ċ@€€Ẏ$ for -1.

Haskell, 109 104 98 97 90 84 83 bytes
Probably not very good but Hopefully this will kick things off a bit.
f s=[[x|x<-map(`take`(a++"$"))[0..],[1]==[1|d<-s,and$zipWith(==)x$d++"$"]]!!0|a<-s]

Try it online!

I think x<=d++"$",x++"{">d is a shorter prefix test.

JavaScript (ES6), 89 86 bytes
a=>a.map(g=(s,i,a,t=s+'$')=>a.some((t,j)=>j-i&&!t.search(s))?t:g(s.slice(0,-1),i,a,s))

Edit: Saved 3 bytes thanks to @CraigAyre. (Supporting arbitrary characters would still have saved two bytes using !t.indexOf(s).)

Can you use search instead of startsWith?: !t.search(s)

PHP, 155 129 102 bytes
for(;++$k<$argc;$t=!print"$t
")for($i=0;count(preg_grep("_^".($t.=$argv[$k][$i++]?:"$")._,$argv))>1;);

expects input to not contain regex special chars and that no argument is -.
Run with php -nr <word> <word> ... or try it online.
breakdown
for(;++$k<$argc;            # loop through arguments
    $t=!print"$t\n")            # 2. print $t, reset $t
    for($i=0;                   # 1. loop through string:
    1<count(preg_grep("_^".(        # 2. continue while more than one argument begins with $t
        $t.=$argv[$k][$i++]?:"$"    # 1. append current character or "$" to $t
    )._,$argv)););

Mathematica, 141 142 bytes
g[x_:0,___]:=x;f=#<>""&/@(Thread@h[x=#~PadRight~99&/@(Characters[#<>"$"]&/@#),Max/@Outer[g@@Join@@Position[#-#2,y_/;y!=0]&,x,x,1]]/.h->Take)&

I think I can golf it a bit.
The code doesn't work on Mathics so you may use Wolfram Sandbox to test.