title: Notcalc (Calculate the wrong answer)

text:
# Question
Title: Notcalc (Calculate the wrong answer)
# Goal:

Given two natural numbers (integers from 0 to infinity), output a number that is not the sum of those numbers, but is a natural number.

# Example solutions (TI-Basic):

* `A+B+1`
* `not(A+B)`

# Invalid solutions:

* `A+B-1` (for inputs `0,0`, it returns `-1`, which is not natural)
* `"ABC"` (`ABC` is not a number)

# Notes:

* The output must always be a sum of two natural numbers (which is actually just a natural number)
* `-1`, `undefined`, `infinity`, `NaN` and Error messages are not natural numbers. For our purposes, `0` is natural (although not all mathematicians agree).

# Answer
> 41 votes
# RProgN, ~~4~~ ~~3~~ 1 Byte

Crossed out 4 is still 4 ;(

```
E

```

The most simple of solutions, compares if A and B are equal. Pushes true, which RProgN sees as 1, if they are the same, or false aka 0 otherwise.

## Test Cases

```
0+0 = 1
1+0 = 0
0+1 = 0
1+1 = 1

```

Try it online!

# Answer
> 17 votes
# Python, 13 bytes

```
[(0,0)].count

```

Try it online! Takes input as a tuple.

Using an object method for the function avoids the boilerplate of a `lambda`.

```
lambda a,b:a-~b   # 15 bytes

```

Here, the idea is to map `(0,0)` to `1` and everything else to `0`. Since only `0+0` gives a sum of `0` among natural numbers, that always avoids matching the sum.

If one could output a Boolean here, which I find shady, a byte could be saved as

```
(0,0).__ge__

```

This checks if the input tuple is at most `(0,0)`, which is only true for `(0,0)`. In Python, `True==1` and `False==0`. Even more shadily, outputting via exit code and treating that as a Python Boolen would save two bytes:

```
[(0,0)].pop

```

If string I/O is allowed and leading zeroes are OK, there's the 8-byte solution

```
'1'.join

```

This concatenates `a1b`, which is always bigger than `a+b`.

# Answer
> 15 votes
# Retina, 3 bytes

```

1

```

Try it online!

(The first line has a space before the newline. Stack Exchange isn't very good at showing trailing whitespace.)

Input is the numbers in decimal, separated by a space (e.g. `12 34`). This program just changes the space to a `1`, creating a number too large to be the sum of the input numbers (it necessarily has at least 2 more digits than either, and adding two numbers produces an output with no more than 1 digit more than the larger input).

# Answer
> 14 votes
# MATL, et al. 1 byte

```
=

```

Accepts two natural numbers as inputs and compares them. If they are equal, the output is `1` and if they not equal the output is `0`. This is the same approach as @ATaco's solution.

# Answer
> 11 votes
# Javascript, 10 bytes

```
x=>y=>!x+y

```

Takes 2 numbers using currying syntax like so:

```
(x=>y=>!x+y)(0)(0) // 1

```

# Answer
> 10 votes
# Brain-Flak, 8 bytes

```
({}{}())

```

Try it online!

This is the most readable brain-flak answer I have ever written. :)

Explanation:

```
(      )    # Push the sum of all the following:
 {}         #   The first input
   {}       #   The second input
     ()     #   and one

```

Alternate solutions (also 8 bytes):

```
({}[]{})    # Sum + 1
([]{}{})    # Sum + 2

```

There's a bunch of other solutions that only work with positive numbers:

```
(<{}>{})
({}<{}>)
({{}}())
({{}()})
({{}}[])
({{}[]})

```

# Answer
> 9 votes
# Vim, 3 bytes/keystrokes

```
<C-a>gJ

```

Try it online!

Note that `<C-a>` is actually *ctrl-a*, which represents byte `0x01`.

I love it when vim (which isn't even a programming language) can compete with golfing languages. :) Input comes in this format:

```
a
b

```

This simply increments the first number by one (This is the `<C-a>` part) and then joins the string representations of the two numbers together. As far as I can tell, this should never result in the sum.

# Answer
> 7 votes
# TI-Basic, 3 bytes

```
not(max(Ans

```

Alternative solutions:

```
10^(sum(Ans         3 bytes @DestructibleWatermelon
not(sum(Ans         3 bytes
1+sum(Ans           4 bytes
Input :X=Y          5 bytes @ATaco
Input :X+not(Y      6 bytes
Input :not(X+Y      6 bytes
Input :10^(X+Y      6 bytes
Input :X+Y+1        7 bytes
Input :not(max(X,Y  7 bytes
Ans(1)=Ans(2        8 bytes
Ans(1)+not(Ans(2    9 bytes
not(Ans(1)+Ans(2    9 bytes

```

It's interesting that you made the question's examples in TI-Basic, but you forgot the shorter `A=B` (or maybe it was up to us to find out?)

# Answer
> 7 votes
# Jelly, 2 bytes

```
+‘

```

The + adds the two inputs together then the ' increments the answer by one

Try it online!

# Answer
> 6 votes
# Brachylog, 2 bytes

```
+<

```

Try it online!

### Explanation

```
+     The sum of the elements in the Input...
 <    ...is strictly less than the Output
      (implicitely label the output with an integer respecting this constraint)

```

This will always result in `A+B+1`, if `Input = [A, B]`.

# Answer
> 5 votes
# Mathematica, 5 bytes

```
1+##&

```

Outputs the sum of the two arguments plus 1. For example, `1+##&[2,5]` yields `8`.

(Side note: `Binomial` almost works, although `Binomial[1,0]=1` and `Binomial[4,2]=6` are counterexamples; I think they're the only counterexamples, though.)

# Answer
> 5 votes
# Java (OpenJDK 9), 10 bytes

```
a->b->a-~b

```

Try it online!

# Answer
> 5 votes
# PHP, 17 bytes

```
<?=1-join($argv);

```

Run like this:

```
echo '<?=1-join($argv);' | php -- 0 0
> 1

```

# Explanation

This just concatenates the arguments. The first argument (script name) contains `-`. So that results in a negative number, which I negate with the minus sign. Then I add 1, just in case the first input number is a `0` (0123 = 123).

# Answer
> 5 votes
# Perl 6, 4 bytes

```
!*+*

```

A lambda (formed by Whatever-currying), that adds the boolean inverse (1 or 0) of the first argument to the second argument.

Try it online!

# Answer
> 4 votes
# Turtlèd, 12 bytes

makes very large numbers

```
'1?:?:[1'0l]

```

### Try it online!

## Explanation:

```
'1                write one on the starting grid square
  ?:?:            take a number, move right that many (repeat)
      [1   ]      while not on a grid square with a one on it
        '0l       put a zero on that square, move left
[implicit output of grid]

```

It thus outputs 10\**(x+y).

# Answer
> 4 votes
# PHP, 19 bytes

```
1<?=max([0]+$argv);

```

# Answer
> 3 votes
# SmileBASIC, 4 bytes

```
!A+B

```

not(A)+B
`1+1=2 -> !1+1 -> 0+1=1`
`0+1=1 -> !0+1 -> 1+1=2`

# Answer
> 3 votes
# MATLAB / Octave, 3 bytes

```
@eq

```

Accepts two inputs and checks for equality and yields `1` if they are equal and `0` otherwise.

Online Demo

# Answer
> 3 votes
## R, 13 bytes

```
sum(scan()+1)

```

Thanks to Jonathan Allan for his inputs !

# Answer
> 3 votes
## C ~~26~~ ~~24~~ 19 bytes

```
f(c,d){return!c+d;}

```

Ungolfed version:

```
int f(int c,int d)
{
   return !c+d;
}

```

I hope I got the specification right. Can definitely be shortened!?

@Pavel Thanks for saving 2 bytes

@Neil Thanks for your input.

# Answer
> 3 votes
# 05AB1E, 1 byte

```
Q

```

Works the same as the `RProgN` answer.

Checks if `a` and `b` are the same. If so, print `1`. Otherwise, print `0`

Try it online!

# Answer
> 3 votes
# PHP, 13 bytes; (17 REPL-less)

```
!max($argv)+0

```

Examples

```
[0,0] -> 1
[0,1] -> 0
[1,0] -> 0

```

For those without REPL use

```
<?=!max($argv)+0;

```

and run using

```
echo '<?=!max($argv)+0;' | php -- 0 0

```

# Answer
> 3 votes
# Cubix, ~~9~~ 8 bytes

```
u-~OII/@

```

## Explanation

Expanded, this answer looks like this:

```
    u -
    ~ O
I I / @ . . . .
. . . . . . . .
    . .
    . .

```

The order of the instructions that are executed is `II~-O@`

```
II~-O@
I      # First input
   -   # Minus
 I~    # NOT(second input)
    O  # Output as integer
     @ # End program

```

Tested for all combinations of inputs where both are in the range `0-100`.

Try it here.

# Answer
> 3 votes
# brainfuck, 12 bytes

Simple solution that outputs `A+B+1`.

```
,>,[-<+>]<+.

```

**Try it online**

# Answer
> 3 votes
# dc, 5 bytes

```
?1n+n

```

Try it online!

Input: Two natural numbers separated by a space on stdin.

Output: The digit 1 immediately followed by the sum of the two numbers, which is a number larger than the sum of the two numbers.

Example:

Input: `222 333`

Output: `1555`

# Answer
> 3 votes
# ///, 10 bytes + input

```
/0/1//+//[input A]+[input B]

```

*Obviously `[input A]` and `[input B]` are supposed to be replaced with the appropriate inputs*

Try it online!

Changes 0's to 1's, then concatenates the strings.

This works because:

* For A,B\>0, join(A,B)\>A+B
* join(A,B)\>join(C,D) if A\>C or B\>D
* The function f(x)='change 0's to 1's in the digits of x' is always at least x

So we have join(f(A),f(B))\>f(A)+f(B)\>=A+B.

And if one or both of the inputs are 0, we have join(1,B)\>1+B\>0+B, join(A,1)\>A+1\>A+0 and join(1,1)=11\>0+0.

*Note 1: This type of input has been approved by the community*
*Note 2: This output doesn't give leading 0's either*
*Note 3: Less bytes than Python, PHP, C#, C, Powershell and more!*

# Answer
> 3 votes
# APL - 4 Bytes

```
1++/

```

Takes array, sums its elements and adds one. Test:

```
 1++/1 2
4
 1++/1 0
2

```

# Answer
> 3 votes
# √ å ı ¥ ® Ï Ø ¿, 4 bytes

```
II1_

II   Take 2 inputs and push to the stack
  1  Push 1 to the stack
   _ Push the sum of the stack

```

To output, add `o` to the end.

# Answer
> 3 votes
# Hexagony, 7 bytes

```
?<.!?)@

```

Try it online!

Or in more readable format,

```
 ? <
. ! ?
 ) @

```

This beats the current Hexagony solution of 11 bytes.

## Explanation:

### If the first number is not 0, the program takes the following path:

This reads the first number and branches right. Then it reads the second number, followed by wrapping and trying to read a third, but that doesn't exist so it reads 0. This is printed and the program terminated (note that if a\>0, since b is non-negative a+b\>0).

### If the first number is 0, the program takes the following path to start with:

This reads the first number and branches left. It hits the corner, taking the route from along the north-west edge because the number is 0, and reads the second number. It wraps, then increments the second number and prints.

It bounces against the `<`, printing the incremented second input again. It increments the value and takes the north-east edge again, but this time because the current edge a twice-incremented non-negative value which is definitely positive. It then tries to get a third input, but receives 0 instead.

Finally it wraps and gets diverted by the arrow, then tries to read a fourth input and gets 0 again. It wraps and tries to read a fifth input and receives 0 for the last time. This it prints, and wraps to the `@` and exits.

Note that b\*(10^k+1)\*10\>0+b=b where k is the length of b in digits, so this works.

# Answer
> 2 votes
# Billiards, 11 characters = 17 bytes

```
⇲
⇲
+
1
+
↥

```

Implements `x + y + 1`. Pretty elementary. It takes the inputs on two separate lines. (By the way, the language was modified slightly after the challenge, but only to suppress the prompt from inputting, not sure if this answer is still valid).

# 7 characters = 11 bytes, non-competing

This one is shorter but only possible after a new update of the language:

```
⇲
⇲
=
$

```

This uses `x == y`, which was shamelessly stolen from @ATaco's RProgN solution \[ hope you don't mind (: \]. The `$`, on exit, outputs how many balls passed over it.

# Answer
> 2 votes
# Carrot, 3 bytes

```
1$$

```

Try it online!

(input is newline separated)

Similar to ais529's answer, except this takes care of leading zeroes. This outputs `1` concatenated with both the input numbers. So `5\n6` outputs `156`.

Alternate solutions:

### 6 bytes

```
1$$^*1

```

Same thing as the above solution, but concatenates it with a copy of itself. So `5\n6` becomes `156` which then becomes `156156`.

### 8 bytes

```
#^A +1+

```

(note the trailing space, the input is space separated this time)

```
#^A +1+
#^                        //gets all of the input
  A                       //convert it an array splitting on spaces
   +1                     //add 1 to each of the array's elements
     +                    //sums up all the elements in the array

```

# Answer
> 2 votes
# C#, 32 bytes

## Golfed

```
int i(int x,int y){return++x+y;}

```

## Ungolfed

```
int i (int x, int y)
{
    return ++x+y; //Returns X+Y+1
}

```

# Answer
> 2 votes
## Ruby, 9 bytes (8 + -n flag)

```
p~/1/||1

```

Input 2 integers separated by comma or space or semicolon or just whatever.

### Explanation:

If the input string does not contain any '1', output '1' (since the sum can't be one).

If the input string is 3 characters long, the position of the first one can be 0 or 2, the sum can't be zero, and only '1 1' has sum two (but the first '1' is at position zero).

If the input string is longer, we don't care, the sum will be bigger than one and bigger than the position of the first '1'.

# Answer
> 2 votes
## Javascript (ES6), 10 Bytes

```
x=>y=>!x+y

```

Put `f=` before the code and run like `f(x)(y)`.

This will output **y** plus either **0 or 1** depending on whether **x** is truthy or falsy, respectively.

*Thanks to TomDevs for the bytes saved*

# Answer
> 2 votes
## Pyke, 1 byte

```
q

```

Try it here!

This is the only 1 byte solution that works in Pyke, all the others have collisions.

# Answer
> 2 votes
# Javascript, 12 bytes

```
(a,b)=>a+b+1

```

Accepts 2 numbers inside a closed lambda and return their sum plus 1

Example:

```
((a,b)=>a+b+1)(1, 2)
// 4

```

# Answer
> 2 votes
## QBIC, 8 bytes

a bit uninteresting:

```
::?a+b+1

```

This just takes A and B from the cmd-line, adds them plus 1.

# Answer
> 2 votes
# CJam, ~~four~~ 3 bytes

```
q~=

```

Try it online!

**Explanation**

```
q~   e# Read the input and eval it (pushes the numbers on the stack).
  =  e# Check equality.

```

# Answer
> 2 votes
# , 4 bytes

```
jj=o

```

The same as other implementations. Get the numbers, test the equality and output. Try it here

```
j    Number input
 j   Number input
  =  Equal to
   o Print object

```

# Answer
> 2 votes
# **Forth, 5 bytes**

I didn't see Forth on the list, this is the `A+B+1` solution.

```
+ 1 +

```

It adds the top 2 numbers on the stack, then adds one to it.

The answer will be the top value on the stack.

Example:

```
=> 4, 5
+ 1 +
=> 10

```

# Answer
> 2 votes
# Clojure, 11 bytes

```
#(+ % %2 1)

```

Unoriginal. Just adds 1 to the sum of `%` and `%2` (the arguments to the function).

# Answer
> 2 votes
# Beam, 4 bytes

This seems a bit cheaty, but it reads from the input (characters only) and outputs the ASCII values for each.

```
>r:!

```

Try it online!

```
>     # redirect right
 r    # read input character
  :   # output numeric value of beam
   !  # if beam <> 0 reflect back

```

The `H`alt command is required on here as the beam just disappears into the aether.

# Answer
> 2 votes
# Cheddar, 11 bytes

```
(a,b)->a-~b

```

Try it online!

# Answer
> 2 votes
# SQLite, ~~23~~ 22 bytes

*Saved 1 byte thanks to MickyT*

```
select 1+sum(v)from i;

```

By default, SQL variants can take input from a named table. In this case it takes two numbers from the column `v` in the table `i`, sums them, and adds 1.

Try it online!

# Answer
> 2 votes
# Hexagony, 11 bytes

```
?}?@!<."+)/

```

Prints X + Y + 1

Try it online!

---

The expanded Hex:

```
  ? } ?
 @ ! < .
" + ) / .
 . . . .
  . . .

```
1. read into the initial memory edge.
2. go forward to the right and read into that one.
3. wrap around to the middle row.
4. go backward to the left and sum the other edges into this one.
5. increment.
6. redirect NW then W to save a byte.
7. print and exit.

# Answer
> 2 votes
# C (gcc), 13 bytes

```
n(a,b){a=&b;}

```

returns `b`'s address in memory, though it's slighty cheaty since the user is able to predict the address of `b`.

Try it online!

# Answer
> 2 votes
# Milky Way 2 bytes

```
b!

```

Checks equality.

http://meta.codegolf.stackexchange.com/a/8493/63187 allows me to assume the inputs are pushed to stack.

Thank you Zach Gates! I out golfed him in his own language :P

# Answer
> 2 votes
# PHP, 22 bytes

```
eval("echo $argn+1;");

```

A port of ConnorLSW´s answer. Run with `echo "<a>+<b>" | php -R '<code>'`.

# Answer
> 2 votes
# Python, ~~25~~ 17 bytes

Takes an array of numbers `n`, and returns their sum + 1:

```
lambda n:sum(n,1)

```

I just translated https://codegolf.stackexchange.com/a/111845/66068 into python.

# Answer
> 2 votes
## Keg, 5 bytes

Input two natural numbers separated with spaces.

```
?(+).

```

Sums the whole stack. The answer is guaranteed to be invalid, since what it sums is the charcodes of the numbers.

TIO

# Answer
> 2 votes
# naz, 56 bytes

```
6a8m2x1v1x1f1r3x1v2e0m1o0x1x2f2r3x1v3e0m1o0x1x3f1a1o0x1f

```

Takes two natural numbers as input, separated by a space.

**Explanation** (with `0x` commands removed)

```
6a8m2x1v         # Set variable 1 equal to 48 ("0")
1x1f1r3x1v2e0m1o # Function 1
                 # Read the first byte of input, removing it from the input string
                 # Jump to function 2 if it equals variable 1
                 # Otherwise, output 0
1x2f2r3x1v3e0m1o # Function 2
                 # Read the second byte that's still in the input string
                 # Jump to function 3 if it equals variable 1
                 # Otherwise, output 0
1x3f1a1o         # Function 3
                 # Output 1
1f               # Call function 1

```

# Answer
> 2 votes
# Flurry, 12 bytes

```
[]{<{}{}>}{}

```

### Run example

```
$ printf "0 0" | ./flurry -nib -c "[]{<{}{}>}{}"
73728
$ printf "0 1" | ./flurry -nib -c "[]{<{}{}>}{}"
75264
$ printf "0 11" | ./flurry -nib -c "[]{<{}{}>}{}"
3687936

```

Takes two numbers separated by single space from stdin **in binary mode**, and prints the return value as an integer.

The binary mode is the trick here. What the program does is to implicitly push all codepoints of stdin to the stack, and print the product of the entire stack.

### Code explanation

```
// Pop (stack height + 1) times and compute the product;
// popping from empty stack gives I = 1
//     []     {<{}{}>}  {}
main = height times-pop pop

//          {   <{}  {}  >}
times-pop = \x.  x ∘ pop

```

### Proof that this does not give `a+b` for any `a b`

Base case: The input of "0 0" gives 48 × 32 × 48 = 73728.

Inductive case:

* The codepoint of any printable ASCII is 32 or above, so adding a digit (which amplifies `a+b` by at most 10) amplifies the output by 32 or above.
* Adding 1 to an existing digit adds the product of all the codepoints except itself to the output, which is much greater than the digit value of the modified digit.

Therefore, the output grows much faster than the value of `a+b`, and they can never be equal.

---

For comparison, here is the program that computes `a+b+1`:

# Flurry, 18 bytes

```
{}(<><<>()>)[{}{}]

```

```
$ ./flurry -nin -c "{}(<><<>()>)[{}{}]" 12 13
26
$ ./flurry -nin -c "{}(<><<>()>)[{}{}]" 0 0
1
$ ./flurry -nin -c "{}(<><<>()>)[{}{}]" 0 10
11

```

```
// initial stack = a b
//     {}  (<><<>()>)  [{}   {} ]
main = pop (push succ) (pop  pop)
//     b                succ a
     = b succ (succ a)
     = b + succ a = a + b + 1

```

# Answer
> 2 votes
# Haskell, 8 bytes

```
(+).succ

```

Try it online!

I'm certain this could be shorter but I haven't found a solution yet.

# Answer
> 1 votes
# Lua, 25 bytes

```
x={...}print(x[1]+x[2]+1)

```

Try it online!

Just a trivial A+B+1 solution.

# Answer
> 1 votes
# Powershell, 15 Bytes

```
("$args"|iex)+1

```

input is in any standard mathematical format, `1+1`,`2+2`,`5123-123213`,`200*99`,`1234/555` etc.

Just takes input, invokes (calculates) it, then adds one at the end.

# Answer
> 1 votes
## Chaincode, 2 bytes

```
a+

```

Explanation:

```
a   #Adds two input values
 +  #Increment

```

# Answer
> 1 votes
# Labyrinth, 6 bytes

```
??+)!@

```

Try it online!

Takes two number inputs, prints their sum + 1.

# Answer
> 1 votes
# Scala, 26 Bytes

```
var n=(a:Int,b:Int)=>a+b+1

```

# Answer
> 1 votes
# Clack, 3 bytes

```
1++

```

Since clack has very few instructions at the moment, the shortest method is to just push 1, the two numbers, and add them.

# Answer
> 1 votes
# C, 18 bytes

```
#define f(a,b)a==b

```

try it online

# Answer
> 1 votes
# \>\<\>, 3 bytes

Also see this post, but \>\<\> needs the explicit print and termination so we can't go under 3 bytes.

```
=n;

```

But this is a pretty boring solution. There are two **5 byte** solutions

```
1nnn;

```

and

```
1++n;

```

that are only *slightly* more interesting. For input *a* and *b*, the first one works by printing *1ba* and the second by printing *a+b+1*.

Here is a TIO test bench where bytes 2-5 should be replaced by the first 4 bytes of a solution.

# Answer
> 1 votes
# Java - 44 bytes

```
int n(int a,int b){return Math.abs(a+(-b));}

```

Returns an absolute value of a + (-b)

Ungolfed version:

```
int n(int a, int b) {
    return Math.abs(a + (-b));
}

```

# Answer
> 1 votes
# ForceLang, 33 bytes

```
def a io.readnum()
io.write a+a+1

```

# Answer
> 1 votes
# Windows batch, ~~24 23~~ 17 bytes

```
@cmd/cset/a%1+%21

```

---

# Test cases:

*Tested on Win10 64-bit*

```
Foo\Bar\Baz>NotCalc.bat 1 55
552

```

---

***Note:*** *batch files are limited to **32-bit signed integer**!*

# Answer
> 1 votes
# Cardinal, 7 bytes

```
%:+~:*.

```

Outputs sum + 1

Try it online!

# Answer
> 1 votes
# Melang (Non competing) 13 bytes

```
\n\n+\n+\n\ni

```

I wrote Melang for this challenge and decided that it works so might as well bring it here.

Adds the numbers inputted together and adds one. For more on the language and to try it out visit here.

# Answer
> 1 votes
# Haskell, ~~11~~ 9 bytes

```
(succ.).(+)

```

Adds together and then adds 1

EDIT: Of course, if you want to go with the boring answer:

```
a#b=a+b+1

```

is 9 bytes.

# Answer
> 1 votes
# c++, 28 bytes

```
[](int a,int b){return!a+b;}

```

Try it here

# Answer
> 1 votes
# Japt, 3 bytes

```
NxÄ

```

Try it online

---

## Explanation

```
N   :The array of all inputs
x   :Sum the array
Ä   :Add one to each element

```

# Answer
> 1 votes
# Aceto, 9 bytes

```
ir+1
ri+p

```

Super straightforward. Prints the sum of the two inputs and 1. If I can assume for the inputs to be on the stack already, there's a 5-byte solution:

```
1+
+p

```

# Answer
> 1 votes
# Braingolf, 3 bytes

```
g1+

```

Appends the inputs to eachother (ie 17, 4 becomes 174), then increments by 1.

Notable testcases:

```
[0, 0] becomes 00, becomes 01
[0, 1] becomes 01, becomes 02
[1, 0] becomes 10, becomes 11
[1, 1] becomes 11, becomes 12

```

# Answer
> 1 votes
## MarioLANG, 35 bytes

```
;
)
;
>[!(+:
"=#===
) -
+ (
! <
#="

```

Reads two inputs and puts them in differents cells (variables). Increments one and decrements the other until the second number is zero. Then adds one calculate the wrong answer.

# Answer
> 1 votes
# Underload, 23 bytes

```
((::)~*)~(~)~*a*^*(**)*

```

Takes input in the form of Church numerals on the stack and outputs to the stack.

Try it online!

# Answer
> 1 votes
# Excel VBA, 13 Bytes

Anonymous VBE immediate window function that takes input from range `[A1:B1]` (... or really any range that is a subset of `[1:1]`, I suppose) and outputs their sum +7

```
?[Sum(1:1)+7]

```

# Answer
> 1 votes
# Perl 5, 8 bytes

7 bytes of code + 1 flag (`-p`)

```
$_+=!<>

```

Try it online!

# Answer
> 1 votes
# Implicit, 2 bytes

```
+.

```

Try it online!

```
+.   implicit input of two integers
+    add them
 .   and increment

```

`=` also works for **1 byte**, but I added that to the existing list of `=`s.

# Answer
> 1 votes
# Aceto, 6 bytes

```
rrJiIp

```

```
r reads input and puts on stack (x2)
J concatenates top 2 values
i makes it an integer
I increments it
p prints it
```

Try it online!

# Answer
> 1 votes
# x86 opcode, 2 bytes

```
INC EDX
RET

```

input EAX and EDX, output EDX:EAX If D':A=D+A then D has to be zero, making the equation still not correct

# x86 opcode \__cdecl, 3 Bytes

```
MOV DL, 3
RET

```

# Answer
> 1 votes
# MAWP, 4 bytes

```
@MM:

```

adds the numbers to the 1 in stack.

Try it!

# Answer
> 1 votes
# Google Sheets, 9

```
=--(A1=A2

```
* If A1=A2, the sum is even, but the output is always 1, which is odd.
* If A1\<\>A2, then the sum is positive, but the output is always 0, which is not positive.

Why didn't I use `=A1+A2+1`? Because if I input a sufficiently large number and `0`, the `+1` does nothing.

# Answer
> 1 votes
# HBL, 2 bytes

```
+.,1

```

Try it at HBL Online!

### Explanation

```
+     Add
 .    the first argument
  ,   the second argument
   1  and one

```

# Answer
> 1 votes
# Vyxal `HṪ`, 2 bytes

```
□∑

```

I had to post this as it is quite obfuscated.

Try it Online!

## Explanation

```
□∑
□   # Get input treated as a list separated by newlines.
 ∑  # Sum the list together.

 Created with the help of Luminespire at https://vyxal.github.io/Luminespire

```

With the explanation above, it seems like that this returns the correct sum. But if you think this, then you haven’t paid attention to the flags.

```
HṪ
H   # Before execution, push 100 to the stack.
 Ṫ  # After execution, take the sum of the whole stack and print it.

 Created with the help of Luminespire at https://vyxal.github.io/Luminespire

```

Now that you have the full picture, you realise that it adds 100 to the result.

# Answer
> 1 votes
# *Acc!!*, 31 bytes

```
Count i while N-10 {
Write 57
}

```

Takes the two numbers space-separated. Try it online!

### Explanation

```
Count i while N-10 {   # While input character is not a newline:
    Write 57           # Output 9
}

```

To prove that the output is always valid, consider the following numbers:

* A + B = the sum of the input numbers
* AB = the concatenation of the input numbers (equal to A * 10 ^ (len B) + B)
* N = a number of the same length as AB but composed of all 9's
* N+ = N with an extra 9 concatenated (equal to N * 10 + 9)

The output of this program is N+ (the extra 9 comes from the space between the input numbers). Looking at the formulas, we have A + B \<= AB, AB \<= N, and N \< N+; therefore, this program's output is always greater than (and therefore not equal to) A + B.

# Answer
> 1 votes
# brainfuck, 18 bytes

```
,[>-[----->+<]>.,]

```

Try it online!

Output is always lot larger than input

# Answer
> 1 votes
# Zsh, 8 bytes

```
<<<9$1$2

```

Try it online!

Concatenates `9 A B` which is always larger than `A + B`

# Answer
> 0 votes
# GolfScript, 3 bytes

Input is to be taken as two separate lines. In GolfScript, a preceding 0 is allowed for numbers.

```
n/0

```

Try it online!

## Explanation

```
# Two inputs taken with newlines
n/  # Split the input (separated by newlines) with newlines
  0 # Add a 0 to prevent a preceding 0
    # Implicit concatenation

```

# GolfScript, 3 bytes

```
~+)

```

Try it online!

# Explanation

```
~   # Evaluate the input
 +  # Add the two numbers
  ) # Increment the sum

```

# Answer
> 0 votes
# 1+, 6 bytes

```
..+1+:

```

As usual. `a + b + 1`.

# Answer
> 0 votes
# , 3 bytes

```
+>:

```

Try it online!

# Answer
> 0 votes
# Thunno 2, 1 byte

```
=

```

Attempt This Online!

Port of @ATaco's RProgN answer.

# Answer
> 0 votes
# J-uby, 8 bytes

```
:+%:succ

```

Attempt This Online!

---
Tags: code-golf, number, arithmetic
---


title: Generate all linked chains

text:
# Question
Title: Generate all linked chains
A followup to this challenge by Jeremy Collprav, inspired by DLosc solving this in Regenerate. Some sections copied from the linked challenge.

## Linking chains

We define a chain to be a string containing exactly one or more of only the `-` character, or 1 or more of only the `_` character, or two chains linked by a `=`. More formally, a chain follows these 6 criteria:

1. The type (`-` or `_`) of chain must change after each `=`
2. Two chains must be linked with an `=` to change
3. The chain does not begin or end with a `=`
4. No two `=` may be adjacent
5. There must be at least 3 characters and both types of chain must appear
6. The chain must only contain `_`, `-` and `=`

## Challenge

This is a challenge, where the sequence is formed by all unique strings that form a valid chain. However, you may choose exactly what order this sequence is in, so long as your program is consistent and deterministic in this order. **You must define your order in your answer**.

Having chosen an order, you may then do one of the three tasks:

* Take a non-negative/positive integer \\$n\\$ as input and output the \\$n\\$th element in the sequence. This may be 0 or 1 indexed
* Take a positive integer \\$n\\$ as input and output the first \\$n\\$ elements in the sequence, separated by a non-empty character that is not any of `-`, `_` or `=`
* Output the entire sequence, separated by a non-empty character that is not any of `-`, `_` or `=`

You may output in any format that supports infinite outputs, such as a stream, a generator, or outputting without natural halt (stopping due to physical limitations such as memory is fine). Take a look through the default output methods for other possible methods.

This is a challenge, so the shortest code in bytes in each language wins.

---

### A sample sequence

The most obvious sequence can be constructed by examining all possible links of each ascending length:

```
-=_
_=-
--=_
-=__
__=-
_=--
---=_
--=__
-=___
-=_=-
___=-
__=--
_=---
_=-=_
----=_
---=__
--=___
--=_=-
-=____
-=__=-
-=_=--
____=-
___=--
__=---
__=-=_

```

and so on. This sequence is implemented in this brute-force Jelly answer, which you can use to test for larger inputs. The top link was provided by Unrelated String's answer to the linked challenge.

# Answer
# Python 3, 59 bytes

```
*l,e='_-='
for s in l:e in s!=print(s);l+=s[0]+s,l[s>e]+e+s

```

Try it online!

Prints the sequence forever, sorted by number of non-`=` characters. Based on Ajax1234's generator. The idea is to do a BFS on valid strings by branching on either prepending a copy of the first character, or the other one of `_-` separated by an `=`. Strings without an `=` aren't printed.

*Thanks to Albert.Lang for -5 bytes*
> 6 votes

# Answer
# JavaScript (ES6), 94 bytes

*-1 thanks to @l4m2*

Returns the \\$n\\$-th entry (1-indexed) as a list of characters.

```
f=(n,k)=>n?f(n-/^(1+0)+1+$/.test(b=(k|1).toString(2)),-~k):[...b].map(x=>"-_="[+x?k&1:k++&&2])

```

Try it online!

### How?

Using the following regular expression, we look for all binary patterns that start and end with a `1`, contain at least one `0` and do not contain two adjacent `0`'s:

```
/^(1+0)+1+$/

```

(This is the intersection of A005408, A062289 and A003754.)

By interpreting `0` as the link character (`=`) and `1` as a chain character (`-` or `_`), we can build exactly two valid outputs for each binary pattern. For instance, `1011` gives `_=--` and `-=__`.

---

# JavaScript (ES6), 83 bytes

@l4m2 pointed out that this can work in base 10 just as well. However, the call stack overflow will happen quite early.

```
f=(n,k)=>n?f(n-/^(1+0)+1+$/.test(b=k|1),-~k):[...b+''].map(x=>"-_="[+x?k&1:k++&&2])

```

Try it online!
> 4 votes

# Answer
# Vyxal, 153 bitsv1, 19.125 bytes

```
{n‛=_‹↔'\=~-Ġj=nUṪ∧;⁋,

```

Try it Online!

Keen readers will notice that this answer includes almost the entirety of my answer to the other question. Uses the mapping defined in the question and outputs infinitely.

I'm having way too much fun with vyncode on this one - same sbcs yet different bit count. This answer started at 25 SBCS bytes/180 bits and is now 25 SBCS bytes/169 bits.

## Explained

```
{n‛=_‹↔Ṡ'\=-Ġṅ\=j=nUṪ∧;⁋,
{                          # Forever:
 n    ↔                    #   Generate all combinations w/ repetition with (loop count) characters from
  ‛=_‹                     #   The string "=_" + "-"
       Ṡ                   #   Convert each combination to a string
        '             ;    #   Keep only combinations n where:
         \=-               #     Removing any "="s, then
            Ġṅ             #     Grouping on consecutive characters, then
              \=j=         #     Joining on "="s equals n
                     ∧     #     And
                  nU       #     removing all duplicate characters from n
                    Ṫ      #     leaves more than one item
                       ⁋,  #   Join the list of filtered combinations on newlines and print

 Created with the help of Luminespire at https://vyxal.github.io/Luminespire

```
> 3 votes

# Answer
# Python3, 114 bytes

A generator that, when consumed, proceeds to produce the entire sequence.

```
def f():
 k='_-';q=[*k]
 while q:
  if{*k}&{*(c:=q.pop(0))}=={*k}:yield c
  T=c[-1]=='-'
  q+=[c+'='+k[~T],c+k[T]]

```

Try it online!
> 3 votes

# Answer
# Charcoal, 47 bytes

```
Ｎθ≔Φ⮌↨θ²κη≔⁺²↨⮌Φη﹪κ²¦²ζ⪫Ｅζ×⊕↨⮌Φη⁼﹪μ⊗ζ⊗ι²§-_⁺ιθ=

```

Try it online! Link is to verbose version of code. 0-indexed. Explanation:

```
Ｎθ

```

Input `n`.

```
≔Φ⮌↨θ²κη

```

Convert `n` to base `2`, but lose the LSB, as that will determine whether the chain starts with `-` or `_`.

```
≔⁺²↨⮌Φη﹪κ²¦²ζ

```

Gather the remaining even bits and convert back from base `2`, then add `2`. This will be the number of chains.

```
⪫Ｅζ×⊕↨⮌Φη⁼﹪μ⊗ζ⊗ι²§-_⁺ιθ=

```

Split the odd bits up among the chains, convert them back from base `2`, then add `1`. This gives the lengths of each chain. The chains alternate with the first chain character determined by the original LSB. The chains are then joined with `=`s.
> 3 votes

# Answer
# JavaScript (V8), 74 bytes

```
f=(h,i,...j)=>f(...j,h[0]+h,i||print(h),(h<{}?'_=':'-=')+h,0);f(...'_x-x')

```

Try it online!
> 2 votes

# Answer
# 05AB1E, 26 bytes

```
∞ε…-=_×æyùêʒD'=Kγ'=ýQyË›]˜

```

Outputs the infinite sequence.
Based on my 05AB1E answer for the base challenge.

Try it online. (Times out for \\$n\>7\\$.)

**Explanation:**

```
∞             # Push an infinite positive list: [1,2,3,...]
 ε            # Map each integer to:
  …-=_        #  Push string "-=_"
      ×       #  Repeat it the current integer amount of times
       æ      #  Get the powerset of this string
        yù    #  Only keep the strings with a length of the current integer
          ê   #  Sorted uniquify this list of strings
  ʒ           #  Filter it by:
   D          #   Duplicate the current string
    '=K      '#   Remove all "="
       γ      #   Group the remaining characters ("-" and "_") into groups of adjacent
              #   equivalent characters
        '=ý  '#   Join these groups with "="-delimiter
   D       Q  #   Check if the string is the same as what we started with
   y          #   Push the current string again
    Ë         #   Check if all its characters are the same
   ›          #   Check whether the first check is larger than the second
              #   (aka, the first check is truthy and the second check is falsey)
 ]            # Close both the filter and map
  ˜           # Flatten the infinite list of lists of strings
              # (after which it is output implicitly as result)

```
> 2 votes

# Answer
# Nekomata, 15 bytes

```
"-_"Ňŧĉᵗz'=ᵚcjt

```

Takes no input and outputs all possible results.

Attempt This Online!

```
"-_"Ňŧĉᵗz'=ᵚcjt
    Ň               Choose a natural number
"-_" ŧ              Choose a string of '-' and '_' of that length
      ĉ             Split the string into runs of identical characters
       ᵗz           Check that there are at least two runs
         '=ᵚc       Prepend '=' to each run
             j      Join the runs together
              t     Remove the first '='

```

---

## Nekomata before v0.5.0.0, 18 bytes

```
Ň"-_"ᵚ~ĉᵗz"="ᵚcjjt

```

Attempt This Online!
> 2 votes

---
Tags: code-golf, string, sequence, open-ended-function
---


title: How many petals around the rose

text:
# Question
Title: How many petals around the rose
# How many petals around the rose

How many petals around the rose is a dice game you can play with your friends. Similar to "can I join the music box", there is a person that knows how the game works and the others have to discover the rule.

In this game, someone rolls some dice (usually two or more) and then people have to call "how many petals are around the rose".

# Algorithm

If you want to play it by yourself, you can play it over at TIO. Just hide the header (which is where the rule is implemented) and try passing different arguments (from 1 to 6) in the function.

**spoiler, what follows *is* the rule you are invited to find by yourself!**

> The "roses" here are the dice, and the "petals" are the black dots that are *around* a central dot. Because only the odd numbers have a central black dot, only numbers `1, 3, 5` matter for the petals. Those numbers have, respectively, `0, 2, 4` dots around the central dot, the "petals".

# Input

Your input will be a non-empty list (or equivalent) of integers in the range `[1, 6]`.

# Output

The number of petals around the rose.

# Test cases

Reference implementation in Python, that also generated the test cases.

```
1, 1 -> 0
1, 2 -> 0
1, 3 -> 2
1, 4 -> 0
1, 5 -> 4
1, 6 -> 0
2, 1 -> 0
2, 2 -> 0
2, 3 -> 2
2, 4 -> 0
2, 5 -> 4
2, 6 -> 0
3, 1 -> 2
3, 2 -> 2
3, 3 -> 4
3, 4 -> 2
3, 5 -> 6
3, 6 -> 2
4, 1 -> 0
4, 2 -> 0
4, 3 -> 2
4, 4 -> 0
4, 5 -> 4
4, 6 -> 0
5, 1 -> 4
5, 2 -> 4
5, 3 -> 6
5, 4 -> 4
5, 5 -> 8
5, 6 -> 4
6, 1 -> 0
6, 2 -> 0
6, 3 -> 2
6, 4 -> 0
6, 5 -> 4
6, 6 -> 0
3, 1, 5 -> 6
4, 5, 2 -> 4
4, 3, 5 -> 6
1, 4, 4 -> 0
5, 5, 2 -> 8
4, 1, 1 -> 0
3, 4, 1 -> 2
4, 3, 5 -> 6
4, 4, 5 -> 4
4, 2, 1 -> 0
3, 5, 5, 2 -> 10
6, 1, 4, 6, 3 -> 2
3, 2, 2, 1, 2, 3 -> 4
3, 6, 1, 2, 5, 2, 5 -> 10

```

---

This is so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!

# Answer
> 30 votes
# Python 3, 30 bytes

```
lambda l:sum(n**3&6for n in l)

```

Try it online!

(test cases shamelessly borrowed from xnor's answer)

### How?

Given \\$1\le n\le6\\$, the number of petals can be computed with:

$$p=n^{2k+1} \operatorname{and}6,\\:k\in\mathbb{N}^\*$$

where \\$\operatorname{and}\\$ is a bitwise operator.

This can also be written as:

$$p=2\times\left\lfloor\frac{n^{2k+1}\bmod 8}{2}\right\rfloor$$

And is based on the fact that, for any \\$k\ge1\\$:

$$n^{2k+1}\bmod 8=\cases{ n&\text{if $n$ is odd ($1$, $3$ or $5$)}\\ 0&\text{if $n$ is even ($2$, $4$ or $6$)} }$$

More specifically, choosing \\$k=1\\$:

$$p=n^3 \operatorname{and}6$$

As Python code, the resulting expression is just as long as the nice `n%-2%n` found by xnor. But because it ends with a digit, we can get rid of the space just before the `for`, saving a byte.

```
 n | n**3 | as binary  | AND 6
---+------+------------+-------
 1 |    1 | 00000 **00** 1 |   0
 2 |    8 | 00001 **00** 0 |   0
 3 |   27 | 00011 **01** 1 |   2
 4 |   64 | 01000 **00** 0 |   0
 5 |  125 | 01111 **10** 1 |   4
 6 |  216 | 11011 **00** 0 |   0

```

# Answer
> 18 votes
# Retina 0.8.2, 11 bytes

```
5
33
3
33
3

```

Try it online! Link includes test cases. Input can be in almost any format really as only the `5`s and `3`s count. Explanation:

```
5
33

```

A `5` has as many petals as two `3`s.

```
3
33

```

Speaking of `3`s, they have two petals, so make them count twice.

```
3

```

Count the petals.

# Answer
> 11 votes
# Python, 31 bytes

```
lambda l:sum(n%-2%n for n in l)

```

Try it online!

The core expression `n%-2%n` evaluates to zero for even `n` and to `n-1` for odd `n`.

```
       | n%-2   n%-2%n
-------+--------------
n even |    0        0
n odd  |   -1      n-1

```

# Answer
> 6 votes
# , ~~26~~ 23 bytes

```
function(l)l%%2%*%(l-1)

```

Try it online!

*-3 thanks to Robin Ryder!*

Returns a 1x1 matrix with the result.

---

Old answer, since there are a handful of explicit ports:

```
function(l)sum((l-1)*l%%2)

```

Try it online!

# Answer
> 6 votes
# Jelly,  ~~7~~  4 bytes

-3 using Giuseppe's method!

```
Ḃ×’S

```

**Try it online!**

### How?

We know that 3's and 5's "score", that they score one less than their pips, and that \\$1-1=0\\$ so:

```
        throw   1  2  3  4  5  6
  x=throw - 1   0  1  2  3  4  5
  y=throw % 2   1  0  1  0  1  0
score = x * y   0  0  2  0  4  0

```

So:

```
Ḃ×’S - Link: throws, list of integers in [1,6]   e.g. [1,2,3,4,5,6]
Ḃ    - (throws) % 2                                   [1,0,1,0,1,0]
  ’  - (throws) - 1                                   [0,1,2,3,4,5]
 ×   - multiply                                       [0,0,2,0,4,0]
   S - sum                                            6

```

# Answer
> 5 votes
# Perl 6, ~~17~~ 16 bytes

```
{sum $_>>³X+&6}

```

Try it online!

Uses Arnauld's formula of \\$n^3\\&6\\$. If HyperWhatevers worked, then something like `(**³+&6).sum` should be possible for 13 bytes.

My old regex based solution:

```
{sum m:g/3|5/X-1}

```

Try it online!

Match 3s and 5s from the input, subtract one from each and sum them together.

# Answer
> 4 votes
# Python, 32 bytes

```
lambda d:sum(r%2*~-r for r in d)

```

Port of Giuseppe's R answer.

**Try it online!**

# Answer
> 4 votes
# , 9 bytes

```
1#.2&|*<:

```

Try it online!

* `1#.` Sum of applying the following to each element...
* `2&|` Remainder when divided by 2
* `*` Times...
* `<:` Number decremented by 1

# Answer
> 4 votes
# Japt `-mx`, 3 bytes

```
³&6

```

Try it

Saved 2 bytes using Arnauld's formula so be sure to `+1` him if you're `+1`ing this.

## Original, 5 bytes

```
fu xÉ

```

Try it

# Answer
> 4 votes
# AWK, 29 28 26 bytes

```
/3|5/{x+=$0-1}END{print+x}

```

Try it online!

*-1 byte thanks to Jo King*

*-2 bytes thanks to user41805*

`+x` is needed so that inputs with no odd numbers still return 0.

# Answer
> 3 votes
# PHP, ~~55~~ ~~53~~ 51 bytes

```
fn($a)=>array_sum(array_map(fn($v)=>$v%2*~-$v,$a));

```

Try it online!

-2 bytes thanks to @RGS

# Answer
> 3 votes
# Python 3, ~~40~~ ~~33~~ 32 bytes

Saved 7 bytes thanks to RGS!!!

```
lambda d:sum(i%2*~-i for i in d)

```

Try it online!

This turns out to be a total rip off of Jonathan Allan's Python answer so update him instead.

# Answer
> 3 votes
# Haskell, 23 bytes

```
f x=sum[n-1|n<-x,odd n]

```

Try it online!

# Answer
> 3 votes
# C (gcc), ~~50~~ 48 bytes

Saved 2 bytes thanks to xibu!!!

```
s;f(l,p)int*p;{for(s=0;l--;)s+=*p%2*~-*p++;l=s;}

```

Try it online!

Inputs an integer array pointer preceded by its length.

# Answer
> 3 votes
# 05AB1E, ~~5~~ 4 bytes

```
ÉÏ<O

```

Try it online!

*-7 byes thanks to Expired Data*

*-1 byte thanks to Grimmy*

As promised, someone who knows 05AB1E better than I came and golfed it somehow.

## 11 bytes

```
ε2%}Iε1-}*O

```

Try it online!

I'm sure someone who knows 05AB1E better than I do will come along and golf this somehow. Really simple:

```
ε2%}   # Map the code 2% (mod 2) to each element of the implicit input
Iε1-}  # Map the code 1- (sub 1) to each element of the explicit input
*O     # Multiply the two lists and sum

```

# Answer
> 3 votes
# Wolfram Language (Mathematica), 25 bytes

```
Tr[(Mod[#,2]#//.0->1)-1]&

```

Try it online!

# Answer
> 3 votes
# C# (Visual C# Interactive Compiler), 20 bytes

```
a=>a.Sum(x=>x--%2*x)

```

Try it online!

# Answer
> 3 votes
# TI-BASIC, ~~13~~ 12 bytes

I found some 12 byte solutions

```
Ans-1:sum(Ansnot(fPart(Ans/2

```

The previous is the same byte count as below due to the line separator costing a byte

```
sum((Ans-1)2fPart(Ans/2

```

The above solutions use NfPart(Ans/N as a modulus operation to judge even/odd, giving us a list of dice that can have petals. Multiplying that by the original list -1 restores the petal counts to the list which can then be summed

```
2sum(Ans=3)+4sum(Ans=5

```

The original 13 byte solution simply compared the list once against 3 and separately against 5 before summing those results independently to get the petal count

All the above solutions take input as a list in Ans

# Answer
> 3 votes
# Julia 1.0, ~~23~~ 16 bytes

```
l->sum(l.^3 .&6)

```

Try it online!

-7 Bytes thanks to Maria Miller

# Answer
> 3 votes
# Brain-Flak, ~~66~~ ~~60~~ ~~44~~ 42 bytes

*Two bytes saved by Jo King*

```
({(({}[()])<>)<>{<({}[()])><>([{}])<>}{}})

```

Try it online!

This challenge seems to ellude a straight forward solution in Brain-flak. It was quite fun to golf.

# Answer
> 3 votes
# Java (JDK), ~~47~~ 45 bytes

```
r->{int s=0;for(int i:r)s+=i%2*~-i;return s;}

```

First time code golfing, hope I posted this right.

-2 Bytes by removing unneeded curly brackets

Try it online!

# Answer
> 2 votes
# , 5 bytes

```
►S≡5u

```

Uncompressed:

(S2m*J

(      % Decrement input
 S     % Swap a copy of the input up
  2m   % Modulo the value by 2
    *  % Multiply them
     J % Find their sum
```
</code></pre>

# Answer
> 2 votes
# Perl 5 `-pl`, 15 bytes

```
$\+=$_%2*$_&6}{

```

Try it online!

Takes the input list as one entry per line.

# Answer
> 2 votes
## Roj, ~~134~~ ~~92~~ ~~88~~ ~~86~~ 65 bytes

Considerably easier than the previous challenge. Takes numbers in separate lines and end input with the input `0`. Outputs via return value. (Dramatically saved 42 bytes by using dynamic input)

```
O=0;i=1;while i do readint i;if i==3 or i==5 do O=O+i-1 end end;O

```

# Answer
> 2 votes
# Bash \+ Core utilities, ~~37~~ ~~35~~ ~~34~~ ~~30~~ 29 bytes

```
sed s/5/33/\;p|tr -cd 3|wc -c

```

Try it online!

---

Shortened by 1 byte: Thanks to @user41805 for pointing out that OP is allowing the program to require one number per line, which lets me eliminate the `g` flag from the sed command.

---

Shortened by 4 bytes thanks to @Neil! The change is to use sed to print the output twice, before counting characters, eliminating the need to double the character count.

---

I was going to use the formula `n%2*(n-1)`, but then I saw that everybody else had the same idea, so I decided to do something different.

Input is a list of integers between 1 and 6, inclusive, on stdin, with one number per line.

Output is on stdout.

**The 30-byte version:**

Uses @Neil's idea of using sed to print the line twice, eliminating the need to double the number.

**The 34-byte version:**

One byte shorter: instead of multiplying by 2, I now add the number to itself.

**How the 35-byte version worked:**

1. Replace every instance of `5` by `33`. (The number of `3`s is now half the desired answer.)
2. Delete all characters except `3`. (This even eliminates the `\n` at the end of the line.)
3. Use `wc` (without the `-c` option this time) to print the number of lines, the number of words, and the number of characters, separated by spaces.
4. Use `dc` to double the number of characters, ignoring the number of lines and the number of words.

**How the original 37-byte version worked:**

1. Replace every instance of `5` by `33`.
2. Replace every instance of `3` by `33`. (In particular, every `5` in the original string has now become `3333`.)
3. Delete all characters except `3`. (This even eliminates the `\n` at the end of the line.)
4. Count and print the number of characters in what remains. (Every `3` in the original string has been replaced by `33`, every `5` has been replaced by `3333`, and everything else has been removed.)

*In looking through the various submissions, it turns out that @Neil's Retina answer had used the same method as my original 37-byte version (but he was earlier). I wasn't sure at first, since I've never used Retina, but @Neil confirmed it.*

*The newer versions work somewhat differently, though.*

# Answer
> 2 votes
# APL (Dyalog Unicode), 8 bytes<sup>SBCS</sup>

```
+/⊢|¯2|⊢

```

Try it online!

A port of xnor's double modulo trick.

### How it works

```
+/⊢|¯2|⊢
    ¯2|⊢  ⍝ Input modulo -2; 0 if even, -1 if odd
  ⊢|      ⍝ That modulo input; 0 if even, n-1 if odd
+/        ⍝ Sum

```

---

# APL (Dyalog Unicode), 9 bytes<sup>SBCS</sup>

```
2∘|+.×-∘1

```

Try it online!

### How it works

```
2∘|+.×-∘1
      -∘1  ⍝ Decrement input
   +.×     ⍝ Dot product with
2∘|        ⍝ Input modulo 2

```

# Answer
> 2 votes
# Ruby, ~~23~~ 21 bytes

```
->a{a.sum{|x|x**9&6}}

```

Try it online!

Actually using the same idea as Arnauld, only with bigger numbers. Read his explanation and upvote him.

# Answer
> 2 votes
# Icon, 50 bytes

```
procedure f(a)
n:=0&n+:=!a-1=(2|4)&\z
return n
end

```

Try it online!

## Explanation:

```
procedure f(a)         # the argument a is the list
    n:=0 &             # sets the sum to 0 and
    n+:=!a-1=(2|4) &   # add to n (n+:=) each element of a decreased by one (!a-1),
                       # if it now equals 2 or 4 (=(2|4)) and
    \z                 # loop (in fact checks if a variable z exists - since it
                       # doesn't, backtracks to get the next element of a, if any)
    return n           # returns the sum
end

```

# Answer
> 2 votes
# K (oK), 13 bytes

```
{+/(2!x)*x-1}

```

Try it online!

Essentially same as Jonah's J solution

# Answer
> 2 votes
# Actually, 8 bytes

A port using Arnauld's formula.

```
⌠3ⁿ6&⌡MΣ

```

Try it online!

# Answer
> 2 votes
# Excel, 34 bytes

```
=SUMIF(A:A,3)/3*2+SUMIF(A:A,5)/5*4

```

`SUMIF` does much of the work for us.

Feel like there should be a solution using `SUMPRODUCT`, but have not found it yet.

# Answer
> 2 votes
# Burlesque, 12 bytes

```
psf{2.%}?d++

```

Try it online!

```
ps     # Parse input to array
f{2.%} # Filter for mod2 == 1
?d     # Decrement each
++     # Sum

```

# Answer
> 2 votes
# MathGolf, 4 bytes

```
(Ç¥Σ

```

Try it online.

**Explanation:**

```
(     # Decrease each value in the (implicit) input-list by 1
 Ç    # Inverted filter this list by (so keep those which are falsey):
  ¥   #  Modulo-2
   Σ  # And sum each remaining item
      # (after which the entire stack joined together is output implicitly as result)

```

# Answer
> 2 votes
# Red, 48 bytes

```
func[b][s: 0 foreach a b[s: a - 1 *(a % 2)+ s]s]

```

Try it online!

# Answer
> 2 votes
# Charcoal, 7 bytes

```
ＩΣ＆⁶ＸＡ³

```

Try it online! Link is to verbose version of code. Port of @Arnauld's Python answer, as Charcoal supports vectorising those operations. Explanation:

```
     Ａ  Input array
    Ｘ ³ Cubed (vectorises)
   ⁶    Literal `6`
  ＆     Bitwise And (vectorises)
 Σ      Sum
Ｉ       Cast to string for implicit print

```

Since  is commutative, the  is placed first in order to keep it separate from the `³`.

# Answer
> 2 votes
# GolfScript, 10 bytes

Port of Arnauld's Python answer.

```
0\{3?6&+}/

```

Try it online!

# Answer
> 2 votes
# C (gcc), 38 bytes

```
b;f(int*a){b=(b=*a++)?b%2*~-b+f(a):0;}

```

Input as 0-terminated array `a`.

Recursive function.

*-10 bytes thanks to Arnauld!*

Try it online!

# Answer
> 2 votes
# Batch, ~~101~~ 90 Bytes

```
@Set _=0
@For %%A in (%*) Do @For %%B in (3,5) DO @IF %%A EQU %%B Set /A _+=%%B-1
@Set _

```

11 bytes saved using Neil's suggestions

# Answer
> 2 votes
# Powershell, 32 18bytes

```
1.."$args"|?{$_%2}

```

Example input 6 will output

```
1
3
5

```

Saved 14 bytes thanks to @mazzy

# Answer
> 2 votes
# PowerShell, 29 bytes

```
$args|?{$_%2}|%{$i+=$_-1}
+$i

```

Try it online!

Takes input via splatting

# Answer
> 2 votes
# Husk, 6 bytes

```
Σm←f%2

```

Try it online!

Direct port of my Haskell answer.

```
   f%2 Take the odd numbers
 m←    Decrement them
Σ      Sum

```

# Answer
> 2 votes
# JavaScript (V8), 34 bytes

```
r=>r.map(i=>d+=i&1&&i>>1<<1,d=0)|d

```

Try it online!

# Answer
> 2 votes
# Vyxal, 4 bytes

```
~∷‹∑

```

Try it Online!

```
~    # Filter by
 ∷   # Odd?
  ‹  # Decrement
   ∑ # Sum

```

# Answer
> 2 votes
# Jelly, 3 bytes

```
’ḋḂ

```

Try it online!

```
’      Decrement each number,
  Ḃ    and take each number mod 2.
 ḋ     Return the dot product of both vectors of results.

```

# Answer
> 1 votes
# APL+WIN, 16 bytes

Prompts for vector of integers

```
+/2 4[(3 5⍳⎕)~3]

```

Try it online! Courtesy of Dyalog Classic

# Answer
> 1 votes
# Keg, `-rR` , 13 bytes

```
÷0&(¦32⑼|54⑼™

```

Try it online!

On days like these, kids like you, should be grateful that SBCS's exist. Because otherwise, this'd be 21 bytes.

Input is taken as a number with no commas. So a roll of `5, 5, 3` would be inputted as `553`.

## Explanation

```
÷           # Item split the implicit input.
0&          # Store 0 in the register.
(           # For each item in the stack:
    ¦       #   Switch statement:
    32⑼     #   If the item is 3, add 2 to the register.
    |54⑼    #   If the item is 5, add 4 to the register.
    ™       #   End switch statement.

# -rR prints the value in the register rawly. In other words, as a number.

```

# Answer
> 1 votes
# Rabbit~, 31

```
_[.0{.51}{+.2}{.53}{+.4}>]_+++:

```

Explanation:

```
_                               - Move to input
 [.0                    >]      - Loop over die rolls
    {.51}{+.2}                  - If die roll is 3 add 2
              {.53}{+.4}        - If die roll is 5 add 4
                          _+++: - Move out of the way, flush and print addition result

```

51 and 53 is ascii for 3 and 5

# Answer
> 1 votes
# Pure data, 401 bytes

```
#N canvas;#X obj 0 0 inlet;#X obj 0 0 list split 1;#X obj 0 0 i;#X obj 0 0 outlet;#X msg 0 0 0;#X obj 0 0 t l;#X obj 0 0 del;#X obj 0 0 expr $i2+$i1%2*($i1>>1);#X obj 0 0 i;#X connect 0 0 4 0;#X connect 0 0 5 0;#X connect 1 0 7 0;#X connect 1 1 5 0;#X connect 1 2 6 0;#X connect 2 0 3 0;#X connect 4 0 8 0;#X connect 5 0 1 0;#X connect 6 0 2 0;#X connect 7 0 8 0;#X connect 8 0 7 1;#X connect 8 0 2 1;

```

Pure Data is a graphical programming language for audio processing.

Here is what my the source looks like:

It is pretty unreadable since I saved bytes by placing all elements at coordinate `0 0`. Here it is reorganized so you can read the elements.

It is important to note that execution in pure data sometimes depends on the order in which objects were created, which is not visible in images like this. For this answer to work The `inlet` object must be connected to the `0` message *before* the `t 1` object. This shows up in the source code as that connection being earlier on.

Most of the program is just list processing. The logic is actually handled in the `expr` block

```
#X obj 0 0 expr $i2+$i1%2*($i1>>1);

```

Here `$i1` is the current element and `$i2` is the result of the last `expr`. So this bitshifts the element down by one, which is intended result for odd numbers. To make even numbers we then multiply it by its 2 modulus, which is zero for even numbers and 1 for odd numbers.

---

Thanks to 0 ' for working on this with me.

# Answer
> 1 votes
# Thunno, \\$ 7\log\_{256}(96)\approx \\$ 5.76 bytes

```
g2%k1-S

```

Attempt This Online!

Port of Kevin Cruijssen's MathGolf answer.

# Thunno, \\$ 9\log\_{256}(96)\approx \\$ 7.41 bytes

```
D2%s1-z*S

```

Attempt This Online!

Port of Jonathan Allan's Jelly answer.

#### Explanations

```
g2%k1-S  # Implicit input
g  k     # Filter for those which are:
 2%      #  Odd
    1-   # Subtract one from each
      S  # Sum

D2%s1-z*S  # Implicit input
D2%        # Duplicate and mod by 2
   s1-     # Swap and subtract one
      z*   # Multiply
        S  # Sum

```

# Answer
> 0 votes
# Thunno 2 `S`, 4 bytes

```
ɗ$⁻×

```

Try it online!

#### Explanation

```
ɗ$⁻×  # Implicit input
ɗ     # Mod each item by 2
 $    # Push the input again
  ⁻   # Decrement each item
   ×  # Multiply elementwise
      # Implicit output

```

# Answer
> 0 votes
# JavaScript (V8), 29 bytes

```
r=>r.map(i=>d+=i%2*--i,d=0)|d

```

Try it online!

---
Tags: code-golf, integer
---


title: Draw the Easter Bunny

text:
# Question
Title: Draw the Easter Bunny
This happy individual is known in folklore as the Easter Bunny.

# Colours

It is created using 4 colours:

* Light pink
* Dark pink
* White
* Black

(I'm happy for these colours to be approximated in your answer. It does not need to be this precise shade)

# Shapes

It is constructed of these shapes:

* Two tall ellipses in light pink (outer ears). They have the same height and width.
* Two tall ellipses in dark pink (inner ears). They are smaller than the outer ears and one is drawn on top of each of the outer ears. They are the same height and width.
* One large circle in light pink (head). It intersects with the bottom third of both outer ears (but no higher).
* Two circles in white (outer eyes). They are drawn on the head. Their diameter is less than the width of the outer ears. They have the same horizontal position as the outer ears.
* Two circles in black (inner eyes). They have a smaller diameter than the outer eyes. One is drawn on each of the outer eyes.
* One vertical line in black (upper mouth). It is drawn on the head and is lower than the bottom of the outer eyes. It is roughly equidistant from each eye.
* Two arcs in black (lower mouth). They are drawn on the head and arc downwards from a horizontal line. Both intersect with the bottom of the upper mouth, but one goes right and the other goes left.

---

# The Rules

* Use any language and tools you like.
* Output can be an image, html, svg, or other markup.
* It's code golf, so aim to do it in the smallest number of bytes.
* Please include a screenshot of the result.
* Please feel free to approximate the colours defined.

# Happy Easter!

# Answer
# T-SQL, ~~445~~ 439 bytes

```
DECLARE @ GEOMETRY='MULTIPOINT((3 3),(7 3))',
@l GEOMETRY='CIRCULARSTRING(3 6,3.3 9,3 12,2.7 9,3 6)',@r GEOMETRY
SET @=@.STBuffer(.6)SET @r=@l.STUnion('CIRCULARSTRING(7 6,7.3 9,7 12,6.7 9,7 6)')
SELECT*FROM(VALUES(@),(@),(@),(@r.STBuffer(.3)),(@),(@),(@),(@),(@),(@),(@),(@),(@),
(@),(@),('CIRCULARSTRING(7 0,6 -1,5 0,5 1,5 1,5 0,5 0,4 -1,3 0)'),
(GEOMETRY::Point(5,1,0).STBuffer(5).STUnion(@r.STBuffer(1.3)).STDifference(@.STBuffer(.4)))
)a(g)

```

This site could use more T-SQL-based drawings!

Run on SQL 2017, but uses SQL geo-spatial storage features added back in SQL 2008. Line breaks are for readability only.

Output:

So, this was a pain to do in T-SQL, since spatial objects aren't exactly designed for drawing (no "ellipse" object, for example). Even more, getting the colors even *close* to right required a bit of trial and error.

Basically I'm constructing the following geometric objects:

1. The eyes (`@`), which are points expanded into disks using `STBuffer(.6)` (the set of all points within 0.6 of those starting points)
2. The ears (`@r`), which are generated as pointy curves, but are "puffed out" using `STBuffer` into either the inner or outer ears
3. The face, which is a disk plus the ears minus the eyes. I have to construct this and display it as a single object, or SQL would display it in different colors.
4. The mouth, which is a curve created using `CIRCULARSTRING`

To get the colors right, I have to `SELECT` these *in the proper order*. SSMS has a built-in sequence of colors for objects displayed in the spatial results pane, so the dark pink inner ears had to come *4th*, and the light pink face had to come *16th*. This required putting in a whole bunch of extra copies of the eyes, which is ok since we want them as close to black as possible (colors are somewhat transparent, so stacking them makes them darker).

Help and inspiration from the following resources:

**EDIT**: Moved the bunny down by 4 units, which changes some coordinates to a single digit, saving 6 bytes. No change in displayed output.
> 19 votes

# Answer
# Red, ~~375~~ ~~340~~ 329 bytes

```
Red[needs 'View]f: 'fill-pen p: 'pen e: 'ellipse c: 'circle
t:[5x5 0 180]view[base 200x200 #FFF draw
compose[(p)pink(f)pink(c)100x100 30(e)75x25
20x60(e)105x25 20x60(p)#E28(f)#E28(e)79x35 12x35(e)109x35
12x35(p)#FFF(f)#FFF(c)88x92 8(c)112x92 8(p)#000(f)#000(c)88x92
5(c)112x92 5 line 100x108 100x115 arc 95x115(t)arc 105x115(t)]]

```
> 11 votes

# Answer
# Python, 368 bytes

Using matplotlib.

```
from matplotlib import pyplot as l,patches as p,transforms as t;z=0,;[l.gca().add_patch(p.Wedge(z*2,R,s,360,width=w,color=(r,o,o),transform=t.Affine2D.from_values(X,0,0,9,350+x*n,y*9)))for R,s,w,r,o,X,x,y in zip([11,7,15,4,2,2,99],z*5+(180,359),[None]*5+[.2,.4],(1,)*4+z*3,(.8,.6,.8,1)+z*3,[4,4]+[9]*5,[7,7,0,6,6,2,98.8],[51,51,30,35,35,24,26])for n in[-9,9]];l.show()

```

Result:

Ungolfed:

```
from matplotlib import pyplot, patches, transforms
z = 0, # store zero as a tuple for later repetition
for radius, startAngle, width, red, other, xStretch, x, y in \
    zip([11 ,7  ,15 ,4  ,2  ,2  ,99   ],  # radius
        z * 5 +             (180,359  ),  # start angle
        [None] * 5 +        [.2 ,.4   ],  # wedge width (None = full)
        (1,) * 4        +z * 3         ,  # red channel
        (.8 ,.6 ,.8 ,1) +z * 3         ,  # other color channels
        [4]*2 + [9]*5                  ,  # x stretch factor
        [ 7 ,7  ,0  ,6  ,6  ,2  ,98.8 ],  # x
        [51 ,51 ,30 ,35 ,35 ,24 ,26   ]): # y
#        |   |   |   |   |   |   |
#        |   |   |   |   |   |   "straight" line for upper mouth
#        |   |   |   |   |   |   approximated by large radius arc
#        |   |   |   |   |   |
#        |   |   |   |   |   Arc for lower mouth
#        |   |   |   |   |
#        |   |   |   |   Inner eye circle
#        |   |   |   |
#        |   |   |   Outer eye circle
#        |   |   |
#        |   |   Circle for head
#        |   |
#        |   Inner ear ellipse
#        |
#        Outer ear ellipse

    for n in [-9, 9]:        # draw left and right side mirrored
        pyplot.gca().add_patch( patches.Wedge(
            z*2,       # center = (0, 0), actual location set by the transform below
            radius,
            startAngle,
            360,       # end angle
            width = width,
            color = (red, other, other), # only red channel varies from the others
            transform = transforms.Affine2D.from_values( # affine transform matrix
                xStretch,    # x stretch factor
                0, 0,        # unused cross-axis coefficients for skew/rotation
                9,           # y stretch factor
                x * n + 350, # x value reflected by n, centered at 350
                y * 9 )))    # y value

pyplot.show()

```
> 8 votes

# Answer
# Ruby with Shoes, 240 characters

```
Shoes.app{['fcc',[0,40,60],[5,0,20,50],[35,0,20,50],'f99',[t=10,t,t,h=30],[40,t,t,h],'fff',[t,55,15],[35,55,15],'000',[14,58,7],[38,58,7]].map{|v|stroke fill v rescue oval *v}
nofill
line h,75,h,80
arc 25,80,t,t,0,3.14
arc 35,80,t,t,0,3.14}

```

Sample output:
> 7 votes

# Answer
# JavaScript + P5.js, ~~291~~ ~~276~~ 273 bytes

A lot of small changes this time around.. that don't change the byte size at all.

```
setup=_=>{createCanvas(u=400,u);(e=ellipse,f=fill)`#fcc`;e(u/=2,u,x=150,x);e(x+=10,z=99,50,z);e(w=240,z,50,z);f`#f77`;e(x,z,y=30,80);e(w,z,y,80);f``;e(w,v=180,y,y);e(x,v,y,y);f(0);e(w,v,y=9,y);e(x,v,y,y);noFill(line(u,225,u,250));arc(195,...a=[245,y,y,0,PI]);arc(205,...a)}

```

Try it online!

Explanation:

```
setup = _ => {
    createCanvas(u=400, u);                 // Create basic canvas.
    (e = ellipse, f = fill)`#fcc`;          // Light pink
    e(u /= 2, u, 150, 150);                 // These first few lines end up defining short-hand names for functions.
    e(x += 10, z = 99, 50, z);              // Throughout the code, you will see
    e(w = 240, z, 50, z);                   // lots of variable definitions.
    f`#f77`;                                // Dark pink
    e(x, z, y = 30, 80);                    // Another variable declaration
    e(w, z, y, 80);
    f``;                                    // Empty fill argument = white, apparently? (Eyes start here)
    e(w, v = 180, y, y);                    // I'll just stop commenting on declarations now
    e(x, v, y, y);
    f(0);                                   // fill(x) = fill(x, x, x)
    e(w, v, y = 9, y);
    e(x, v, y, y);
    noFill(line(u, 225, u, 250));           // Last part of bunny starts here.
                                            // Get rid of fill so the bunny doesn't look bad
    arc(195, ...a= [245, y, y, 0, PI]);
    arc(205, ...a)                          // arc() creates something similar to a semi-circle.
}

```
> 5 votes

# Answer
## Javascript, ~~381~~ 326 bytes

Thanks Arnold and Epicness.

```
(d=document).body.appendChild(a=d.createElement`canvas`);b=a.getContext`2d`;'A707|A7,/|Z707|Z7,/|MZAA|CR--|UR--|CR**|UR**|Id**|Nd**|La(+'.split`|`.map(x=>x.split``.map(c=>c.charCodeAt()-40)).map((x,i)=>b[b.beginPath(b.fillStyle='#'+'fccf77fff000'.substr('030306699'[i],3)),b.ellipse(...x,0,0,3*-~(i<9)),i>8?'stroke':'fill']())
```
> 5 votes

# Answer
# HTML, ~~280~~ 278 bytes

```
a{color:#FFC8C8;}b{color:#FF7F7F;font-size:6px;margin-left:-10px;}m,n,j,d{display:block;}m{margin:-15px -3px;font-size:40px;}n{margin:-35px 5px;color:#FFF;font-size:15px;}j{margin:-14px 1px;color:#000;font-size:10px;}
```

```
<a>⬮<b>⬮</b><a>⬮<b>⬮</b><m>⬤<n>● ●<j>●   ●<d>   w
```

Here is a screenshot:

Citations
> 5 votes

# Answer
# Processing, ~~388~~ ~~343~~ 319 chars/bytes

Not very elegant, but here it is. Saved bytes by making the image smaller.

```
int b=50,c=60,g=70;
noStroke();
//Face
fill(#FFCCCC);
ellipse(b,g,c,c);
//Outer ears
ellipse(40,25,15,b);
ellipse(c,25,15,b);
//Inner ears
fill(#FF9999);
ellipse(40,25,7,30);
ellipse(c,25,7,30);
//Outer eyes
fill(-1);
ellipse(40,g,10,10);
ellipse(c,g,10,10);
//Inner eyes
fill(0);
ellipse(40,g,5,5);
ellipse(c,g,5,5);
//Mouth
stroke(0);
line(b,80,b,85);
noFill();
arc(53,85,5,5,0,PI);
arc(48,85,5,5,0,PI);

```
> 4 votes

# Answer
# PostScript, ~~688~~ ~~484~~ ~~468~~ ~~439~~ 359 bytes

Golfed version:

```
<</F{closepath fill}/C{0 360 arc}/c{curveto}/s{setrgbcolor}/M{moveto}/h{7 15 M 7 25 1 25 1 15 c 1 5 7 5 7 15 c F 1 .5 .5 s 6 15 M 6 22 2 22 2 15 c 2 8 6 8 6 15 c F 1 1 1 s 4 3 2 C F 0 0 0 s 4 3 1 C F 0 -3 M 0 -5 lineto stroke 1 -5 1 180 0 arc stroke}>>begin 80 60 translate 5 5 scale .2 setlinewidth 1 .7 .7 s 0 0 10 C F gsave h grestore -1 1 scale h showpage

```

Ungolfed version:

```
% define some short-named procedures for later use
<<
  /F {closepath fill}
  /C {0 360 arc}
  /c {curveto}
  /s {setrgbcolor}
  /M {moveto}
  /h {                           % procedure for drawing one half
    7 15 M 7 25 1 25 1 15 c      % ellipse for outer ear
           1  5 7  5 7 15 c F
    1 .5 .5 s                    % dark pink
    6 15 M 6 22 2 22 2 15 c      % ellipse for inner ear
           2  8 6  8 6 15 c F
    1 1 1 s                      % white
    4 3 2 C F                    % circle for outer eye
    0 0 0 s                      % black
    4 3 1 C F                    % circle for inner eye
    0 -3 M 0 -5 lineto stroke    % line for upper mouth
    1 -5 1 180 0 arc stroke      % arc for lower mouth
  }
>> begin

80 60 translate                  % over-all shift
5 5 scale                        % over-all scale
.2 setlinewidth
1 .7 .7 s                        % light pink
0 0 10 C F                       % large circle for head
gsave h grestore                 % right half
-1 1 scale h                     % left half
showpage

```

Result:
> 4 votes

# Answer
# Lua + LÖVE/Love2D, 328 bytes

```
l=love g=l.graphics c=g.setColor e=g.ellipse a=g.arc f="fill" k="line" o="open"function l.draw()c(1,.7,.7)e(f,50,82,40,40)e(f,30,28,10,25)e(f,70,28,10,25)c(1,.4,.4)e(f,30,28,5,18)e(f,70,28,5,18)c(1,1,1)e(f,35,73,8,8)e(f,65,73,8,8)c(0,0,0)g[k](49,90,49,99)a(k,o,45,96,5,.5,2.7)a(k,o,53,96,5,.5,2.7)e(f,35,73,4,4)e(f,65,73,4,4)end

```

Try it online!
> 4 votes

# Answer
## SVG (HTML5), 415 bytes

```
<svg width=48 height=80><g fill=#fdd><circle cx=24 cy=52 r=24 /><ellipse cx=12 cy=16 rx=8 ry=16 /><ellipse cx=36 cy=16 rx=8 ry=16 /></g><g fill=#f99><ellipse cx=12 cy=16 rx=4 ry=12 /><ellipse cx=36 cy=16 rx=4 ry=12 /></g><g fill=#fff><circle cx=16 cy=44 r=6 /><circle cx=32 cy=44 r=6 /></g><circle cx=16 cy=44 r=3 /><circle cx=32 cy=44 r=3 /><path stroke=#000 fill=none d=M18,60a3,3,180,0,0,6,0v-6v6a3,3,180,0,0,6,0
```

Keeping the height below 100 to help save precious bytes, but still the longest...
> 3 votes

# Answer
# Java, ~~508~~ 472 bytes

```
import java.awt.*;v->new Frame(){Graphics2D G;Color C;void d(int...d){G.fillOval(d[0],d[1],d[2],d[3]);}{add(new Panel(){public void paint(Graphics g){G=(Graphics2D)g;G.setPaint(C.PINK);d(0,65,99,99);d(22,0,24,75);d(58,0,24,75);G.setPaint(C.MAGENTA);d(27,5,14,65);d(63,5,14,65);G.setPaint(C.WHITE);d(24,85,20,20);d(60,85,20,20);G.setPaint(C.BLACK);d(30,91,8,8);d(66,91,8,8);G.drawArc(41,124,9,11,0,-180);G.drawArc(50,124,9,11,0,-180);G.drawLine(50,119,50,130);}});show();}}

```

This is the resulting bunny:

**Explanation:**

```
import java.awt.*;              // Required imports for almost everything
v->                             // Method with empty unused parameter and no return-type
  new Frame(){                  //  Create a new Frame
    Graphics2D G;               //   Graphics2D-object on class-level
    Color C;                    //   Color variable to save bytes with static calls
    void d(int...d){            //   Create an inner method with integer-varargs as parameter
      G.fillOval(               //    Draw a circle/oval, filled with the current color:
        d[0],d[1],              //     With the first two integers as starting x,y position
        d[2],                   //     Third as width
        d[3]));}                //     And fourth as height
    {                           //   Then open an initializer-block inside the Frame-class
     add(new Panel(){           //    And add a Panel to the Frame we can draw on
       public void paint(Graphics g){
                                //     Override the Panel's paint-method
         G=(Graphics2D)g;       //      Set the Graphics2D-object with the parameter
         G.setPaint(C.PINK);    //      Set the color to pink (255,175,175)
         d(0,65,99,99);         //      Draw the head circle
         d(22,0,24,75);         //      Draw the left ear
         d(58,0,24,75);         //      Draw the right ear
         G.setPaint(C.MAGENTA); //      Change the color to magenta (255,0,255)
         d(27,5,14,65);         //      Draw the inner part of the left ear
         d(63,5,14,65);         //      Draw the inner part of the right ear
         G.setPaint(C.WHITE);   //      Change the color to white (255,255,255)
         d(24,85,20,20);        //      Draw the left eye
         d(60,85,20,20);        //      Draw the right eye
         G.setPaint(C.BLACK);   //      Change the color to black (0,0,0)
         d(30,91,8,8);          //      Draw the left pupil
         d(66,91,8,8);          //      Draw the right pupil
         G.drawArc(41,124,9,11,0,-180);
                                //      Draw the left mouth elipse
         G.drawArc(50,124,9,11,0,-180);
                                //      Draw the right mouth elipse
         G.drawLine(50,119,50,130);}});
                                //      Draw the line of the mouth
    show();}}                   //    And finally show the Frame on the screen

```
> 3 votes

# Answer
# Racket – 597 bytes

```
#!racket/gui
(require pict)(show-pict(let*([c cc-superimpose][f filled-ellipse][h hc-append][v vc-append][r rotate][p"pink"][E(c(f 85 140 #:color p)(f 50 90 #:color"maroon"))][I(c(f 60 60 #:color"white")(f 30 30 #:color"brown"))][M(dc(λ(D X Y)(define-syntax-rule(S a ...)(send D a ...))(let([P(S get-pen)][B(S get-brush)])(S set-brush(new brush%[style 'transparent]))(S set-pen(new pen%[width 5]))(S draw-arc(+ 1 X)Y 48 48(- pi)0)(S set-brush B)(S set-pen P)))50 50)])(v -40(h 20(r E .2)(r E -.2))(c(f 220 220 #:color p)(v 20(h 40 I I)(v -25(filled-rectangle 8 30 #:color"darkbrown")(h M M)))))))

```

Here's the TIO link. Note that TIO can not display the `pict`, hence why it shows an error. Feel free to use the link as a means to verify byte count and/or copy code into a local file.

---

## Screenshot from DrRacket

Yeah, I'm using Light Theme at 12am xD

## Explanation of the code

This explanation uses the ungolfed version of the program, but I will explain what I did to golf it up along the way.

On line one, we set the language to `racket/gui`. This us to create GUIs and use some pieces of Racket's canvas API (we use the `brush%` and `pen%` classes to make new styles for them). Right underneath the language statement, we import the `pict` package. This package sort of works like JavaScript's Canvas API.

```
#lang racket/gui
(require pict)

(show-pict ...)

```

We then start the program by calling `show-pict` which renders a picture to the screen.

While Racket has already made picts for fishes and files, it doesn't have a pict for an easter bunny. So let's make one! To make the eyes and the ears, we can use filled ellipses. In pict, they are defined simply as `filled-ellipse`. The function receives the following input:

```
(filled-ellipse width height #:color [fill-color])

```

Now we want to center an ellipse inside of another (the outer one for the outer ear/eyeball and the inner ellipse for the inner ear/pupil). To that, we simply use the function `cc-superimpose` (standing for "align center x, align center y, on top of another pict").

```
(let ([ear (cc-superimpose (filled-ellipse 85 140 #:color "pink")
                           (filled-ellipse 50 90 #:color "maroon"))]  ;; Inner ear
      [eye (cc-superimpose (filled-ellipse 60 60 #:color "white")
                           (filled-ellipse 30 30 #:color "brown"))])  ;; Eye pupil
  ...))

```

Now comes a trickier part: the mouth. I say it is tricky because it involves using the canvas context API to draw arcs. `pict` provides a neat little function called `dc` which allows use to access the `d`rawing `c`ontext for the canvas. It accepts three arguments: a function that draws the pict using the context, width and height. The function that it receives must also receive three arguments, but this time, they are: the drawing context and the current `x` and `y` positions for the pen and brush.

```
(dc (lambda (dc dx dy)
      ...) width height)

```

To tell the context to draw something or to configure the pen and brush, we use the `send` function to call the one of the object's methods. In our case, we set the brush to `'transparent`.

```
(send dc set-brush (new brush% [style 'transparent]))

```

Now that the basic functionality is mostly explained, let's create the mouth once and for all.

```
(let ([ear (cc-superimpose (filled-ellipse 85 140 #:color "pink")
                           (filled-ellipse 50 90 #:color "maroon"))]  ;; Inner ear
      [eye (cc-superimpose (filled-ellipse 60 60 #:color "white")
                           (filled-ellipse 30 30 #:color "brown"))]  ;; Eye pupil
      [mouth (dc (λ (dc dx dy)
                   ;; Save old pen/brush state
                   (define old-pen (send dc get-pen))
                   (define old-brush (send dc get-brush))
                   ;; Set new styles for pen/brush
                   (send dc set-brush (new brush% [style 'transparent]))
                   (send dc set-pen (new pen% [width 5]))
                   ;; Draw an arc of width/height 48 at (dx+1,dy) counter-clockwise
                   (send dc draw-arc (+ 1 dx) dy 48 48 (- pi) 0)
                   ;; Reset to default pen/brush for `dc` function
                   (send dc set-brush old-brush)
                   (send dc set-pen old-pen)) 50 50)])
  ...))

```

One thing to note is `(+ 1 dx)`. I had a rendering issue where the arc would be one pixel to the left of the nose, and this seemed to fix it. I think it might be caused from putting the arcs side-by-side using `hc-append`.

Let's add these facial features to the actual face.

```
(let ([ear (cc-superimpose (filled-ellipse 85 140 #:color "pink")
                           (filled-ellipse 50 90 #:color "maroon"))]  ;; Inner ear
      [eye (cc-superimpose (filled-ellipse 60 60 #:color "white")
                           (filled-ellipse 30 30 #:color "brown"))]  ;; Eye pupil
      [mouth (dc (λ (dc dx dy)
                    ;; Save old pen/brush state
                    (define old-pen (send dc get-pen))
                    (define old-brush (send dc get-brush))
                    ;; Set new styles for pen/brush
                    (send dc set-brush (new brush% [style 'transparent]))
                    (send dc set-pen (new pen% [width 5]))
                    ;; Draw an arc of width/height 48 at (dx+1,dy) counter-clockwise
                    (send dc draw-arc (+ 1 dx) dy 48 48 (- pi) 0)
                    ;; Reset to default pen/brush for `dc` function
                    (send dc set-brush old-brush)
                    (send dc set-pen old-pen))
                  50 50)])
  ;; Ears + Face
  (vc-append -40
             ;; Ears
             (hc-append 20
                        (rotate ear .2)
                        (rotate ear -.2))
             ;; Face
             (cc-superimpose (filled-ellipse 220 220 #:color "pink")
                             (vc-append 20
                                        ;; Eyes
                                        (hc-append 40 eye eye)
                                        (vc-append -25
                                                   ;; Nose
                                                   (filled-rectangle 8 30 #:color "darkbrown")
                                                   ;; Mouth
                                                   (hc-append mouth mouth))))))

```

The `vc-append` appends picts vertically, and `hc-append` appends picts horizontally. Both functions receive an optional spacing parameter as it's first argument. So the arcs for the mouth have no space between them, but the eyes have 40 pixels between them. To fit the nose and the mouth snuggly together, I used -25 as the spacing.

Putting the program together is as simple as placing the `let` block inside of `show-pict`.

## A cleaner more declarative way

```
#lang racket/gui
(require pict)

(define ear (cc-superimpose (filled-ellipse 85 140 #:color "pink")
                            (filled-ellipse 50 90 #:color "maroon")))

(define ears (hc-append 20 (rotate ear .2) (rotate ear -.2)))

(define eye (cc-superimpose (filled-ellipse 60 60 #:color "white")
                            (filled-ellipse 30 30 #:color "brown")))

(define eyes (hc-append 40 eye eye))

(define nose (filled-rectangle 8 30 #:color "darkbrown"))

(define mouth (dc (λ(dc dx dy)
                    (define old-pen (send dc get-pen))
                    (define old-brush (send dc get-brush))
                    (send dc set-brush (new brush% [style 'transparent]))
                    (send dc set-pen (new pen% [width 5]))
                    (send dc draw-arc (+ 1 dx) dy 48 48 (- pi) 0)
                    (send dc set-brush old-brush)
                    (send dc set-pen old-pen))
                  50 50))

(define nose+mouth (vc-append -25 nose (hc-append mouth mouth)))

(define eyes+nose+mouth (vc-append 20 eyes nose+mouth))

(define face (cc-superimpose (filled-ellipse 220 220 #:color "pink")
                             eyes+nose+mouth))

(define easter-bunny (vc-append -40 ears face))
(show-pict easter-bunny)

```

## How I golfed the code

While the `let` statement is cool, its brother `let*` is cooler. A normal `let` statement doesn't allow other variables inside of its binding block to see each other. but this isn't the case with `let*`:

```
;; Normal let - Can't use `f` in let binding
(let ([f filled-ellipse]
      [red-circle (filled-ellipse 50 50 #:color "red")])
  (cc-superimpose (f 50 50 #:color "yellow") red-circle))

;; Cooler let*
(let ([f filled-ellipse]
      [red-circle (f 50 50 #:color "red")])
  (cc-superimpose (f 50 50 #:color "yellow") red-circle))

```

Because I use `cc-superimpose`, `vc-append`, `hc-append`, etc. a lot, I used `let*` so that I could bind them to shorter names:

```
(let* ([c cc-superimpose]
       [f filled-ellipse]
       [h hc-append]
       [v vc-append]
       [r rotate]
       [p "pink"])
  ...)

```

I then proceeded to rename all variables to shorter names, ear becomes `E`, eye becomes `I`, etc. After that was done, I started to ponder what I could do with the dreaded mouth `send`s. I ended up creating a macro :)

```
(let* (...
       [M (dc (λ (D X Y)
                 ;; This macro will replace (S get-pen) with (send D get-pen)
                 (define-syntax-rule (S a ...)
                   (send D a ...))
                 (let ([P (S get-pen)] [B (S get-brush)])
                   (S set-brush (new brush% [style 'transparent]))
                   (S set-pen (new pen% [width 5]))
                   (S draw-arc (+ 1 X) Y 48 48 (- pi) 0)
                   (S set-brush B)
                   (S set-pen P)))
                50 50)])
  ...)

```

Once that was done, I deleted all unnecessary spaces.

The golfed code and the code I used in the explanation are basically identical. If you don't want to open a new window, simply remove the call to `show-pict`. Pict only displays well in DrRacket. If you try to print a pict to a console like CMD or terminal, you'd see `#<pict>` which is Racket's way of telling you "Yes the statement returned something, but I can only tell you what type of object it returned.

## Conclusion

It's 2am now as I write this conclusion, hope everyone enjoyed this little tutorial-ish explanation!

**Have an amazing week!**
> 2 votes

# Answer
# Scala, with Java AWT(Abstract Window Toolkit). 714 bytes

Port of @Kevin Cruijssen's Java answer in Scala.

---

Golfed Scala code.

```
import java.awt._;import java.awt.event._;object M extends App{new Frame{def d(g:Graphics2D,x:Int,y:Int,w:Int,h:Int)=g.fillOval(x,y,w,h);add(new Panel{override def paint(g:Graphics){val g2=g.asInstanceOf[Graphics2D];g2.setPaint(Color.PINK);d(g2,0,65,99,99);d(g2,22,0,24,75);d(g2,58,0,24,75);g2.setPaint(Color.MAGENTA);d(g2,27,5,14,65);d(g2,63,5,14,65);g2.setPaint(Color.WHITE);d(g2,24,85,20,20);d(g2,60,85,20,20);g2.setPaint(Color.BLACK);d(g2,30,91,8,8);d(g2,66,91,8,8);g2.drawArc(41,124,9,11,0,-180);g2.drawArc(50,124,9,11,0,-180);g2.drawLine(50,119,50,130);}});setSize(new Dimension(200,200));setVisible(true);addWindowListener(new WindowAdapter{override def windowClosing(e:WindowEvent):Unit=System.exit(0);})}}

```

This is the resulting bunny.

Ungolfed Scala code.

```
import java.awt._
import java.awt.event._

object ScalaMain extends App {
  new Frame {
    def d(g: Graphics2D, x: Int, y: Int, w: Int, h: Int): Unit = g.fillOval(x, y, w, h)

    add(new Panel {
      override def paint(g: Graphics): Unit = {
        val g2d = g.asInstanceOf[Graphics2D]
        g2d.setPaint(Color.PINK)
        d(g2d, 0, 65, 99, 99)
        d(g2d, 22, 0, 24, 75)
        d(g2d, 58, 0, 24, 75)
        g2d.setPaint(Color.MAGENTA)
        d(g2d, 27, 5, 14, 65)
        d(g2d, 63, 5, 14, 65)
        g2d.setPaint(Color.WHITE)
        d(g2d, 24, 85, 20, 20)
        d(g2d, 60, 85, 20, 20)
        g2d.setPaint(Color.BLACK)
        d(g2d, 30, 91, 8, 8)
        d(g2d, 66, 91, 8, 8)
        g2d.drawArc(41, 124, 9, 11, 0, -180)
        g2d.drawArc(50, 124, 9, 11, 0, -180)
        g2d.drawLine(50, 119, 50, 130)
      }
    })
    setSize(new Dimension(200, 200))
    setVisible(true)
    addWindowListener(new WindowAdapter {
      override def windowClosing(e: WindowEvent): Unit = System.exit(0)
    })
  }
}

```
> 1 votes

---
Tags: code-golf, graphical-output
---