Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 286 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, 2 bytes

NC

Try it online! Or see all test-cases.

How?

In Jelly any sequence of monadic atoms forms a monadic chain which simply applies those monadic atoms in turn from left to right, starting with the value of it's left argument. When a full program is run with no arguments zeros are implicitly supplied as necessary, i.e. main_link(0) is called. As such NC is C(N(0)) and CN is N(C(0)).

NCNC ... CN ... NC - Main Link: no arguments
N - negate((implicit)0) -1 * 0 = 0
 C - complement(that) 1 - 0 = 1
 N - negate(that) -1 * 1 = -1
 C - complement(that) 1 - -1 = 2
 ... - 
 ... - ... = x a
 C - complement(a)  1 - a = 1 - a
 x N - negate(that)  -1 * (1 - a) = a - 1 ... - x
 ... -  ... = b
  N - negate(b)  -1 * b = -b
  C - complement(that) 1 - x)-b = x -b + 1

Jelly, 2 bytes

NC

Try it online! Or see all test-cases.

How?

In Jelly any sequence of monadic atoms forms a monadic chain which simply applies those monadic atoms in turn from left to right, starting with the value of it's left argument. When a full program is run with no arguments zeros are implicitly supplied as necessary, i.e. main_link(0) is called. As such NC is C(N(0)) and CN is N(C(0)).

NCNC ... CN - Main Link: no arguments
N - negate((implicit)0) -1 * 0 = 0
 C - complement(that) 1 - 0 = 1
 N - negate(that) -1 * 1 = -1
 C - complement(that) 1 - -1 = 2
 ... - 
 ... - ... = x
 C - complement 1 - x = 1 - x
 N - negate -1 * (1 - x) = x - 1

Jelly, 2 bytes

NC

Try it online! Or see all test-cases.

How?

In Jelly any sequence of monadic atoms forms a monadic chain which simply applies those monadic atoms in turn from left to right, starting with the value of it's left argument. When a full program is run with no arguments zeros are implicitly supplied as necessary, i.e. main_link(0) is called. As such NC is C(N(0)) and CN is N(C(0)).

NCNC ... CN ... NC - Main Link: no arguments
N - negate((implicit)0) -1 * 0 = 0
 C - complement(that) 1 - 0 = 1
 N - negate(that) -1 * 1 = -1
 C - complement(that) 1 - -1 = 2
 ... - 
 ... - ... =  a
 C - complement(a)  1 - a = 1 - a
  N - negate(that)  -1 * (1 - a) = a - 1 ... - 
 ... -  ... = b
  N - negate(b)  -1 * b = -b
  C - complement(that) 1 - -b = b + 1
added 840 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, 2 bytes

NC

Try it online! Or see all test-cases.

How?

In Jelly any sequence of monadic atoms forms a monadic chain which simply applies those monadic atoms in turn from left to right, starting with the value of it's left argument. When a full program is run with no arguments zeros are implicitly supplied as necessary, i.e. main_link(0) is called. As such NC is C(N(0)) and CN is N(C(0)).

NCNC ... CN - Main Link: no arguments
N - negate((implicit)0) -1 * 0 = 0
 C - complement(that) 1 - 0 = 1
 N - negate(that) -1 * 1 = -1
 C - complement(that) 1 - -1 = 2
 ... - 
 ... - ... = x
 C - complement 1 - x = 1 - x
 N - negate -1 * (1 - x) = x - 1

Jelly, 2 bytes

NC

Try it online! Or see all test-cases.

Jelly, 2 bytes

NC

Try it online! Or see all test-cases.

How?

In Jelly any sequence of monadic atoms forms a monadic chain which simply applies those monadic atoms in turn from left to right, starting with the value of it's left argument. When a full program is run with no arguments zeros are implicitly supplied as necessary, i.e. main_link(0) is called. As such NC is C(N(0)) and CN is N(C(0)).

NCNC ... CN - Main Link: no arguments
N - negate((implicit)0) -1 * 0 = 0
 C - complement(that) 1 - 0 = 1
 N - negate(that) -1 * 1 = -1
 C - complement(that) 1 - -1 = 2
 ... - 
 ... - ... = x
 C - complement 1 - x = 1 - x
 N - negate -1 * (1 - x) = x - 1
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, 2 bytes

NC

Try it online! Or see all test-cases.

AltStyle によって変換されたページ (->オリジナル) /