title: Mutual Negative Quines

text:
# Question
Title: Mutual Negative Quines
This was inspired by Print a Negative of your Code and Golf a mutual quine.

---

Consider a **rectangle** of characters, that meet the following restrictions: 1. Consists solely of printable ASCII characters
2. Dimensions both greater than 1
3. Each row and each column contains at least one space.
4. Each row and each column contains at least one non-space character.

For example, the following is a valid 6x4 rectangle:

```
%n 2e
1  g 3
 &* __
 3

```

A **negative** for this rectangle is defined to be a rectangle of equal dimensions, with all spaces replaced by non-space characters, and all non-space characters replaced by spaces. A negative of the above rectangle could be:

```
  f  ^
 33 >
9  $
^ }|Q'

```

Any non-space printable ASCII character may be used to replace a space.

## Task

Your task is to write a program with rectangular source code, that outputs a valid negative to itself. The negative outputted must also be a valid program, in the same language as the original, and it must output the source of the original.

No trailing whitespace may be added or removed, except for a single trailing newline at the end of either output, which is optional.

Neither program is permitted to read the source code of either; nor may REPL environments be assumed.

## Scoring

Your score is the product of the dimensions of your code (i.e. if your source code is in a 12 by 25 rectangle, your score is 12\*15=180). Additionally, for each character used in a comment, your score increases by 2 (If you use `/* .. */` once in your code, and your code is in a 10 by 10 rectangle, your score would be 10\*10+8\*2=116).

The lowest score wins.

If there is a tie, the submission with the least number of spaces in the program (either the original or the negative, whichever has fewer spaces) wins.

If there still remains a tie, the earlier answer shall win.

There is a bonus of **-52%**, if combining the original and the negative together produces a normal quine. For example:

```
Original   Negative   Combined
 A A       B B        BABA
A A         B B       ABAB

```

# Answer
> 17 votes
# CJam, (~~51 49 47 46 45~~ 42 x 2) * 48% = 40.32

```
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~
                                         R

```

Running the above code gives this output:

```
                                         R
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~

```

running which, prints back the original source.

*The source and the output are simply swapped lines.*

**Now comes the magic.**

Overlapping the source and the output results into the following code:

```
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~R
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~R

```

which is a perfect quine!

Try them online here

---

**How it works**

All the printing logic is in the first line itself which handles all three cases explained later.

```
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~
{                                     }_~   "Copy this code block and execute the copy";
 ]                                          "Wrap everything before it in array";
  )                                         "Pop the last element out of it";
   "_~"+                                    "Append string '_~' to the copied code block";
        S41*                                "Create a string of 41 spaces";
            'R+                             "Append character R to it";
               @,                           "Rotate the array to top and get its length";
                 [{   }{   }{     }]=~      "Get the corresponding element from this"
                                            "array and execute it";

```

The array in the last line above is the array which has code blocks corresponding to all three cases.

**Case 1**

```
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~
                                         R

```

In this case, the length of remaining stack was 0 as when the block was executed, it only had the copy of the block itself, which was initially popped out in the third step above. So we take the index `0` out of the last array and execute it:

```
 {N@S}          "Note that at this point, the stack is something like:"
                "[[<code block that was copied> '_ '~ ] <41 spaces and R string>]";
  N             "Add newline to stack";
   @            "Rotate the code block to top of stack";
    S           "Put a trailing space which negates the original R";

```

In this case, the second line is a no-op as far as printing the output is concerned.

**Case 2**

```
                                         R
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~

```

In this case, the stack already contained an empty string, so when the copied code block was executed, it had 2 elements - an empty string and the code block itself. So we take the index `1` out of the last array and execute it:

```
{SN@}            "Note at this point, the stack is same as in case 1";
 SN              "Push space and newline to stack";
   @             "Rotate last three elements to bring the 41 spaces and R string to top";

```

**Case 3**

```
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~R
{])"_~"+S41*'R+@,[{N@S}{SN@}{W=N]_}]=~}_~R

```

In this case, the stack has 6 elements. So after popping the last code block, remaining array length is 5. We take the index `5` out of the array and execute it. *(Note that in a array of `3` elements, index `5` is index `5%3 = 2`)*

```
{W=N]_}          "Note at this point, the stack is same as in case 1";
 W=              "Take the last character out of the 41 spaces and R string, i.e. R";
   N]            "Add a new line to stack and wrap the stack in an array";
     _           "Copy the array to get back the source of Case 3 itself";

```

# Answer
> 28 votes
## Python, 97x2 + 2 = 196

Not a great solution to start off, but at least it works (I think).

```
c='o=1-%d;print("%%97s\\n%%97s"%%("#","c=%%r;exec(c%%%%%%d)\\40"%%(c,o),"#")[o:][:2])';exec(c%1)
                                                                                #

```

Output:

```
                                                                                #
c='o=1-%d;print("%%97s\\n%%97s"%%("#","c=%%r;exec(c%%%%%%d)\\40"%%(c,o),"#")[o:][:2])';exec(c%0)

```

# Answer
> 27 votes
# CJam, (~~58~~ ~~56~~ ~~54~~ ~~48~~ 46 x 2) * 48% = 44.16

```
{`"_~"+{_,94\m2/S*a_+\*
                       N/23f/Wf%N*}_`'"#)!*}_~

```

which prints

```
                       {`"_~"+{_,94\m2/S*a_+\*
N/23f/Wf%N*}_`'"#)!*}_~

```

The non-space characters in each line remain the same between the two mutual quines.

But now the really sweet part:

```
{`"_~"+{_,94\m2/S*a_+\*{`"_~"+{_,94\m2/S*a_+\*
N/23f/Wf%N*}_`'"#)!*}_~N/23f/Wf%N*}_`'"#)!*}_~

```

is a quine! :)

Test it here.

## How it works

I recommend you read the explanation on my other submission first, as it explains the basics of quining in CJam in general.

This one is a bit trickier. For the mutual quine, as in the other case, I modify the string representation of the block by adding spaces before or after each line, and swapping a 0 with a 2, so that the resulting program puts the spaces at the opposite end.

Note that the spaces don't affect the mutual quines at all. In the first one, they are in a block, which isn't really used, and in the second they are around the entire code.

To obtain a regular quine when combining both, we need to find a way to avoid doing all that modification. Notice that the structure of the whitespace and code means that by combining both, we insert the entirety of one quine into the other. So if we put the entire modification code in a block, we can run that block depending on its actual contents.

So now I've got this block... for the mutual quines, it only contains the code I actually want to run. For the combined quine, it also contains the entire quine again, in a random position, which doesn't make any sense... but since it's a block, it's not run automatically. So we can determine whether to modify the string based on the contents of that block. That's what `_`'"#)!` is for. It duplicates the block, converts it to a string, searches for the character `"` (which, in the mutual quines, only appears *outside* the block) - the search returns `-1` if the character isn't found and a positive integer otherwise -, increments the result and negates it logically. So if a `"` was found this yields `0` otherwise it yields `1`. Now we just do `*`, which executes the block once, if the result was 1 and not at all otherwise.

Finally, this is how the modifying code works:

```
_,94\m2/S*a_+\*N/23f/Wf%N*
_,                         "Duplicate the quine string and get its length.";
  94\m                     "Subtract from 94.";
      2/                   "Divide by two.";
        S*                 "Create a string with that many spaces. This will be
                            an empty string for the first mutual quine, and contain
                            23 spaces for the second mutual quine.";
          a_+              "Create an array that contains this string twice.";
             \*            "Join the two copies together with the quine string.";
               N/          "Split into lines.";
                 23f/      "Split each line into halves (23 bytes each).";
                     Wf%   "Reverse the two halves of each line.";
                        N* "Join with a newline.";

```

# Claiming the Bounty, (12 x 10) * 48% = 57.6

Turns out that this code can be split over more lines very easily with some modifications. We add 2 characters, to get 48 in a row, which we can then conveniently divide by 8, so that we have 8 lines with 6 characters of code and 6 spaces. To do that we also need to change a few numbers, and to rearrange an operator or two, so they aren't split over both lines. That gives us a working version with size **12 x 8**... one off the requirement. So we just add two lines that don't do anything (push a 1, pop a 1, push a 1, pop a 1...), so get to **12 x 10**:

```
{`"_~"
      +{129X
$,m2/S
      *a_+\*
N/6f/1
      ;1;1;1
;1;1;1
      ;Wf%N*
}_`'"#
      )!*}_~

```

As the previous one this produces

```
      {`"_~"
+{129X
      $,m2/S
*a_+\*
      N/6f/1
;1;1;1
      ;1;1;1
;Wf%N*
      }_`'"#
)!*}_~

```

(Side note: there is no need to keep alternating left and right on the intermediate lines, only the position of the first and last line are important. Left and right can be chosen arbitrarily for all other lines.)

And through pure coincidence, the full quine also still works:

```
{`"_~"{`"_~"
+{129X+{129X
$,m2/S$,m2/S
*a_+\**a_+\*
N/6f/1N/6f/1
;1;1;1;1;1;1
;1;1;1;1;1;1
;Wf%N*;Wf%N*
}_`'"#}_`'"#
)!*}_~)!*}_~

```

(I say coincidence, because the part that takes care of not executing the inner code now gets weirdly interspersed with the other quine, but it still happens to work out fine.)

That being said, I could have just added 44 lines of `1;` to my original submission to fulfil the bounty requirement, but `12 x 10` looks a lot neater. ;)

**Edit:** Haha, when I said "pure coincidence" I couldn't have been more spot on. I looked into how the final quine now actually works, and it's absolutely ridiculous. There are three nested blocks (4 actually, but the innermost is irrelevant). The only important part of the innermost of those 3 blocks is that it contains a `"` (and not the one that it did in the original submission, but the very `'"` that is used at the end to check for this same character). So the basic structure of the quine is:

```
{`"_~"{`"_~"+{___'"___}_`'"#)!*}_~)!*}_~

```

Let's dissect that:

```
{`"_~"                               }_~ "The standard CJam quine.";
      {`"_~"+                  }_~       "Another CJam quine. Provided it doesn't do
                                          anything in the rest of that block, this
                                          will leave this inner block as a string on
                                          the stack.";
                                  )      "Slice the last character off the string.";
                                   !     "Negate... this yields 0.";
                                    *    "Repeat the string zero times.";

```

So this does indeed do some funny magic, but because the inner block leaves a single string on the stack, `)!*` happens to turn that into an empty string. The only condition is that the stuff in the inner block after `+` doesn't do anything else to the stack, so let's look at that:

```
             {___'"___}                  "Push a block which happens to contain
                                          quotes.";
                       _`'"#)!*          "This is from the original code and just
                                          removes the block if it does contain
                                          quotes.";

```

# Answer
> 10 votes
# CJam, ~~42~~ ~~37~~ 33 x 2 = 66

```
{`As_W%er"_~"+S 33*F'Lt1{\}*N\}_~
               L

```

which prints

```
               L
{`As_W%er"_~"+S 33*F'Lt0{\}*N\}_~

```

(The lines are swapped, and a `1` turns into a `0`.)

Test it here.

## How it works

First, you should understand the basic CJam quine:

```
{"_~"}_~

```

The braces simply define a block of code, like a function, that isn't immediately executed. If an unexecuted block remains on the stack, it's source code (including braces) is printed. `_` duplicates the block, and `~` executes the second copy. The block itself simply pushes the string containing `_~`. So this code, leaves the stack in the following state:

```
Stack: [{"_~"} "_~"]

```

The block and the string are simply printed back-to-back at the end of the program, which makes this a quine.

The beauty of this is that we can do whatever we want in the block, and it remains a quine, because each piece of code will automatically be printed in the block contents. We can also modify the block, by obtaining it's string representation with ``` (which is just a string of the block with braces).

Now let's look at this solution. Notice that either part of the mutual quine contains of the quine-like block with `_~`, and an `L`. The `L` pushes an empty string onto the stack, which doesn't contribute to the output. So here is what the block does:

```
`                             "Convert block to its string representation.";
 As                           "Push 10 and convert to string.";
   _W%                        "Duplicate and reverse, to get another string 01.";
      er                      "Swap 0s and 1s in the block string.";
        "_~"+                 "Append _~.";
             S 33*            "Push a string with 33 spaces.";
                  F'Lt        "Set the character at index 15 to L.";
                      1{ }*   "Repeat this block once.";
                        \     "Swap the code string and the space string.";
                           N\ "Push a newline and move it between the two lines.";

```

So this will do the quine part, but exchange a 1 for a 0, and it will also prepend another line with an `L`, where the code above has a space. The catch is that the order of those two lines is determined by the swapping inside `{ }*`. And because the outer part of the mutual quine has the `0` in front of it replaced by a `1`, it never executes this swap, and hence produces the original order again.

# Answer
> 6 votes
# CJam, 27 × 2 = 54

```
{ ` " _ ~ " + N - ) 2 * ' '
 > @ t s G B + / N * } _ ~

```

Output:

```
 { ` " _ ~ " + N - ) 2 * '
' > @ t s G B + / N * } _ ~

```

`'A'B>` compares the characters A and B. `' '\n >` returns 1 because 32\>10 and `' \n' >` returns 0 because the two spaces are equal.

# Answer
> 3 votes
# CJam, ~~30~~ 29 x 2 = 58

```
{"_~"SN]_,4=S28*'R+\{N@}*}_~
                            R

```

Outputs:

```
                            R
{"_~"SN]_,4=S28*'R+\{N@}*}_~

```

which outputs the original source.

This is based on the same principal as my other solution.

Try it online here

# Answer
> 3 votes
# Klein, 2\*96 = 192

```
 \                                                                                1
< (!.:!.?!|84*:999*+2+$<::::::]]]]]]]77*55+<)!.:!.?!>(84*2+@*77]]]]]]]::::::<$*77:*48+55+2*48 <"

```

Try it online!

```
< 84*2+55+84*:77*$<::::::]]]]]]]77*@+2*48(>!?.!:.!)<+55*77]]]]]]]::::::<$+2+*999:*48|!?.!:.!( <"
 1                                                                                1

```

Try it online!

---
Tags: code-golf, quine, source-layout, whitespace
---


title: Check for Wonky numbers

text:
# Question
Title: Check for Wonky numbers
# Task :

Wonky numbers are 3-or-more digit numbers that meet one or more of the following criteria:

* Any digit followed by all zeros: `100`, `70000`
* Same digit throughout the entirety of the number : `1111`, `777777777`
* The digits are in consecutive ascending order : `1234`, `1234567890` (for 0 see below)
* The digits are in consecutive descending order : `4321`, `9876543210`
* The number is a palindromic number : `1221`, `123321`

Ascending and descending order mean no repeated digits in their so `122` is not ascending in this case, you may also not skip digits `1245` is not Wonky because 3 is missing. For both ascending and descending numbers 0 will come last so order is : `1234567890` and `9876543210` for ascending and descending respectively. Numbers can be given in any order, do not assume that it may be in some specific order : `1234`, `987`, `76842` are all valid numbers.

# I / O :

Your input will always be a number (positive) in the following range : $$99 \< Z \< 1,000,000,000$$

Check if the number is a Wonky number.

You may not take input as anything but a number unless your language is simply incapable of handling that, in which case take input in any reasonable format (per language)

You may output any truthy value (for wonky numbers) and any falsy value (for non wonky numbers).

# Examples :

```
Input : Output

100 : true
12344321 : true
77777777777 : true
132 : false
321 : true
122 : false
987789 : true
98765 : true
120000 : false
100001 : true
786 : false
890 : true

```

# Extra Credit :

Check if number is not a Wonky number, but one of next `x` numbers is a wonky number, where x is in range of 1 (inclusive) to 10 (exclusive).

This is code-golf, so shortest code in bytes wins.

# Answer
# JavaScript (Node.js), ~~103~~ ~~88~~ 82 bytes

```
n=>"1234567890|9876543210".match(n)|/^(.0+|(.?)(.?)(.?)(.?).?\5\4\3\2\1)$/.test(n)

```

Try it online!

* -15 bytes thanks to Dom Hastings.
* -6 bytes thanks to Kevin Cruikssen.

# Original :

# JavaScript (Node.js), 103 bytes

```
n=>RegExp(n).test("1234567890|9876543210")|/^(\d0+|(\d)\1+|(\d?)(\d?)(\d?)(\d?)\d?\6\5\4\3\2)$/.test(n)

```

Try it online!

# Changes :

* changed all `\d` to `.` because input is guaranteed to be a number.
* instead of `regex(n).test` switch to match
* Removed the check for same digits (because palindromes check that)
> 4 votes

# Answer
# Retina, 43 bytes

```
$
¶$^$`¶10*#0
Y`#`d
\b(.+)¶(.+¶)?.*\1|¶0*.¶

```

Try it online! Link includes test cases. Explanation:

```
$
¶$^$`¶10*#0
Y`#`d

```

Append the reverse of the input and build up the string `01234567890`.

```
\b(.+)¶(.+¶)?.*\1|¶0*.¶

```

Check whether either the string or its reverse is a substring of each other (i.e. palindromic) or the created string, or whether the reverse is all zeros except the last digit.
> 3 votes

# Answer
# 05AB1E, ~~19~~ ~~18~~ ~~16~~ 15 bytes

```
RT‹žhĆIÂ‚åàIÂQM

```

Try it online or verify all test cases.

**Explanation:**

```
RT‹      # Rule 1:
R        #  Reverse the (implicit) input
 T‹      #  Check if it's smaller than 10
žhĆIÂ‚åà # Rules 3 & 4:
žh       #  Push builtin 0123456789
  Ć      #  Enclose, append its own head: 01234567890
   I     #  Push the input-integer again
    Â    #  Bifurcate it (short for Duplicate & Reverse copy)
     ‚   #  Pair them together
      å  #  Check for both whether it's a substring of 01234567890
       à #  Pop and push the maximum to check if either was truthy
IÂQ      # Rules 2 & 5:
I        #  Push the input-integer yet again
 Â       #  Bifurcate it (short for Duplicate & Reverse copy)
  Q      #  Check if both are equal, thus it's a palindrome
         #  (if all digits are the same it's also a palindrome, so no need to
         #  check rule 2 separately)
M        # Push the largest number on the stack to check if any were truthy
         # (which is output implicitly as result)

```
> 2 votes

# Answer
# Vyxal, 18 bytes

```
Ḣ0J≈?¯ȧ:19∩⊍¬?Ḃ⁼Wa

```

Try it Online!

`0` can still go frick itself.

## Explained

```
Ḣ0J≈?¯ȧ:19∩⊍¬?Ḃ⁼Wa
Ḣ0J≈               # Test 1: Is the input[1:] all 0's? (not why I hate 0 btw)
    ?¯ȧ:19∩⊍¬      # Test 2: Is the differences between all numbers either 1 or 9? (this is why I hate 0)
             ?Ḃ⁼   # Test 3: Is the input a palindrome?
                Wa # Did any of the tests pass? For some reason the -G flag doesn't work here to save 2 bytes. /shrug

```
> 1 votes

# Answer
**Broken because I didn't notice the “0 comes last” rule. I'll try to fix it.**

# Jelly, ~~20~~ ~~19~~ 12 bytes

```
DµIṠEoŒḂ*ḊẸ$

```

Try it online!
> 1 votes

# Answer
# Charcoal, 27 bytes

```
Ｎθ≔⁺⭆χι⁰η∨‹⮌θχ⊙⟦η⮌η⮌Ｉθ⟧№ιＩθ

```

Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. `-` for wonky, nothing if not. Would have saved 4 bytes if it wasn't necessary to take input as a number. Explanation:

```
Ｎθ

```

Input the number.

```
≔⁺⭆χι⁰η

```

Get the string `01234567890`.

```
∨‹⮌θχ

```

Output `-` if the reverse of the number is less than 10, or...

```
⊙⟦η⮌η⮌Ｉθ⟧№ιＩθ

```

... any of the strings `01234567890`, `09876543210` or the reverse of the number as a string contain the number as a string.
> 0 votes

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


title: Holy Hole In A Donut, Batman!

text:
# Question
Title: Holy Hole In A Donut, Batman!
Some characters are more holy than others. Using as few unholy letters as possible, display the statement above.

**Challenge**

Write a full program to print `Holy Hole In A Donut, Batman!` to STDOUT or closest alternative. If you can compress the input to reduce your score, go wild :)

**Input**

None

**Output**

```
Holy Hole In A Donut, Batman!

```

**Rules**

1. This is a , and lowest score wins
2. The desired output can be read from a file, but that should then be counted towards your total.
3. Trailing newlines are fine in the output
4. Standard loopholes and T&C's apply

**Scoring**

Your score is your byte count, plus some modifiers:

1. Using holy characters `0469abdegopqrADOPQR@#` count as 2 points each
2. Using extra holy characters `8B%$&` are 1 point (no penalty)
3. Using unholy characters `12357cfhijklmnstuvwxyzCEFGHIJKLMNSTUVWXYZ!"^*()[]{}-=_+|\/?,.<>:;'~` carries a heavier penalty and count as 10 points per character.
4. Space, tab and newlines are 1 point (no penalty).
5. Any other characters not listed are 10 points.

\*On my keyboard the key '$' and '&' are extra holy. Where font variations cause a character to become unholy, defer to the list above

The unmodified string `Holy Hole In A Donut, Batman!` scores **172**
Ruby: `puts "Holy Hole In A Donut, Batman!"` scores **225**

**Score checker**

@DeadChex has kindly put together a scoring script

Please do let me know if I need to clarify anything. I will update the list of characters if necessary - I've only included the obvious keys at this point. The idea is simple enough though - holes in characters are good.

# Answer
# Vyxal, 21 bytes, score 141

```
`¤∞ ∵⁽ In A DoṖ₃, Ṙ↳!

```

Try it Online!

A compressed string.

Despite various attempts, I haven't found anything better than this :P

The score is 108 if you count the Unicode holy characters (`¤∞ṖṘ`) as holy.
> 4 votes

# Answer
# Unary, 109,700,689,123,880,793,751,483,665,383,781,675,730,387,604,429,204,978,112,223,950,724,553,435,005,885,707,908,578,678,850,861,879,910,670,154,149,244,112,969,597,673,955,700,447,838,276,456,862,280,889,656,901,703,351,515,963,083,297,978,322,224,548,248,606,910,210,200,102,145,647,654,537,444,488,063,149,647,173,155,335,488,014,867,140,385,453,547,997,132,573,700,942,612,360 points

Calculated through bc which is the highest precision calculator that I know of

Code:

```
54850344561940396875741832691890837865193802214602489056111975362276717502942853954289339425430939955335077074622056484798836977850223919138228431140444828450851675757981541648989161112274124303455105100051072823827268722244031574823586577667744007433570192726773998566286850471306180 zeros

```

4.5x10259 Yottabytes

Well this ain't winning
> 36 votes

# Answer
# CJam, ~~154~~ ~~153~~ ~~148~~ 143 points

```
"
$&	 &
&$&%

 %		B8B$
	 $8
%8%8&	 	$&
 &
8
8 $B$ 	$&B8$$$B
"0$0$&$f#8b90b' f+

```

Try it online!

### How it works

```
"
$&  &
&$&%

 %      B8B$
     $8
%8%8&       $&
 &
8
8 $B$     $&B8$$$B
"

      e# Push a string of encoded base 8 digits.

0$0$  e# Push two copies of that string.
&     e# Intersect the copies to remove duplicates.
$     e# Sort the resulting string.
      e# Pushes "\t\n $%&8Bb".

f#    e# Replace each char of the original string by its index in "\t\n $%&8Bb".
      e# Pushes 213502515354211124007673102360146465020351251616237320357633371,
      e# to be understood as an array of single-digit integers.

8b90b e# Convert from base 8 digits to base 90 digits.

' f+  e# Add each base 90 digit to the code point of the space character.
      e# Pushes the desired string.

```
> 30 votes

# Answer
# BrainF\***, 3140 points

Behold, the language of **unholiness**!

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

```
> 23 votes

# Answer
## Malbolge, ~~1874~~ 1239

```
(=<`$9]~6;Y327U5v-Qr*Np-&J$#jFg}Cdd@>`O<t]KZp6Wm3US0QPfe**(:9I^$o"`CkW{>Txv:99'`6oo2m1YXiggAed>P&N^?!\IlY3ExTBARc10/_nJ8IG(X&Dfec@~av<]\r8Zon4UTj0Rmfe+Lha`&HFED!BX]VzZ=Rv9UNrLKo2Hk

```

I'm pretty sure this can be golfed more. Will try running this for longer. I want to get sub 1000...

I've found shorter length programs (down to 175 I think it was), but the score was higher... Sad. Currently on a 179 length (180 is current) with 4 points less, not sure if editing for that short little bit.
> 19 votes

# Answer
# sed, ~~169~~ 166 points

```
s&$&\to#y \to#e I% A Do%u8, Ba8ma%!&
y&\t#8%&Hltn&

```

I've counted each `\t` as a single point, since it can be replaced with an actual tabulator.

Try it online!

### How it works

* Both commands use the extra holy `&` as delimiter.
* The first command replace the end of the (empty) pattern space with the string `\to#y \to#e I% A Do%u8, Ba8ma%!`.
* The second command replaces `\t`, `#`, `8` and `%` with the unholy `H`, `l`, `t` and `n`, respectively.

Because of the penalty for unholy characters, transliteration adds 12 bytes but saves 20 points.
> 17 votes

# Answer
# PHP, ~~175~~ ~~168~~ ~~163~~ ~~160~~ 159 points

I did what I could to reduce the score as much as possible.
With the help of @Dennis, the score was reduced by 5 points.

```
echo BeeABBeeoBodBaBdOdPQBBgDQgDdp^"\n\n\t8b\n\n\t\nb&\nb b  \n%%nb%%%\n%\nQ";

```

Yeah, not exactly short...

Replace the `\n` and `\t` with a UNIX-style newline and a tab, respectivelly.

To execute it, simply run it with the -r switch (not counted on the score)

---

Here's a shorter one that is only 256 points:

```
<?=$a=Hol,"y {$a}e In A Donut, Batman!";

```
> 14 votes

# Answer
# HTML, 169 points

```
Holy Hole In A Donut&#44 Batman!
```

That's the only character that had a decimal numeric entity with only holed numbers.

(In the HTML specification, entities must be followed by a semicolon but it still works in major browsers without one.)
> 10 votes

# Answer
# JavaScript, 1337 Points

```
for(B="&$8$$&8$%&8&&%8$&%8&$8$$&8$%&8$$8$&%8&&8$$$8$&%8%8$&%8$%8$$&8$$$8&%&8&%$8$&%8$8%8&%$8$$%8%8$$$8$&%8".split("8"),$="",i=0;i<B.length;i++)$+=toDec(s[i]);alert($.split("P").join(" ").toLowerCase().replace(/\b(\s\w|^\w)/g,function($){return $.toUpperCase()})+"!");

```

This takes advantage of the face that there are 26 letters in the alphabet, and 26 characters can be represented by three digits of ternary (base-3) numbers 0, 1, and 2, here represented by `%$&` respectively.

Split that enormous string up at each '8' (I use it as a delimiter because it's extra-holy, spaces would have worked too), convert to a base-3 integer by replacement (`0` becomes `%`, `1` becomes `$`, `2` becomes `&`), convert that to decimal (`%%&` = `2`), and then put the string back together. Add 65 (the `char` value of the letter `A`) and convert each integer to a character, A-Z. Lastly, convert to title-case, and add in punctuation.

An easier-to-read unminified version:

```
B ="&$8$$&8$%&8&&%8$&%8&$8$$&8$%&8$$8$&%8&&8$$$8$&%8%8$&%8$%8$$&8$$$8&%&8&%$8$&%8$8%8&%$8$$%8%8$$$8$&%8".split('8')
    $=''
    for (i = 0;i<B.length;i++) {
        $ += toDec(s[i])
    };
    alert($.split('P').join(' ').toLowerCase().replace(/\b(\s\w|^\w)/g, function (t) { return t.toUpperCase(); })+ "!");

```

**Sure it's goofy.** But it was a fun idea to play around with anyhow!
> 10 votes

# Answer
## Whitespace, 438 points

If you see nothing, then it's because of whitespace!

Reading about "*4. Space, tab and newlines are 1 point (no penalty).*" brings me to my choice of language:

* S = Space
* T = Tab
* L = Line feed

\[Start of code\]

```
S S S T S S T   S S S L
T   L
S S S S S T T   S T T   T   T   L
T   L
S S S S S T T   S T T   S S L
T   L
S S S S S T T   T   T   S S T   L
T   L
S S S S S S T   S S S S S L
T   L
S S S S S T S S T   S S S L
T   L
S S S S S T T   S T T   T   T   L
T   L
S S S S S T T   S T T   S S L
T   L
S S S S S T T   S S T   S T L
T   L
S S S S S S T   S S S S S L
T   L
S S S S S T S S T   S S T   L
T   L
S S S S S T T   S T T   T   S L
T   L
S S S S S S T   S S S S S L
T   L
S S S S S T S S S S S T L
T   L
S S S S S S T   S S S S S L
T   L
S S S S S T S S S T S S L
T   L
S S S S S T T   S T T   T   T   L
T   L
S S S S S T T   S T T   T   S L
T   L
S S S S S T T   T   S T S T L
T   L
S S S S S T T   T   S T S S L
T   L
S S S S S S T   S T T   S S L
T   L
S S S S S S T   S S S S S L
T   L
S S S S S T S S S S T   S L
T   L
S S S S S T T   S S S S T   L
T   L
S S S S S T T   T   S T S S L
T   L
S S S S S T T   S T T   S T L
T   L
S S S S S T T   S S S S T   L
T   L
S S S S S T T   S T T   T   S L
T   L
S S S S S S T   S S S S T   L
T   L
S S L
L
L

```

\[End of code\]
> 8 votes

# Answer
# Batch, 197 points

```
echo Holy Hole In A Donut, Batman!

```

`c` and `h` are the only two extra characters that aren't holy - and since batch doesn't require quotes round strings, I miss out the 20 point penalty there.
> 7 votes

# Answer
# Headsecks, ~~333~~ 470

I converted my BF program to Headsecks using as many Extra Holy characters as possible. Much holier than BF.

Since vertical tabs apparently cost 10, switched to `#`.

Note: Probably still a better score than if I hadn't used loops.

```
#&#######8B o8#$#&###8B    o8BB$###$#&###8B o8$#&####8B    o8BB$BBBB&#8BB o8$#&###8B  o8BB$###$#######$##&###8B    o8#$BBBB&#8BB o8B$B&###8B  o8$#&#8BBBBB  o8#$&#8BB o8B$#&##8B   o8$BB&#8BB o8$&###8B    o8BBB$#$BBBBBBB$#$&BB8###  o8##$############$B&#8BB o8$&##8BBB    o8##$##&###8B    o8#$#######$############$BBBBBBBBBBBBB$#&#8BBBBB  o8$

```
> 7 votes

# Answer
# Z80 assembler, ~~539~~ 523 points

```
ld hl,Q
L: ld a,(hl)
or a
ret z
call 0A2h
inc hl
jr L
Q: db "Holy Hole In A Donut, Batman!",0

```

Note that this is intended to run on a MSX computer, whose BIOS routine CHPUT, located at address 00A2h, prints the character passed in the accumulator without modifying any register.

(How could the score be calculated by using the assembled binary, by the way?) :-P
> 6 votes

# Answer
# Insomnia, 168 points

```
  doe
@opp@e p@ pp
@d
dr$%p$ opp@ p@rop@@%  @oe@@
do@ %@pr$%
@ r$
%
po
@
@dp
@@ep@  d
@% %@d
@@% p@
d
@

```

Only managed to do 1 point better than HTML solution.
> 6 votes

# Answer
# Pyth, 182 points

```
"Holy Hole In A Donut, Batman!

```

It's not my strongest language. I'm open to suggestions...
> 5 votes

# Answer
# Pyth, 352 points

```
jkmCid2c::"B88B888 BB8BBBB BB8BB88 BBBB88B B88888 B88B888 BB8BBBB BB8BB88 BB88B8B B88888 B88B88B BB8BBB8 B88888 B88888B B88888 B888B88 BB8BBBB BB8BBB8 BBB8B8B BBB8B88 B8BB88 B88888 B8888B8 BB8888B BBB8B88 BB8BB8B BB8888B BB8BBB8 B8888B"\8\0\B\1d

```

I tried to be smart and encode the string as extra holy characters. That did not work too well...
> 3 votes

# Answer
# SMBF, 232 points

represents a literal null byte `\x00`, which is unholy.

```
<[.<]␀!namtaB ,tunoD A nI eloH yloH

```
> 2 votes

# Answer
# Jolf, noncompeting

### 84 points

Try it here!

```
»Ho§ Ho€ In A D©, BΆn!

```

Uncompressing a compressed string.
> 2 votes

# Answer
# Golunar, 1713

Sure, it's not that competitive, but it scores better than my BF answer. Code is obtained by taking the length of the code in Unary as a number.

```
17674921849995820305790270238143323861912297173117627579717678879378201073932744615660131563027031190590108979867232158537472346711601276443457666612884962806277404746795044800422000866416680881699125205492286893675575004572084572619659104159027555358269065090420400745692716750939076

```
> 1 votes

# Answer
# ferNANDo, 467 points

```
8 B
B 8 B B 8 B B B
B 8 8 B 8 8 8 8
B 8 8 B 8 8 B B
B 8 8 8 8 B B 8
B B 8 B B B B B
B 8 B B 8 B B B
B 8 8 B 8 8 8 8
B 8 8 B 8 8 B B
B 8 8 B B 8 B 8
B B 8 B B B B B
B 8 B B 8 B B 8
B 8 8 B 8 8 8 B
B B 8 B B B B B
B 8 B B B B B 8
B B 8 B B B B B
B 8 B B B 8 B B
B 8 8 B 8 8 8 8
B 8 8 B 8 8 8 B
B 8 8 8 B 8 B 8
B 8 8 8 B 8 B B
B B 8 B 8 8 B B
B B 8 B B B B B
B 8 B B B B 8 B
B 8 8 B B B B 8
B 8 8 8 B 8 B B
B 8 8 B 8 8 B 8
B 8 8 B B B B 8
B 8 8 B 8 8 8 B
B B 8 B B B B 8

```

Try it online!
> 1 votes

# Answer
# Forth, 193 points

```
." Holy Hole In A Donut, Batman!

```

**Try it online**

This also works with the same score:

```
.( Holy Hole In A Donut, Batman!

```
> 1 votes

# Answer
# 05AB1E, 28 bytes (246 points/182 points)

```
‘¨®¥Ê€†€…‘" Donut, "‘ßƒ‘'!J™

```

Try it online!

even worse (base-5 with holy characters) - 256 bytes:

```
"BB8$$&B8&&$B$$$8B&$8B%8%$$$&8%&88$$&8%$BB$8B$B$&B8%&%B&8&$8$8&&88""8B%$&"4ÝJ‡5ö36B2ÝJ… ,!‡™

```

or (less fun, super trivial):

```
"Holy Hole In A Donut, Batman!

```

for 182 points.
> 1 votes

# Answer
# W.Y.A.L.H.E.I.N., ~~3103 score, 2784 bytes~~ 2886 score, 2558 bytes

```
14192091
121
8888888888888888888888888888888888888888888888888888888888888888888888888.%8888888888888888888888888888888888888888888888888888.%888888888888888888888888888888888888888888888888888888888888888888888888.%88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%888888888888888888888888888.%88888888888.%8888888888888888888888888888888888888888888888888888888888888888888888888888888888.%888888888888888888888888888888888888888888888888888888888888888888888888888888888.%88888888888888888.%88.%8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%888888888888888888888888888888888888888888888888888888888888888888888888.%88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%8888888888888888888888888888888888888888.%888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%88888888888888.%8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%8888888888888888888888888888888888.%88888888888888888888888.%8888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%8888888888888888888888.%888888888.%888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%888888888888888888888888.%88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888.%

```

Try it online!

Used with a brute forcer.

After several days, I have golfed this.
> 0 votes

# Answer
# \>\<\>, 201 Points

```
#o<$g0d"oy Hole In A Donut, Batman!"og0b

```

Try it online!

Slightly better than just printing. I imagine clever modulo stuff might be able to shave off a few more points.
> 0 votes

# Answer
## Ook! - 15699 points

I'll see your Brainfuck, and I raise you this :

```
Ook! Ook! Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook. Ook! Ook! Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook. Ook! Ook! Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook! Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook. Ook! Ook! Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook! Ook! Ook. Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook? Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook. Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook. Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook. Ook! Ook? Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook.

```

No orangutan were harm in the redaction of this program.
> -2 votes

---
Tags: code-challenge, kolmogorov-complexity, restricted-source
---


# Question
Title: Create all arrays of non-negative integers of length N with sum of parts equal to T
Create all arrays of non-negative integers of length N where the array sum is equal to T. The output order of arrays does not matter.

Possible solutions are e.g.

```
N = 5, T = 2:
1 1 0 0 0
1 0 1 0 0
1 0 0 1 0
1 0 0 0 1
0 1 1 0 0
0 1 0 1 0
0 1 0 0 1
0 0 1 1 0
0 0 1 0 1
0 0 0 1 1
2 0 0 0 0
0 2 0 0 0
0 0 2 0 0
0 0 0 2 0
0 0 0 0 2

```

```
N = 4, T = 5
0 4 1 0
1 1 2 1
2 0 3 0
0 3 1 1
...

```

Erroneous outputs would be:

```
N = 3, T = 1
1 1 1
3 0 0

N = 4, T = 2
0 1 1
0 2 0 0 0 0

```

Edit: I sadly do not understand most of these very short code golf languages (but admire the creativity of them). To understand what you mean, main stream languages or explanations are encouraged. (How about Java, C# or C++?)

# Answer
# JavaScript (V8),  ~~71 69~~  67 bytes

*Saved 1 byte thanks to @l4m2*

Expects `(n, t)` and prints all possible arrays.

```
f=(n,t,a=[],v=0)=>n?f(n-1,t,[...a,v])|t&&f(n,t-1,a,v+1):t||print(a)

```

Try it online!

### Commented

```
f = (             // f is a recursive function taking:
  n,              //   n   = expected number of entries
  t,              //   t   = expected sum
  a = [],         //   a[] = current output array
  v = 0           //   v   = current value to be added to a[]
) =>              //
  n ?             // if there's at least one more entry to add:
    f(            //   do a first recursive call:
      n - 1,      //     decrement n
      t,          //     pass t unchanged
      [...a, v]   //     append v to a[]
    ) | t         //   end of recursive call; yield t
    &&            //   if the above is truthy ...
    f(            //   ... do a 2nd recursive call:
      n,          //     pass n unchanged
      t - 1,      //     decrement t
      a,          //     pass a[] unchanged
      v + 1       //     increment v
    )             //   end of recursive call
  :               // else:
    t || print(a) //   print a[] if t = 0

```
> 11 votes

# Answer
# Jelly (fork), 5 bytes

```
ŻṗSƘ⁸

```

Can't Try it online! as this is a fork of Jelly with some newly added commands. `Ƙ` was added 3 days ago.

Essentially a shortened version of my other answer

## How it works

```
ŻṗSƘ⁸ - Main link. Takes T on the left and N on the right
Ż     - Yield [0, 1, ..., T]
 ṗ    - N'th Cartesian power
    ⁸ - Yield T
   Ƙ  - Keep those for which the result of the following equals T:
  S   -   Sum

```
> 11 votes

# Answer
# Haskell, ~~44~~ 42 bytes

```
1#t=[[t]]
n#t=[t-x:y|x<-[0..t],y<-(n-1)#x]

```

Try it online!

Takes `n` and `t` as input, returns the list of all the arrays of non-negative integers of length `n` that sum to `t`.

The implementation relies on the following recursive idea: such an array can always be obtained as the concatenation of the first element \\$\texttt{x}\in\\{0,1,\ldots,\texttt{t}\\}\\$ and an array `y` of length \\$\texttt{n}-1\\$ with sum equal to \\$\texttt{t}-\texttt{x}\\$.

**EDIT:** because of syntactic restrictions, it's actually more efficient (in terms of bytes) to pick \\$\texttt{t}-\texttt{x}\\$ as the first element, and recurse on \\$(\texttt{n}-1,\texttt{x})\\$.
> 10 votes

# Answer
# Wolfram Language (Mathematica), 28 bytes

```
1~Table~#~FrobeniusSolve~#2&

```

Try it online!

```
FrobeniusSolve[     (* find all nonnegative integer vectors x s.t.: *)
 1~Table~#,         (*  {1,...(N 1s)...,1}.x *)
 #2]                (*  =T *)

```
> 9 votes

# Answer
# Ruby, ~~56~~ 53 bytes

```
->n,t{(a=*0..t).product(*[a]*~-n){|a|a.sum==t&&p(a)}}

```

Try it online!

Ironically, this is shorter than directly using a built-in method - that's the result of long names:

### Ruby, ~~58~~ 57 bytes

```
->n,t{[*0..t].repeated_permutation(n){|a|a.sum==t&&p(a)}}

```

Try it online!

Thanks to Dingus for -3 and -1 bytes, respectively.
> 8 votes

# Answer
# Haskell, ~~46~~ 42 bytes

```
n#t=[x|x<-mapM(\u->[0..t])[1..n],sum x==t]

```

Try it online!

* saved 4 thanks to @Delfad0r
> 7 votes

# Answer
# , 26 bytes

```
((=1&#.)#])]>@,@{@#<@i.@>:

```

Try it online!

Similar to the other answers, this just generates all possible Cartesian products and filters them.
> 7 votes

# Answer
# C++ (gcc), ~~164~~ \\$\cdots\\$ ~~153~~ 151 bytes

Saved 3 bytes thanks to ceilingcat!!!
Added 7 bytes to fix a bug kindly pointed out by Neil.
Saved 2 bytes thanks to Neil!!!

```
#import<bits/stdc++.h>
auto f(int n, int t){std::vector<int>r;for(int i=pow(++t,n),v,j;i--;v||(r.push_back(i),0))for(v=t-1,j=i;j;j/=t)v-=j%t;return r;}

```

Try it online!

You asked for a C++ answer so here's one! :D

Inputs positive integers \\$n\\$ and \\$t\\$ and returns a `std::vector` holding all of the \\$n\\$-digit base\\$\_{t+1}\\$ integers who's \\$n\\$ base\\$\_{t+1}\\$ digits all sum to \\$t\\$.
> 6 votes

# Answer
# Zsh, ~~86~~ 57 bytes

```
for p (`eval echo ${(l:$2*8::+{0..$1}:)}`)<<<$p>>$[$p-$1]
```

Attempt This Online!

Outputs to a file called `0`.

* `${(l:$2*8::{0..$1},:)}`: repeat the string `"{0..$1}"`, \\$ n \\$ (`$2`) times
* `eval`: expand the string `+{0..$1}+{0..$1}+{0..$1}`, which produces the \\$ n\\$-permutations of the range \\$ 0, 1, 2, ... T \\$, separated by `+`
* ``echo``: print those permutations, space-separated
* `for p ()`: for each permutation, `$p`:
    + `<<<$p`: print `$p`
    + `$[$p-$1]`: evaluate `$p` as a numeric string, which sums the elements of the permutation (because each element was separated by `+`), and subtract the first input from it
    + `>>` append to the file `$[$p-$1]`; if they're equal, this difference will be zero, and it will be written to the file `0`.
> 5 votes

# Answer
# APL (Dyalog Extended), 10 bytes

```
∪↑¯⍸¨,⍳⎕⍴⎕

```

Try it online!

Filtering is not so convenient in APL, so here is a solution that uses each input only once. A full program, which takes N then K from stdin, and prints a matrix. The final  can be omitted if duplicate rows are allowed.

### How it works

```
∪↑¯⍸¨,⍳⎕⍴⎕  ⍝ First input (right): N, Second input (left): T
       ⎕⍴⎕  ⍝ T copies of N
     ,⍳     ⍝ Cartesian product of T copies of 1..N
  ¯⍸¨       ⍝ For each vector V from above,
            ⍝ creates another vector W where each index i appears W[i] times in V
            ⍝ e.g. [3 3 4] → [0 0 2 1]
 ↑          ⍝ Mix (promote a vector of vectors to a matrix), padding with zeros
∪           ⍝ Take unique rows

```
> 5 votes

# Answer
# , 62 bytes

```
function(n,t)(m=expand.grid(rep(list(0:t),n)))[rowSums(m)==t,]

```

Try it online!

Slightly shorter (and more efficient) to use `expand.grid` rather than `combn`.

Generates the cartesian product of `[0..t]` with itself `n` times, then filters for those with row sums equal to `t`.

# , 63 bytes

```
function(n,t)(m=unique(t(combn(rep(0:t,n),n))))[rowSums(m)==t,]

```

Try it online!
> 4 votes

# Answer
# K (ngn/k), 16 bytes

```
{(y=+/)#+!x#1+y}

```

Try it online!

```
{(y=+/)#+!x#1+y} / a function with arguments x (N) and y (T)
           #     / create a list
          x      / of x copies
            1+y  / of 1+y
         !       / make an odometer from this list (ranged permutations)
        +        / transpose the result
       #         / keep only those lists
 (  +/)          / that have sum which
  y=             / equals y

```
> 4 votes

# Answer
# Wolfram Language (Mathematica), 40 bytes

```
Select[Range[0,s=#2]~Tuples~#,Tr@#==s&]&

```

Try it online!

-2 bytes from @att
> 3 votes

# Answer
# Python 3, 87 bytes

```
lambda n,t:[k for k in product(range(t+1),repeat=n)if sum(k)==t]
from itertools import*

```

Try it online!

# Explanation

First use `range` to get all integers between `0`and `t` and use `itertools.product` to find the array of cartesian product of itself repeated `n` times (so that would include all arrays of length n where each element is between 0 and t). Among all such arrays, we only pick the ones with sum equal to `t`.
> 3 votes

# Answer
# Jelly, 7 bytes

```
ŻṗS=¥Ƈ⁸

```

Try it online!

## How it works

```
ŻṗS=¥Ƈ⁸ - Main link. Takes T on the left and N on the right
Ż       - Yield [0, 1, ..., T]
 ṗ      - N'th Cartesian power
    ¥Ƈ  - Keep those for while the following is true:
  S     -   Sum
   =  ⁸ -   Equals T

```
> 3 votes

# Answer
# Retina, 50 bytes

```
G`$
.+
*
"$+"+%Lv$`_*$
$`,$&
(_*),
$.1,
Lm$`,$
$%`

```

Try it online! No test suite because this program uses history. Explanation:

```
G`$

```

Delete `N`. (Don't worry, we can get it back later via `$+`.)

```
.+
*

```

Convert `T` to unary.

```
"$+"+`

```

Repeat `N` times...

```
%`

```

... for each line...

```
Lv$`_*$

```

... for all the suffixes of the last entry, i.e. the numbers from it down to zero...

```
$`,$&

```

... split the last entry into two values that sum to it.

```
(_*),
$.1,

```

Convert all the values to decimal, except for the last value on each line.

```
Lm$`,$
$%`

```

List only those lines that end with a zero entry, keeping only the prefix of the line. This is required because we split `T` `N` times, resulting in a list of length `N+1`, so to fix this we only keep those entries that end with zero, dropping that zero from the final output.
> 3 votes

# Answer
# Japt, 20 bytes

```
pVÄ osU ù'0 m¬f_x ¥V

```

Try it

```
Input : U = n , V = t

    o    - numbers from 0 to..
pVÄ      - (n raised to t+1)excluded
     sU  - to base n

ù'0      - pad to left with '0' to max length element
m¬       - split each
f_       - keep
  x ¥V   - sum == t

```
> 3 votes

# Answer
# Charcoal, 36 bytes

```
Ｎθ⊞υ⟦Ｎ⟧Ｆυ¿⁼Ｌιθ⟦⪫ι,⟧«≔⊟ιηＦ⊕η⊞υ⁺ι⟦κ⁻ηκ

```

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

```
Ｎθ

```

Input `N`.

```
⊞υ⟦Ｎ⟧Ｆυ

```

Start a breadth first search with an array `[T]`.

```
¿⁼Ｌιθ

```

If the current array has the correct number of entries, ...

```
⟦⪫ι,⟧

```

... then join it with commas and print it on its own line, ...

```
«

```

... otherwise:

```
≔⊟ιη

```

Remove the last entry from the array.

```
Ｆ⊕η

```

For all values from `0` to that entry inclusive...

```
⊞υ⁺ι⟦κ⁻ηκ

```

... concatenate the value and the difference from the original last entry to the remainder of the array, and save that for a future search pass.
> 3 votes

# Answer
# MATL, 13 bytes

```
Q:qZ^t!s1G=Y)

```

First input is `T` and second input is `N`

Try it out at MATL Online

**Explanation**

```
        % Implicitly grab the first input, T
Q:q     % Add 1 to T, create array from 1...(T+1), subtract 1 to yield 0...T
Z^      % Perform the Cartesian product with the second input
t       % Duplicate the result
!s      % Sum across the rows
1G      % Explicitly grab the first input again, T
=       % Compare the sum of each row to T
Y)      % Use this a logical index to grab only those rows where the sum == T
        % Implicitly display the result

```
> 3 votes

# Answer
# 05AB1E, 6 bytes

```
Ý¹ãʒOQ

```

Try it online!

```
Ý¹ãʒOQ  # full program
   ʒ    # all elements of...
  ã     # all combinations of...
Ý       # [0, 1, 2, ...,
        # ..., implicit input...
Ý       # ]...
  ã     # repeated...
 ¹      # first input...
  ã     # times...
   ʒ    # where...
    O   # sum of all elements in...
        # (implicit) current element in list...
     Q  # is equal to...
        # implicit input
        # implicit output

```
> 2 votes

# Answer
# C (clang), ~~133 124~~ 112 bytes

```
p,i,j,r;f(n,t){for(p=pow(++t,n);i=j=--p;){for(r=t-1;j;j/=t)r-=j%t;for(j=n;j--;i/=t)r||printf("%d%c",i%t,9+!j);}}

```

Try it online!

* Saved 12 thanks to @ceilingcat
* iterates over all numbers up to (t+1)^n , convert to base t+1 then prints only if digits sums to t.
* prints elements separated by tab.
> 2 votes

# Answer
# Functional Bash*, 160 bytes

* This is bash with the additional constraint that you can't mutate variables.

```
d=$(eval echo $(printf "{0..$1}%.0s+" $(seq $1))|tr \  \\n)
paste <(sed s/$/0/<<<$d|bc|awk "{print match(\$0,/^$2$/)?1:0}") <(sed s/+/\ /g<<<$d)|grep ^1|cut -f2

```

Try it online!

Could be golfed more, but sort of a fun idea.
> 2 votes

# Answer
# Japt, 17 bytes

```
ÆVòÃc àU f_x ¥VÃâ

```

Try it online!

Uses a significantly different strategy from the other Japt answer. The order of the outputs is weird, but all of them seem to be there.

Explanation:

```
ÆVòÃc àU f_x ¥VÃâ
 Vò                  # Create the array [0...T]
Æ  Ã                 # Create N copies of that array
    c                # Flatten them all into a single array
      àU             # Create all combinations of elements of that array that have length N
         f_    Ã     # Keep only the ones where:
           x         #  The sum of the numbers
             ¥V      #  Is equal to T
                â    # Remove any duplicates

```
> 2 votes

# Answer
# JavaScript (V8), 60 bytes

```
f=(n,t,a,g=i=>f(n,t-i,[a,i])|i&&g(i-1))=>--n?g(t):print(t+a)

```

Try it online!

```
f=(n,t,
  a, // previous numbers, initialed as undefined (empty)
  g= // helper function to loop current number from t to 0
    i=> // `i` is current number
      f(n,t-i,[a,i])| // try to use current number and `t-i` remined
      i&&g(i-1) // loop until i = 0
)=>
  --n? // Is more than 1 number required?
    g(t): // Try current number, loop from `t`
    print(t+a) // We found an partition with t and previous numbers

```
> 2 votes

# Answer
# JavaScript (V8), ~~76~~ 74 bytes

```
f=(n,t,z=t)=>n<2?[[t]]:f(n-1,t-z).map(a=>[z,...a]).concat(z?f(n,t,z-1):[])

```

Try it online!
> 1 votes

# Answer
# Python 3, 74 bytes

```
f=lambda N,T:N and[j+[i]for i in range(T+1)for j in f(N-1,T-i)]or[[]]*-~-T

```

Try it online!

Shortened version of this

```
def f(N,T):
  if N == 0:
    if T == 0: return [[]]
    else: return []
  else:
    l = []
    for i in range(T+1):   # possible last elements
      for j in f(N-1,T-i): # solutions for rest of elements
        l.append(j+[i])
    return l

```
> 1 votes

# Answer
# Haskell 73 (88) bytes

This solution is longer than both existing Haskell solutions. But it's fun, and that's what code golf is about.

```
1#t=[[t]]
n#1=(n-1)#1>>=(\p->[0:p,1:(0<$p)])
n#t=zipWith(+)<$>n#1<*>n#(t-1)

```

Here's how it works:

* Bottom case: If, given any particular *N*, you could solve the problem for *T=1* and any other *Ta*, you could solve it for *Ta+1* as well. You would only have to find every possible pairing of a *Ta* array and a *T=1* array and add up both arrays element-wise. So by induction if you could solve the problem for *T=1*, you could solve it for any *T*.
* Middle case: Now you only have an infinite number of problems remaining: solving the task for any *N*, given *T=1*. But if you *had* a solution for *T=1* and any *Na*, you could get a solution for *T=1* and *Na+1* by simply putting a zero in front of every existing array and adding one more trivial array (in this case, many times). So actually you only have to solve the task for *T=1* and *N=1*.
* Top case: Now that's trivial.

To get down to this enormous reduction of being almost longer than all existing Haskell solutions combined, this solution not only uses almost every trick in my book, but it also exploits two holes of the task description:

1. The task doesn't state that an array can only appear once
2. No restrictions are given for *N* and *T*, so I didn't make it work for non-trivial *T=0*.

To get rid of both exploits, more bytes are necessary. But yet another level of beauty emerges, both because the solution is now actually longer than all existing Haskell solutions combined, and because the middle case gains some symmetry.

```
1#t=[[t]]
n#0=[0<$[1..n]]
(n+1)#1=[1:p|p<-n#0]++[0:p|p<-n#1]
n#(t+1)=zipWith(+)<$>n#1<*>n#t

```
> 1 votes

# Answer
# Macaulay2, 36 bytes

```
n->t->exponents(sum gens(ZZ[n:x]))^t

```

Try it online!

This is based on the fact that, by the multinomial theorem, the multivariate polynomial $$(x\_1 + \cdots + x\_n)^t = \sum\_{t\_1+\cdots+t\_n=t} \binom{t}{t\_1,\dots,t\_n} x\_1^{t\_1} \cdots x\_n^{t\_n} \in ℤ\[x\_1,\dots,x\_n\]$$ involves all the monomials of degree *t* in *n* variables when fully expanded. As the exponents of each monomial sum to *t*, taking all the exponent vectors of this polynomial gives the solution.

For example, with *n*=2, *t*=4, the polynomial $$(x\_1 + x\_2)^4 = x\_1^4 + 4 x\_1^3 x\_2 + 6 x\_1^2 x\_2^2 + 4 x\_1 x\_2^3 + x\_2^4$$ has exponents (4,0), (3,1), (2,2), (1,3), (0,4).

---

Edit: As a side note, there is even a builtin for this: `compositions` (12 bytes). Try it online!
> 1 votes

# Answer
# TI-Basic, ~~56~~ 52 bytes

```
Prompt N,T
T+1→U
For(I,1,U^N
seq(UfPart(int(I/U^J)/U),J,0,N-1
If T=sum(Ans
Disp Ans
End

```

-4 bytes thanks to MarcMush.

Output is displayed as lists separated by newlines.
> 1 votes

# Answer
# Ruby, ~~54~~ 53 bytes

```
f=->n,t,*a{n>1?0.upto(t){|x|f[n-1,t-x,*a,x]}:p(a<<t)}

```

Try it online!

I don't know if the initial "f=" is considered part of the function. If I could move that to the header, this would be 51 bytes. I've always considered it a part of the function (because of recursion), but I think I've seen answers where it was removed.
> 0 votes

# Answer
# Burlesque, 17 bytes

```
Js1rzjCBf{++g1==}

```

Try it online!

```
J        # Duplicate T on stack
s1       # Store T as 1
rz       # Get range from [0..T]
jCB      # Combinations (w/repl) of length N of that range
f{       # Filter for
 ++g1==  # Sum == T
}

```
> 0 votes

---
Tags: code-golf, array
---


title: Compatible strings

text:
# Question
Title: Compatible strings
When studying numerology, you can say two words (strings consisting entirely of letters) are compatible if they produce the same number under the following operation (let's use the string `hello` as an example):

* Map each letter to a number according to the following, ignoring case:

```
1 2 3 4 5 6 7 8 9
a b c d e f g h i
j k l m n o p q r
s t u v w x y z

```

The number at the top of the column a letter is in is its mapped value (e.g. `a -> 1`, `x -> 6`)

`hello -> [8, 5, 3, 3, 6]`
* Take the sum of these numbers. `hello -> 25`
* Repeatedly take the digital sum until it reaches a single digit (i.e. it's digital root). `hello -> 2+5 = 7`

For example, `hello` and `world` are not compatible (they yield `7` and `9` respectively), whereas `coding` and `sandbox` are (both `7`).

---

You are to write a program which will take two strings as input and output two distinct consistent values which indicate whether the strings are compatible or not

* The inputs will only consist of letters (`ABCDEFGHIJKLMNOPQRSTUVWXYZ` or `abcdefghijklmnopqrstuvwxyz`) in a consistent case
* You may choose the case of the inputs, so long as it is consistent across inputs and runs
* You may take input as a delimited string (e.g. space separated), so long as the delimiter is non-empty and consists of entirely non-letter characters of your chosen case (i.e. if you input in uppercase, the delimiter may contain lowercase letters, but not uppercase letters)
* Otherwise, you may input and output in any convenient method

This is so the shortest code in bytes wins.

## Test cases

```
a, b -> out

"hello", "world" -> 0
"raahyjc", "mvj" -> 0
"mpqtjmjd", "bwkhrh" -> 0
"VZZLCZTH", "DOJEIV" -> 0
"coding", "sandbox" -> 1
"vhw", "wl" -> 1
"HMCZQZZRC", "SIQYOBXK" -> 1
"a", "j" -> 1

```

These two programs can generate more test cases

# Answer
> 12 votes
# Jelly, 6 bytes

```
O’§%9E

```

Try it online! All Tests.

We take input in capital letters. The key insight here is to note (ref. en.wikipedia.org/wiki/Digital\_root that the digital root of \\$n\>0\\$ is \\$n\mod 9\\$ except if \\$n\\$ is a multiple of 9, at which case it is 9. However, we only care if the digital roots are equal, so we can treat the digital root as \\$n\mod 9\\$ in all cases.

```
O’§%9E
O       # Character values A→65,...
 ’      # minus 1, A→64...
  §     # take the sum of each word
   %9   # modulo 9 (∑{A...} = ∑{1...})
     E  # are the two words' sums equal?

```

# Answer
> 5 votes
# K (oK), ~~10~~ 9 bytes

```
=/9!+/'3+

```

Try it online!

Another port of fireflame241's answer.

# Answer
> 4 votes
# 05AB1E, ~~12~~ 11 bytes

Takes input as lists of lists of characters.

-1 byte thanks to Kevin Cruijssen!

```
ÇÌ9%>ΔO€S}Ë

```

Try it online!

**Commented:**

```
€Ç             # convert both words to codepoint lists  a->97, b->98, ...
  Ì            # add 2 to each number                   a->99, b->100, ...
   9%          # modulo 9                               a->0, b->1, ...
     >         # increment                              a->1, b->2, ...
      Δ   }    # execute until the reult doesn't change:
       O       #   sum each list
        €S     #   split the results into lists of digits
           Ë   # are both lists equal?

```

---

A port of fireflame's excellent Jelly answer comes in at 6 bytes as well (provided by Kevin):

```
Ç<O9%Ë

```

Try it online!

# Answer
> 4 votes
# Husk, ~~11~~ 8 bytes

-7 bytes after looking at fireflame241's answer
-3 bytes thanks to Dominic van Essen

```
Ëo%9ṁo←c

```

Try it online!

Needs the input a list of uppercase words.

```
Ëo%9ṁo←c
    ṁ     Map each word and sum the results
       c  Get integer value of character
     o←   And decrement
 ȯ%9      Take that modulo 9
Ë         Check if they're equal

```

# Answer
> 4 votes
# Wolfram Language (Mathematica), ~~32~~ 27 bytes

```
9∣(#-#2&@@FromDigits/@#)&

```

Try it online!

Takes a list containing two strings.

Inspired by Neil's Charcoal solution: `FromDigits` still recognizes `a`=10, `b`=11, etc., even if those digits are not present in the base (by default, it interprets its input base 10).

# Answer
> 3 votes
# , 15 bytes

Based on fireflame241's Jelly answer.

```
=&(9|1#.3+3&u:)

```

Try it online!

### Original approach: , 29 bytes

*-2 after reading ovs' answer: `(x-97)|9 = (x+2)|9`*

```
=&(1(,.&.":@#.^:_)1+9|2+3&u:)

```

Try it online!

```
=&(1(,.&.":@#.^:_)1+9|2+3&u:)
f&(            g            ) call g on both arguments, then call f
                        3&u:  convert string to code points
                      2+      'a' -> 99, 'b' -> 100 …
                    9|        mod 9
                  1+          plus 1
   1(  f     )^:_             execute 1 f (list of digits)
                                until the result does not change
           @#.                sum digits and
       &.":                   convert the sum to a string and
     ,.                       itemize the characters
       &.":                   convert the characters back to digits
=&                            are the digital roots equal?

```

# Answer
> 3 votes
# Retina 0.8.2, ~~31~~ 30 bytes

```
+T`_l`dl
.
$*
1{9}|(1*)¶\1

^$

```

Try it online! Takes input on separate lines, but link includes header which lowercases the test suite and splits on `,` for convenience. Explanation:

```
+T`_l`dl

```

Retina 0.8.2 doesn't have `Y`, but fortunately we can just repeatedly transliterate 9 digits at a time, shuffling the letters back 9 places in the alphabet.

```
.
$*

```

Convert all of the digits to unary.

```
1{9}|(1*)¶\1

```

Take the difference modulo 9.

```
^$

```

Check that the result is zero.

# Answer
> 3 votes
# Python 2, ~~61~~ \\$\cdots\\$ ~~53~~ 51 bytes

Saved a byte thanks to ovs!!!
Saved 2 bytes thanks to Dingus!!!

```
lambda t:len({sum(ord(c)+3for c in w)%9for w in t})

```

Try it online!

Inputs a tuple of two strings in lowercase and returns \\$1\\$ if they are compatible or \\$2\\$ otherwise.

# Answer
> 3 votes
# Perl 5 `-MList::Util=sum -p`, 61 bytes

```
y/a-z/1-91-91-8/;s|\d+|sum$&=~/./g|ge while/\d\d/;$_=/(.) \1/

```

Try it online!

# Answer
> 2 votes
# Python 3, ~~203~~ 145 bytes

-58 bytes thanks to @caird coinheringaahing

```
def f(a):
 x,y=[sum((ord(i)-97)%9+1for i in z)for z in a]
 g=lambda t:sum(int(i)for i in str(t))
 while x>9:x=g(x)
 while y>9:y=g(y)
 return x==y

```

Try it online!

# Answer
> 2 votes
# Retina, 31 bytes

```
Y`l_`1-9
{`\d
*
)`_+
$.&
(.) \1

```

Try it online!

A direct implementation of the given algorithm. Outputs 0/1 indicating incompatible/compatible taking the argument in lower case.

### Explanation

```
Y`l_`1-9

```

Transliterate cyclically the sets `a-z_` to `1-9`. Here, the underscore is not a real character but a dummy, not that it particularly matters. To cyclically transliterate we extend both sequences infinitely, then each time we encounter a character in the input in the first set we output the corresponding character in the same location in the second set. This behaviour requires the dummy character to map to 9 after `z` is mapped to `8`, as otherwise the second occurrence of each character will be off by one, the third occurrence off by two, etc.

```
{`\d
*
)`_+

```

Here we loop until a fixed point over these two stages, indicated by `{` and `)`. The first stage converts each individual digit to a corresponding number of `_` characters, while the second converts each chain of `_` characters to a number equal to the length of the chain. This reaches a fixed point naturally only at single digit numbers.

```
(.) \1

```

Count if the remaining digits are the same, so the total is zero if they are not the same and one if they are.

# Answer
> 2 votes
# Charcoal, ~~13~~ 10 bytes

```
¬﹪⁻⍘Ｓχ⍘Ｓχ⁹

```

Try it online! Link is to verbose version of code. Takes input in lower case. Outputs a Charcoal boolean, i.e. `-` for compatible, nothing if not. Edit: Saved 3 bytes via inspiration from @att's Mathematica solution, which only seems fair. Explanation:

```
    Ｓ       First input string
   ⍘ χ      Interpret as "base 10"
  ⁻         Subtract
      ⍘Ｓχ   Second input string as "base 10"
 ﹪       ⁹  Reduced modulo 9
¬           Equals zero?
            Implicitly print

```

Like Mathematica, Charcoal interprets interprets `a=10`, `b=11` ... `z=35` even in bases which don't actually go up that high. Obviously it also interprets `aa=110` which has a digital root of 2 etc.

# Answer
> 2 votes
# Ruby 2.7, ~~89~~ \\$\cdots\\$ ~~55~~ ~~52~~ 41 bytes

*Saved a whooping 34 bytes, thanks to fireflame241's answer!*
*Saved extra 11 bytes, thanks to Dingus!*

```
->w{!w.map{|s|s.bytes.sum{_1-6}%9}.uniq!}

```

Try it online!

This outputs with the boolean values swapped!
In Ruby 2.7, we can use `_1` in place of `|c|c` to save 2 bytes.

# Answer
> 2 votes
# Scala, 27 bytes

Uses fireflame241's approach.

```
_.map(_.map(3+).sum%9).size

```

Try it online!

Accepts input as a `Set` of lowercase strings. Returns 2 if inputs are not compatible, 1 if they are. I'll probably go to hell for my abuse of the rules here.

# Answer
> 2 votes
# Haskell, 44 bytes

```
a#b=o a-o b
o s=sum[fromEnum c-1|c<-s]`mod`9

```

Try it online!

# Answer
> 2 votes
# Java 8, 50 bytes

```
a->b->a.map(v->v-1).sum()%9==b.map(v->v-1).sum()%9

```

Inputs in uppercase as character-Streams.

Port of *@fireflame241*'s Jelly answer, so make sure to upvote him!

Try it online.

**Explanation:**

```
a->b->                    // Method with two IntStream parameters & boolean return-type
  a.map(v->               //  Map over the characters of the first input:
           v-1)           //   Decrease each value by 1
   .sum()                 //  Then sum them all together
         %9               //  And take modulo-9 on that
  ==b.map(v->v-1).sum()%9 //  Do the same for the second input,
                          //  and check if they're equal to one another

```

# Answer
> 2 votes
# Vyxal `a`, 7 bytes

```
C‹v∑9%≈

```

Another port of fireflame241's Jelly solution. Takes input as newline-separated strings. Try it Online!

```
C‹v∑9%≈
C          Convert the input from a list of strings to a list of lists of their codepoints
 ‹         Decrement every number
  v∑       Sum each sublist
    9%     Mod 9 both sums
      ≈    Check if both sums are equal

```

# Answer
> 1 votes
# Wolfram Language (Mathematica), 66 bytes

```
SameQ@@(Tr@*IntegerDigits~FixedPoint~Tr@#&/@LetterNumber@#~Mod~9)&

```

Try it online!

thanks @att

# Answer
> 1 votes
# JavaScript (ES6),  ~~80 79 65~~  63 bytes

*Saved 14 bytes by using @fireflame241's insight*
*Saved 2 more bytes thanks to @Neil*

Expects `(a)(b)`. Returns a Boolean value.

```
a=>b=>(g=s=>[...s].map(c=>t+=parseInt(c,36),t=0)&&t%9)(a)==g(b)

```

Try it online!

# Answer
> 1 votes
# C (gcc), 67 bytes

Takes two lowercase strings and returns `0` if they match, non-zero otherwise. Uses the method from @fireflame241's answer.

```
i;g(char*s){for(i=0;*s;i+=(2+*s++)%9+1);s=i%9;}f(s,t){s=g(s)-g(t);}

```

Try it online!

# Answer
> 1 votes
# Burlesque, 18 bytes

```
WDm{{**-.}ms9.%}sm

```

Try it online!

```
WD     # Split into words
m{     # Map over words
  {**  # To int
   -.  # Decrement
  }ms  # Map sum
  9.%  # Modulo 9
}
sm     # Are the same

```

Using Fireflame241's solution.

# Burlesque, 36 bytes

```
WDm{{**2.-9.%+.}ms{XX++}{ln1!=}w!}sm

```

Try it online!

Full solution. Saving a byte using `2.-` rather than `65.-` having looked at some other answers. Otherwise much the same as other answers.

```
wd          # Split into words
m{          # For each word
  {
   **       # ord(a)
   2.+9.%+. # ((x+2)%9)+1
  }ms       # Map each letter then sum result
  {
   XX       # XXplode into digits
   ++       # Sum digits
  }
  {ln       # Number of digits
   1!=      # Not equal 1
  }w!       # While
 }
 sm        # Are all the same

```

# Answer
> 1 votes
# CJam, 14 bytes

```
S%{:i:(:+9%}/=

```

Try it online!

First attempt at CJam. Using Fireflame241's solution.

```
S%  # Split on spaces
{
 :i # Convert each to int
 :( # Decrement each
 :+ # Sum list
 9% # Modulo 9
}/  # For each word (push to stack)
=   # Are equal

```

# Answer
> 1 votes
# TI-Basic, 92 bytes

```
Prompt Str1,Str2
"BCDEFGHIJKLMNOPQRSTUVWXYZ→Str3
"fPart(1/9sum(1+seq(9fPart(inString(Str3,sub(Ans,I,1))/9),I,1,length(Ans→u
Str1
u→S
Str2
u=S

```

Output is stored in `Ans` and displayed. Outputs `0` for incompatible numbers and `1` for compatible ones.

---
Tags: code-golf, string, decision-problem
---


title: Pascal's Column Sums

text:
# Question
Title: Pascal's Column Sums
Most everyone here is familiar with Pascal's Triangle. It's formed by successive rows, where each element is the sum of its two upper-left and upper-right neighbors. Here are the first `5` rows (borrowed from Generate Pascal's triangle):

```
    1
   1 1
  1 2 1
 1 3 3 1
1 4 6 4 1

```

We're going to take Pascal's Triangle and perform some sums on it (hah-ha). For a given input `n`, output the columnar sum of the first `n` rows of Pascal's Triangle. For example, for input `5`, the output would be formed by

```
            1
          1   1
        1   2   1
      1   3   3   1
[+] 1   4   6   4   1
----------------------
    1 1 5 4 9 4 5 1 1

```

So the output would be `[1, 1, 5, 4, 9, 4, 5, 1, 1]`.

Note that you don't necessarily need to generate Pascal's Triangle to calculate the summation - that's up to your implementation if it's shorter to do so or not.

## Input

A single positive integer `n` with `n >= 1` in any convenient format.

## Output

The resulting array/list of the column-wise summation of the first `n` rows of Pascal's triangle, as outlined above. Again, in any suitable format.

## Rules

* Leading or trailing newlines or whitespace are all optional, so long as the characters themselves line up correctly.
* Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
* If possible, please include a link to an online testing environment so other people can try out your code!
* Standard loopholes are forbidden.
* This is so all usual golfing rules apply, and the shortest code (in bytes) wins.

### Examples

```
[input]
[output]

1
[1]

2
[1, 1, 1]

3
[1, 1, 3, 1, 1]

5
[1, 1, 5, 4, 9, 4, 5, 1, 1]

11
[1, 1, 11, 10, 54, 44, 155, 111, 286, 175, 351, 175, 286, 111, 155, 44, 54, 10, 11, 1, 1]

```

# Answer
> 8 votes
# MATL, 16 bytes

```
tZv=Gq:"t5BZ+]vs

```

Try it online!

### Explanation

This repeatedly applies convolution to generate the rows. For example, for input `n=5` we start with the first row

```
0 0 0 0 1 0 0 0 0

```

Convolving with `[1 0 1]` gives

```
0 0 0 1 0 1 0 0 0

```

Repeating the operation gives

```
0 0 1 0 2 0 1 0 0

```

then

```
0 1 0 3 0 3 0 1 0

```

etc. Concatenating these arrays vertically and computing the sum of each column gives the result.

```
t       % Input n implictly. Duplicate
Zv      % Symmetric range. Gives [1 2 3 4 5 4 3 2 1] for input 5
=       % Equal to (element-wise). Gives [0 0 0 0 1 0 0 0 0]. This is the first row
Gq:     % Push [1 2 ... n-1]
"       % For each. This executes the following code n-1 times
  t     %   Duplicate
  5B    %   Push 5 in binary, that is, [1 0 1]
  Z+    %   Convolution keeping size
]       % End
v       % Concatenate all results vertically
s       % Sum. Display implicitly.

```

# Answer
> 5 votes
## CJam, ~~32~~ ~~25~~ 24 bytes

*Thanks to Luis Mendo for saving 1 byte.*

```
{(_0a*1+\{_(2$+.+}*]:.+}

```

Try it online!

### Explanation

```
(       e# Decrement input N.
_0a*1+  e# Create a list of N-1 zeros and a 1. This is the top row with
        e# the required indentation.
\{      e# Run this block N-1 times.
  _     e#   Duplicate the last row.
  (     e#   Pull off a leading zero, shifting the row left.
  2$+   e#   Copy the full row and prepend that zero, shifting the row right.
  .+    e#   Element-wise addition, which results in the next row.
}*
]       e# Wrap all rows in a list.
:.+     e# Add up the columns by reducing element-wise addition over the rows.

```

# Answer
> 5 votes
# Octave, ~~84~~ ~~67~~ 45 bytes

*22 bytes saved thanks to Neil!*

```
@(n)sum(spdiags(flip(tril(flip(pascal(n))))))

```

Try it online!

### Explanation

The `pascal` function gives a matrix that contains the values in the Pascal triangle:

```
>> pascal(5)
ans =
     1     1     1     1     1
     1     2     3     4     5
     1     3     6    10    15
     1     4    10    20    35
     1     5    15    35    70

```

To extract the desired values we flip vertically (`flip`), keep the lower triangular part (`tril` ), and flip again. This gives

```
ans =
   1   1   1   1   1
   1   2   3   4   0
   1   3   6   0   0
   1   4   0   0   0
   1   0   0   0   0

```

`spdiags` then extracts the diagonals as columns

```
ans =
   1   1   1   1   1   0   0   0   0
   0   0   4   3   2   1   0   0   0
   0   0   0   0   6   3   1   0   0
   0   0   0   0   0   0   4   1   0
   0   0   0   0   0   0   0   0   1

```

and `sum` computes the sum of each column, which gives the result.

# Answer
> 5 votes
## JavaScript (ES6), ~~90~~ ~~87~~ ~~86~~ ~~84~~ 82 bytes

*Saved 3 bytes thanks to ETHproductions*

```
f=(n,a=[1],b=a)=>n--?f(n,[...(F=x=>a.map((n,i)=>n+~~x[i-d]))(a,d=2),0,d=1],F(b)):b

```

### Test cases

```
f=(n,a=[1],b=a)=>n--?f(n,[...(F=x=>a.map((n,i)=>n+~~x[i-d]))(a,d=2),0,d=1],F(b)):b

console.log(JSON.stringify(f(1)))
console.log(JSON.stringify(f(2)))
console.log(JSON.stringify(f(3)))
console.log(JSON.stringify(f(5)))
console.log(JSON.stringify(f(11)))
```

# Answer
> 5 votes
# Mathematica, ~~59~~ 57 bytes

*Thanks to Martin Ender for finding a two-byte savings!*

```
Binomial[i,(j+i)/2]~Sum~{i,Abs@j,b,2}~Table~{j,-b,b=#-1}&

```

Pure function taking a positive integer input and returning a list of integers. Literally produces all the relevant entries of Pascal's triangle and sums them appropriately.

Previous submission (which is a bit easier to read):

```
Table[Sum[Binomial[i,(j+i)/2],{i,Abs@j,b,2}],{j,-b,b=#-1}]&

```

# Answer
> 5 votes
## JavaScript (ES6), 83 bytes

```
f=
n=>[...Array(n+--n)].map(g=(j=n,i,a)=>j--?g(j,i-1)+g(j,i+1)+(a?g(j,i,a):0):i-n?0:1)
```

```
<input type=number min=1 oninput=o.textContent=f(+this.value)><pre id=o>
```

1-indexing cost me a byte. Explanation: `g(j-1,i-1)+g(j-1,i+1)` recursively calculates Pascal's triangle until it reaches the first row, which is the base case. To obtain column sums, I use the fact that `map` actually passes a third parameter, so there is an extra recursive step when this is the case.

# Answer
> 4 votes
# 05AB1E, ~~34~~ ~~32~~ ~~28~~ ~~25~~ 24 bytes

*-4 thanks to Emigna.*

```
FN©ƒ®Ne0})¹®-Å0.ø˜¨ˆ}¯øO

```

Try it online!

---

```
FN©ƒ®Ne0})               # Generate, iteratively, the current pascal row, interspersed with 0's.
          ¹®-Å0          # Calculate the number of zeros to middle pad it.
               .ø˜¨ˆ}¯øO # Surround with the zeros, transpose and sum.

```

---

Basically all it does is generate this:

```
0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 1 0 1 0 0 0 0 0
0 0 0 0 1 0 2 0 1 0 0 0 0
0 0 0 1 0 3 0 3 0 1 0 0 0
0 0 1 0 4 0 6 0 4 0 1 0 0

```

Transpose it:

```
0 0 0 0 0
0 0 0 0 1
0 0 0 1 0
0 0 1 0 4
0 1 0 3 0
1 0 2 0 6
0 1 0 3 0
0 0 1 0 4
0 0 0 1 0
0 0 0 0 1
0 0 0 0 0

```

Then sums each row:

```
0
1
1
5
4
9
4
5
1
1
0

```

---

If a leading and trailing 0 are not acceptable, `®>-Å` isntead of `®-Å` fixes it for a +1 byte penalty.

---

Result for `50`:

```
[0, 1, 1, 50, 49, 1224, 1175, 19551, 18376, 229125, 210749, 2100384, 1889635, 15679951, 13790316, 97994765, 84204449, 523088334, 438883885, 2421229251, 1982345366, 9833394285, 7851048919, 35371393434, 27520344515, 113548602181, 86028257666, 327340174085, 241311916419, 851817398634, 610505482215, 2009517658701, 1399012176486, 4313184213360, 2914172036874, 8448367214664, 5534195177790, 15139356846901, 9605161669111, 24871748205410, 15266586536299, 37524050574849, 22257464038550, 52060859526501, 29803395487951, 66492351226050, 36688955738099, 78239857877649, 41550902139550, 84859704298201, 43308802158651, 84859704298201, 41550902139550, 78239857877649, 36688955738099, 66492351226050, 29803395487951, 52060859526501, 22257464038550, 37524050574849, 15266586536299, 24871748205410, 9605161669111, 15139356846901, 5534195177790, 8448367214664, 2914172036874, 4313184213360, 1399012176486, 2009517658701, 610505482215, 851817398634, 241311916419, 327340174085, 86028257666, 113548602181, 27520344515, 35371393434, 7851048919, 9833394285, 1982345366, 2421229251, 438883885, 523088334, 84204449, 97994765, 13790316, 15679951, 1889635, 2100384, 210749, 229125, 18376, 19551, 1175, 1224, 49, 50, 1, 1, 0]

```

# Answer
> 4 votes
# PHP, 119 bytes

columns numbers from 1-input to input -1

```
for(;$r<$argn;$l=$t[+$r++])for($c=-$r;$c<=$r;$c+=2)$s[$c]+=$t[+$r][$c]=$r|$c?$l[$c+1]+$l[$c-1]:1;ksort($s);print_r($s);

```

Try it online!

# Answer
> 3 votes
# Jelly, 12 bytes

```
Ḷµc€j€0Ṛṙ"NS

```

Try it online!

### How it works

```
Ḷµc€j€0Ṛṙ"NS  Main link. Argument: k

Ḷ             Unlength; yield A := [0, ..., k-1].
 µ            New chain. Argument: A
  c€          Combinations each; compute nCr for each n and r in A, grouping by n.
    j€0       Join each resulting array [nC0, ..., nC(k-1)], separating by zeroes,
              yielding, [nC0, 0, ..., 0, nC(k-1)].
              Note that nCr = 0 whenever r > n.
       Ṛ      Reverse the resulting 2D array.
          N   Negate A, yielding [0, ..., -(k-1)].
        ṙ"    Zipwith rotate; for each array in the result to the left and the
              corresponding integer non-positive integer to the right, rotate
              the array that many units to the left.
           S  Take the columnwise sum.

```

# Answer
> 2 votes
# Python 3, ~~201~~ 184 bytes

```
def f(n):x,z,m=[1],[0],n-1;l=[z*m+x+z*m];exec("x=[*map(sum,zip(z+x,x+z))];l.append(z*(n-len(x))+[b for a in zip(x,z*len(x))for b in a][:-1]+z*(n-len(x)));"*m);return[*map(sum,zip(*l))]

```

# Answer
> 2 votes
# Haskell, 118 112 104 bytes

*6 14 bytes saved thanks to @nimi*

```
z=zipWith(+)
p n|n<2=[1]|m<-p(n-1)=z(0:0:m)(m++[0,0])            -- Generate the nth triangle row.
f n=foldl1 z[d++p x++d|x<-[1..n],d<-[0<$[1..n-x]]]  -- Pad each row with 0s and then sum all the rows.

```

# Answer
> 2 votes
# Python 2, ~~140~~ 137 bytes

```
n=input()
x=[]
a=[0]*n+[1]+n*[0]
z=n%2
exec'x+=[a];a=[(i%2^z)*sum(a[i-1:i+2])for i in range(2*n+1)];z^=1;'*n
print map(sum,zip(*x))[1:-1]

```

Try it online! or Try it online!

<sup>For `n=3`</sup>
Starts with a list with `n` zeros surround an one - `[[0, 0, 0, 1, 0, 0, 0]]`
Generate the full pyramid

```
[[0, 0, 0, 1, 0, 0, 0],
 [0, 0, 1, 0, 1, 0, 0],
 [0, 1, 0, 2, 0, 1, 0]]

```

Rotate 90º and sum each row, discarding the first and the last one (only zeros)

```
[[0, 0, 0],
 [0, 0, 1],
 [0, 1, 0],
 [1, 0, 2],
 [0, 1, 0],
 [0, 0, 1],
 [0, 0, 0]]

```

# Answer
> 2 votes
# Python 3.9+, ~~124~~ 115 chars

```
s=range;f=lambda k:[sum([(q:=(lambda t:(k>(u:=n+x+t)>=0)*(t<1or u/t*q(~-t))))(x)for x in s(2*k)])for n in s(1-k,k)]

```

My previous answer didn't seem to work. Future me using python3.9+. The solution still uses the fact that the Pascal Triangle can be defined with binomial coefficents. Expanding it and defining the negatives as 0.

Also this is my first time golfing so I hope you forgive any faux-pas.

The binomial is not mine and was taken from here.

# Answer
> 1 votes
# Python 3, 100 bytes

```
f=lambda n,r=0:r and[r]+(n and[r+n[0]+(r==n[0])]+f(n[1:],n[0]))or(n*[1]and[1]+f(f(n-1)[2::2],1))+[1]

```

Try it online!

This is really ugly mostly because I mashed together two separate functions. The outer one gets selected when r=0. It recursively calls itself to generate the previous row and then does the following: Discard every other entry. Add a 1 at the end and the beginning. Then have the inner function: Fill the gaps with the sums of the neighbouring entries and if the middle entry was among the discarded ones increment it by one.

# Answer
> 0 votes
# Pari/GP, 31 bytes

```
n->Vec(((y=1+x^2)^n-x^n)/(y-x))

```

Try it online!

The sum of first \\$n\\$ rows is the coefficients of the polynomial \\$\frac{(x^2+1)^n-x^n}{x^2+1-x}\\$.

# Answer
> 0 votes
# Wolfram Language (Mathematica), 40 bytes

```
(((y=x^2+1)^#-x^#)/(y-x)+O@x^(2#))[[3]]&

```

Try it online!

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


title: The last digit in an exponentation

text:
# Question
Title: The last digit in an exponentation
In this task you will be given A (less than 10000 digits long) and B (less than 2^64), and you will need to compute the last digit of (A · A · A · ... · A (B times)).

The inputs A and B are given in a single line separated by a blank; the inputs are terminated by EOF.

**Input**

```
34543232321323243242434544533445343432434311112223454323232132324324243454453344534343243431111222345432323213232432424345445334453434324343111122234543232321323243242434544533445343432434311112223454323232132324324243454453344534343243431111222345432323213232432424345445334453434324343111122234543232321323243242434544533445343432434311112223454323232132324324243454453344534343243431111222 22337254775808
38758436543765743875437656358764347568437658743658743454354645645543532487548758475847684756897548758457843758437584758478574857438758436587436587436587643875643856783478743658743658764387564387564378658437658743658743687564387564387564765746576475647564756475465746574675647654765476547534587545689475689748574385743765874585743857843765893748643587438957458754376543265874387564384764367584375874758943267632487564357 54545454123
6777744348435743587643756438765436574587564354375674365645643675 23232
3875843654376574357 54545454

```

**Output**

```
6
3
5
9

```

**Constraints**

* Don't use any **inbuilt function or overloaded operators** to compute AB (you don't really need to compute that at all).
* Shortest solution wins!

# Answer
# J - 52 characters

```
wd,.10|(^12+12&|)/"1(".@{:`".;._2@,&'x ');._2(1!:1)3

```

Passes all tests given, though only if the trailing spaces on the third input are removed (I'm guessing this was unintentional).

Solution will work in j602 in console mode (e.g. in terminal, emacs j-shell, etc.). It will not work in j701 (no `wd`).

Explanation & Mathiness:

The 'magic number' 12 is the LCM of the lengths of the "last digit" tables found in the other answers. All digits repeat with periods 1,2,3 or 4 so they will also repeat with period 12. Adding twelve to that fixes cases where b mod 12 = 0. My solution computes (Last digit of A)^(12+(B mod 12)), giving a number with the same last digit. (I considered a sneaky broken solution eliminating the three characters '12+' by using e.g. B mod 96 where no examples were likely to collide...)
> 9 votes

# Answer
**Python ~~125~~ 107 Chars**

O(1) solution

```
while 1:a,b=map(int,raw_input().split());d=1;exec"d*=a;"*(b%4);c=a%5and d%5;print b/~b+1or c+[0,5][c%2-a%2]

```
> 6 votes

# Answer
# GolfScript 21

```
~]2/{~.(4%)and?10%n}/

```

This basically calculate `A^C mod 10` where C is in the range `[1,4]` and `C mod 4 = B mod 4`, except if B is 0, then C is also 0.

This shortcut is possible because `A^(B+4) mod 10 = A^B mod 10` for any non-negative integer A and positive integer B.
> 6 votes

# Answer
## Ruby, 97 93 72 71 67 61 60

Also handles the case where b == 0.

```
#!ruby -nl
~/ /
p eval"#$`%10*"*($'>?0?($'.to_i-1)%4+1:0)+?1

```

Guess it's actually worse to use a lookup table.
> 5 votes

# Answer
## J, 79

```
,._2(4 :'10|x^(+y&(|~))x{10$1 1 4 4 2')/\x:".(]_1&{.`];._2~(' ',LF)e.~])(1!:1)3

```
> 5 votes

# Answer
## Windows PowerShell, 85

O(1) solution. Taken a hint from Lowjacker's Ruby solution ;-)

```
$input|%{$a,$b=-split$_
'0000111162481397646455556666179368421919'[4*$a[-1]%48+$b%4]}

```
> 4 votes

# Answer
## Python (119 134 109)

I trust the prohibition against built-in functions doesn't apply to I/O.

```
import sys
p=lambda b,e:e and p(b*b%10,e/2)*(~e&1or b)%10or 1
for l in sys.stdin:print p(*map(int,l.split()))

```

**Edit:** remove use of Python's exponentiation operator.

**Edit:** Replaced ternary operators with short-circuited boolean operators.
> 3 votes

# Answer
**Python 149 Chars**

```
p=[[0],[1],[6,2,4,8],[1,3,9],[6,4],[5],[6],[1,7,9,3],[6,8,4,2],[1,9]]
while 1:a,b=map(int,raw_input().split());print b/~b+1or p[a%10][b%len(p[a%10])]

```
> 3 votes

# Answer
# Vyxal, 4 bytes

```
t$et

```

Try it Online!

No one said it had to be efficient, and the rules forbid only calculating \\$A^B\\$, not \\$A\[-1\]^B\\$.

```
   t # Last digit of...
t    # Last digit of A
  e  # To the power of
 ?   # B

```

More efficient version
> 3 votes

# Answer
## Python 3k

**121 Chars**
```
def p(a,b):
  if b<1:return 1
  return p(a*a%10,b//2)*[1,a][b%2]%10
while 1:
  a,b=map(int,input().split())
  print(p(a%10,b))

```

The `(a*a)%10` is not necessary but it speeds it up, so decided to keep it.

Edit: Apparently, the parentheses are not required.

Meanwhile, thinking about the `O(1)` Solution. :)
> 2 votes

# Answer
# Javascript ( 117   84  79 60 chars)

Reached 60 chars with the suggested improvements from @JiminP and @NoOneIsHere. Thank you!

d=function(s,n){a=Math.pow(s\[s.length-1\],n%4==0?1:n%4)+'';return a\[a.length-1\]}

```
d=(s,n)=>{return(Math.pow(s.slice(-1),n%4||1)+'').slice(-1)}

```

To test:

```
console.log(d('243242434544533445343432434311112223454323232132324324243454453344534343243431111222345432323213232432424345445334453434324343111122234543232321323243242434544533445343432434311112223454323232132324324243454453344534343243431111222345432323213232432424345445334453434324343111122234543232321323243242434544533445343432434311112223454323232132324324243454453344534343243431111222', 22337254775808));
console.log(d('38758436543765743875437656358764347568437658743658743454354645645543532487548758475847684756897548758457843758437584758478574857438758436587436587436587643875643856783478743658743658764387564387564378658437658743658743687564387564387564765746576475647564756475465746574675647654765476547534587545689475689748574385743765874585743857843765893748643587438957458754376543265874387564384764367584375874758943267632487564357', 54545454123));
console.log(d('6777744348435743587643756438765436574587564354375674365645643675', 23232));
console.log(d('3875843654376574357', 54545454));

```

Results:

```
2
3
5
9

```
> 2 votes

---
Tags: code-golf, math
---