# Question
Title: Print the current time… taking leap seconds into account
> (Note: although related, this challenge is not a duplicate of this one because it requires determining leap seconds automatically rather than hardcoding their times, and is not a duplicate of this one because most of the difficulty comes from determining the time without leap second skewing, something that most time APIs don't do by default. As such, a solution is likely to look different from a solution to either of those challenges.)

We're coming to the end of 2016, but it's going to take slightly longer than most people expect. So here's a challenge celebrating our extra second this year.

Output the current time in UTC, as hours, minutes, seconds. (For example, legitimate output formats for midday would include `12:00:00` and `[12,0,0]`; the formatting isn't massively important here.)

However, there's a twist: your program must handle leap seconds appropriately, both past and future. This means that your program will have to obtain a list of leap seconds from some online or automatically updated/updatable source. You may connect to the Internet to obtain this if you wish. However, you may only connect to a URL that predates this challenge (i.e. no downloading parts of your program from elsewhere), and you may not use the connection to determine the current time (specifically: your program must function even if any attempt to access the Internet returns a page that's up to 24 hours stale).

Most operating systems' default APIs for the current time will skew time around leap seconds in order to hide them from programs that might otherwise be confused. As such, the main difficulty of this challenge is to find a method or an API to undo that, and work out the true unmodified current time in UTC.

In theory, your program should be perfectly accurate if it ran on an infinitely fast computer, and must not intentionally take more than zero time to run. (Of course, in practice, your program will run on an imperfect computer, and so will probably not run instantaneously. You don't have to worry about this invalidating the results, but must not depend on it for the correctness of your program.)

Your program must function regardless of which timezone the system clock is set to. (However, it may request information from the operating system or environment as to what timezone is being used, and may assume that the reply is accurate.)

As a , the shortest program wins. Good luck!

# Answer
# PowerShell, 161 bytes

```
(('{0:H:m:s}','23:59:60')[(($d=[datetime]::UtcNow).Ticks-6114960*98e9)/1e8-in((irm ietf.org/timezones/data/leap-seconds.list)-split'[^@]	|
'-match'^\d{9}')])-f$d

```

Try it online! (doesn't work here, it seems that TIO doesn't recognize `irm` and `iwr`, maybe it's a security feature?)

### Logic Test (Hardcoded Date):

```
(('{0:H:m:s}','23:59:60')[(($d=[datetime]'1/1/2017 00:00:00').Ticks-6114960*98e9)/1e8-in((irm ietf.org/timezones/data/leap-seconds.list)-split'[^@]	|
'-match'^\d{9}')])-f$d

```

### Notes

There is a literal `TAB` and a literal linebreak (`0xA`) in the regex string, so that I didn't have to escape them (saved 1 byte each).

### Explanation

The times given (of the leap seconds) in the ietf file are in seconds since NTP epoch which is `1/1/1900 00:00:00`. On Windows, a "tick" is simply one ten-millionth of a second (10,000,000 ticks/sec).

If you add an integer to a `[datetime]` it counts the integer value as ticks, so I'm using the hardcoded tick value of NTP epoch, then subtracting it from the tick value of the current UTC time (the original value of which is simultaneously being assigned to `$d`).

To make that hardcoded tick value smaller, I took away some zeros (9 of them) and divided by 98, then multiply by `98e9` (98\*109).

The result of that subtraction is the value in ticks since NTP epoch. That gets divided by `1e8` (not `1e9`, for reasons that will be clear in a moment) to get the value in seconds (sort of) since NTP epoch. It will be smaller by a factor of 10, actually.

Retrieving the document from the IETF, rather than split it into lines first, then process the lines with the timestamps, I decided to split on both line breaks and on `TAB` characters, since that's what comes after the timestamp. Because of a single errant line in the file, that alone would include an additional timestamp we don't want. The line looks like this:

```
#@	3707596800
```

So I changed the regex to split on `[^@]\t` (any character that's not `@` followed by a `TAB`) which works to exclude that line, but also ends up consuming the last `0` in each of the timestamps.

That's why I divide by `1e8` and not `1e9`, to account for the missing `0`.

The current timestamp is checked to see it exists inside the list of neutered leap second timestamps. This whole process I described is inside the array accessor `[]`, so the resulting `[bool]` value gets coalesced to a `0` (`$false`) or `1` (`$true`). The array we're indexing into contains two elements: a format string for displaying the time, and a hardcoded `23:59:60`. The truthiness of the aforementioned comparison determines which one will be chosen, and that is fed into the format operator `-f` with the previously assigned current date `$d` as its parameter.
> 2 votes

---
Tags: date, code-golf
---


title: Double-slit Quine

text:
# Question
Title: Double-slit Quine
**Objective:**

> Code two programs where each of the programs outputs both source codes interlaced per character like a zipper, a Double-slit Quine. The output from a Double-slit Quine is starting with the first character from the source code of the first program. If the source code of one of the programs is shorter in length than the other, then the rest of the output must be filled with the rest of the longer source code.

**Rules:**

1. You can use any programming language for both programs, not necessary the same programming language for both.
2. Your programs should not take any input from a file, file name, network, the other program or anything else.

**Mandatory criteria:**

* There is a catch, somewhere in the output the word `QUINE` in capital letters must exist, uninterrupted.
* You need to state what two programming languages you are using. If you are using the same programming language for both, then you only need to state one programming language.
* Both programs should be able to execute, or be interpreted, respectively independent of the other program.

**Example:**

Having this example source code of program **one**:

```
"QIE"

```

Having this example source code of program **two**:

```
"UN"

```

Then the valid Double-slit Quine output from both programs must be:

```
""QUINE""

```

This is code-golf, the least bytes when summing the length of both source codes, and obviously also the length of each programs output, wins!

# Answer
# CJam, ~~49~~ 47 bytes

```
{`:_"__~~e#QUINE"}_~

```

and

```
{`:_"__~~e#QUINE"}_~e#QUINE

```

both print

```
{{``""__~~""++::__""ee##QQUUIINNEE""}}__~~e#QUINE

```

Try it online: program 1, program 2, proof of validity

### How they work

```
{                }   e# Push a code block.
                  _~ e# Execute a copy.
 `                   e# Convert the code block into a string.
  :_                 e# Duplicate each character of the resulting string.
    "__~~e#QUINE"    e# Push this string.

```

Program 1 finishes here and has a string representation of its entire source code (which each character repeated twice) as well as the string **e#QUINE** on the stack.

Program 2 additionally parses `e#QUINE`, which is a comment.

In both cases, CJam prints the two strings automatically, resulting in the aforementioned output.
> 9 votes

# Answer
## Seriously, ~~46~~ ~~56~~ 42 bytes

```
QUNX;RZtdXεj.ƒ£REIQ

```

Hex Dump:

```
51554e583b525a746458ee6a2e7f9f9c524549510a

```

The second program is this exact program reversed. It does contain an invisible character, but the byte count is correct. Both programs output this palindromic string:

```

QQUINEXR;£RƒZ⌂t.djXεεXjd.t⌂ZƒR£;RXENIUQQ

```

(For some reason it displays the invisible character when it outputs it in my terminal. I don't really understand that 7F byte.)

How it works:

```
Q                     Push the source to the stack
 U                    Nop
  NX                  Push and pop lyrics to 99 bottles of beer
    ;R                Make a copy of the source reversed.
      Z               Zip them together.
       t              Completely flatten the list.
        dX            Delete the trailing newline
          εj          Join it into a string.
            .         Print it with a trailing newline.
             ⌂        (This is that 7F byte that won't show up. It halts.)

```

The rest of the program is not executed.

Then the other direction:

```
\n                   Nop
  Q                  Push the source code.
   IE                Nops
     R               Reverse source code to get source of first program
      £              Eval it into a function
       ƒ             Call it.

```

At this point, we are now running the first program above, so execution continues as described there.

I am heavily exploiting the fact that several commands do nothing to strings or empty stacks here. I'm also exploiting the unexpected behavior of `t` when there is only one item on the stack. Do not expect this program to work in future versions of Seriously.

As the online version of the Seriously interpreter continues to be broken, you'll have to download the interpreter and run it on your own machine to test it.
> 4 votes

# Answer
# GolfScript, 46 bytes

```
{`{.}%"..~~QUINE"}.~

```

and

```
{`{.}%"..~~QUINE"}.~QUINE

```

both print

```
{{``{{..}}%%""....~~~~QQUUIINNEE""}}..~~QUINE

```

Try it online: program 1, program 2, proof of validity

### How it works

```
{`{.}%"..~~QUINE"}.~

{                }    # Push a code block.
                  .~  # Execute a copy.
 `                    # Convert the code block into a string.
  {.}%                # Duplicate each character of the resulting string.
      "..~~QUINE"     # Push that string.

```

The source code of program 2 additionally parses `QUINE\n`, which are two undefined tokens.
> 1 votes

# Answer
# Perl, 61+60=121 bytes

Program 1:

```
$x=q<print"\$x=q<$x>;eval\$x#"=~s/./$&$&/gr,QUINE>;eval$x#QIE

```

Program 2:

```
$x=q<print"\$x=q<$x>;eval\$x#"=~s/./$&$&/gr,QUINE>;eval$x#UN

```

I thought I'd give this a go in a non-golfing language. This is basically just a universal quine constructor in Perl modified to double every character before printing it, and append `QUINE` to the end. Then we just have to stick a comment at the end of the code to compensate for the added text.

(I wrote this without really looking at the other answers. Turns out it'd be possible to save a byte by putting the entire comment in one program, but I'm not sure if I should just be blatantly copying algorithms like that.)
> 1 votes

---
Tags: code-golf, quine
---


# Question
Title: Returning the range of a number as a palindrome
I like to do programming challenges in my free time to teach myself and keep fresh, this one I can't seem to optimize though and it's driving me insane.

The goal is essentially, "Given a number, return the numbers leading up to it as a palindrome."

For example if you are given the input `5` the answer your program should return is: `123454321`

The catch? You have to solve it in as few characters as possible. The minimum needed seems to be 41 characters and I can't condense it past 76.

I have tried all sorts of solutions, here are a few:

```
# Note: "Palindromic_Number" is required. "def P(N):" will not work.
def Palindromic_Number(N):
    a = ''
    for x in range(1,N+1):
        a += str(x)
    return a + a[::-1][1:]

def Palindromic_Number(N):
    a = ''.join(map(str, range(1,N+1)))
    return a + a[::-1][1:]

def Palindromic_Number(N):
    a = ''.join([str(x) for x in range(1, N+1)])
    return a + a[::-1][1:]

# This one uses Python 2.7
Palindromic_Number = lambda N: ''.join(map(str, range(1,N+1) + range(1,N+1)[::-1][1:]))

```

Does anyone have any ideas as to how I could shorten my code? I'm just looking for a point in the right direction where to look as this point.

# Answer
> 11 votes
You could try:

```
def Palindromic_Number(N):
    return int('1'*N)**2

```

just preforms `11111 * 11111` which equals `123454321`

47 chars.

---

Or, as a lambda:

```
Palindromic_Number=lambda N:int('1'*N)**2

```

41 chars.

# Answer
> 2 votes
In the last solution (that takes advantage of Python 2 style ranges) you could reduce this

```
range(1,N+1) + range(1,N+1)[::-1][1:]

```

in a couple of ways:

1. Instead of slicing the second range, create the reversed range directly as `range(N-1,0,-1)`
2. Making `N` come out of the second range allows changing `N+1` and `N-1` to `N` and `N`:

```
range(1,N) + range(N,0,-1)

```

# Answer
> 2 votes
# Python 2, 40 bytes

```
Palindromic_Number=lambda n:(10**n/9)**2

```

Try it online! (Includes test code to actually run the program.)

I know that you claimed that 41 is the minimum, but it's actually possible to do it in 40.

This uses the same strategy seen in the other answers, of squaring a repunit (a number made out of repetitions of the digit `1`). However, instead of using string operations to produce the repunit (and thus having to pay for `int` to convert string to integer), it generates the palindrome entirely arithmetically.

The basic idea here is that 10<sup>*n*</sup> is a `1` followed by *n* `0`s; if we subtract 1 we therefore get *n* `9`s, and dividing by 9 gives us *n* `1`s. Because Python 2 rounds integer arithmetic downwards, we can omit the subtraction of 1 (as it'll leave the answer higher by ⅑ than it should, which is a fraction that will disappear in the rounding), and we'll still get the correct answer.

# Answer
> 1 votes
~~`range` is a rather long name; with `lambda N,r=range:`/`def ...(N,r=range):` you can shave off a few characters if you~~ also remove all unnecessary whitespace.

---
Tags: code-golf, tips, python, palindrome
---


# Question
Title: Pokemon Type chart (and dual type chart)
I'm always forgetting Pokemon type matchups. This is a challenge to print the pokemon type chart!

```
                                            Attacking Type
                No  Fi  Fl  Po  Gr  Ro  Bu  Gh  St  Fr  Wa  Gr  El  Ps  Ic  Dr  Da  Fa
    Normal      1.0 2.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
    Fighting    1.0 1.0 2.0 1.0 1.0 0.5 0.5 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 0.5 2.0
D   Flying      1.0 0.5 1.0 1.0 0.0 2.0 0.5 1.0 1.0 1.0 1.0 0.5 2.0 1.0 2.0 1.0 1.0 1.0
e   Poison      1.0 0.5 1.0 0.5 2.0 1.0 0.5 1.0 1.0 1.0 1.0 0.5 1.0 2.0 1.0 1.0 1.0 0.5
f   Ground      1.0 1.0 1.0 0.5 1.0 0.5 1.0 1.0 1.0 1.0 2.0 2.0 0.0 1.0 2.0 1.0 1.0 1.0
e   Rock        0.5 2.0 0.5 0.5 2.0 1.0 1.0 1.0 2.0 0.5 2.0 2.0 1.0 1.0 1.0 1.0 1.0 1.0
n   Bug         1.0 0.5 2.0 1.0 0.5 2.0 1.0 1.0 1.0 2.0 1.0 0.5 1.0 1.0 1.0 1.0 1.0 1.0
d   Ghost       0.0 0.0 1.0 0.5 1.0 1.0 0.5 2.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0
i   Steel       0.5 2.0 0.5 0.0 2.0 0.5 0.5 1.0 0.5 2.0 1.0 0.5 1.0 0.5 0.5 0.5 1.0 0.5
n   Fire        1.0 1.0 1.0 1.0 2.0 2.0 0.5 1.0 0.5 0.5 2.0 0.5 1.0 1.0 0.5 1.0 1.0 0.5
g   Water       1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5 0.5 0.5 2.0 2.0 1.0 0.5 1.0 1.0 1.0
    Grass       1.0 1.0 2.0 2.0 0.5 1.0 2.0 1.0 1.0 2.0 0.5 0.5 0.5 1.0 2.0 1.0 1.0 1.0
T   Electric    1.0 1.0 0.5 1.0 2.0 1.0 1.0 1.0 0.5 1.0 1.0 1.0 0.5 1.0 1.0 1.0 1.0 1.0
y   Psychic     1.0 0.5 1.0 1.0 1.0 1.0 2.0 2.0 1.0 1.0 1.0 1.0 1.0 0.5 1.0 1.0 2.0 1.0
p   Ice         1.0 2.0 1.0 1.0 1.0 2.0 1.0 1.0 2.0 2.0 1.0 1.0 1.0 1.0 0.5 1.0 1.0 1.0
e   Dragon      1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5 0.5 0.5 0.5 1.0 2.0 2.0 1.0 2.0
    Dark        1.0 2.0 1.0 1.0 1.0 1.0 2.0 0.5 1.0 1.0 1.0 1.0 1.0 0.0 1.0 1.0 0.5 2.0
    Fairy       1.0 0.5 1.0 2.0 1.0 1.0 0.5 1.0 2.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.5 1.0

```

It has to take an optional parameter that specifies a single type and then prints the dual type chart for that type, which looks like:

```
                                                    Attacking Type
                        No  Fi  Fl  Po  Gr  Ro  Bu  Gh  St  Fr  Wa  Gr  El  Ps  Ic  Dr  Da  Fa
    Electric/-          1.0 1.0 0.5 1.0 2.0 1.0 1.0 1.0 0.5 1.0 1.0 1.0 0.5 1.0 1.0 1.0 1.0 1.0
    Electric/Normal     1.0 2.0 0.5 1.0 2.0 1.0 1.0 0.0 0.5 1.0 1.0 1.0 0.5 1.0 1.0 1.0 1.0 1.0
D   Electric/Fighting   1.0 1.0 1.0 1.0 2.0 0.5 0.5 1.0 0.5 1.0 1.0 1.0 0.5 2.0 1.0 1.0 0.5 2.0
e   Electric/Flying     1.0 0.5 0.5 1.0 0.0 2.0 0.5 1.0 0.5 1.0 1.0 0.5 1.0 1.0 2.0 1.0 1.0 1.0
f   Electric/Poison     1.0 0.5 0.5 0.5 4.0 1.0 0.5 1.0 0.5 1.0 1.0 0.5 0.5 2.0 1.0 1.0 1.0 0.5
e   Electric/Ground     1.0 1.0 0.5 0.5 2.0 0.5 1.0 1.0 0.5 1.0 2.0 2.0 0.0 1.0 2.0 1.0 1.0 1.0
n   Electric/Rock       0.5 2.0 0.3 0.5 4.0 1.0 1.0 1.0 1.0 0.5 2.0 2.0 0.5 1.0 1.0 1.0 1.0 1.0
d   Electric/Bug        1.0 0.5 1.0 1.0 1.0 2.0 1.0 1.0 0.5 2.0 1.0 0.5 0.5 1.0 1.0 1.0 1.0 1.0
i   Electric/Ghost      0.0 0.0 0.5 0.5 2.0 1.0 0.5 2.0 0.5 1.0 1.0 1.0 0.5 1.0 1.0 1.0 2.0 1.0
n   Electric/Steel      0.5 2.0 0.3 0.0 4.0 0.5 0.5 1.0 0.3 2.0 1.0 0.5 0.5 0.5 0.5 0.5 1.0 0.5
g   Electric/Fire       1.0 1.0 0.5 1.0 4.0 2.0 0.5 1.0 0.3 0.5 2.0 0.5 0.5 1.0 0.5 1.0 1.0 0.5
    Electric/Water      1.0 1.0 0.5 1.0 2.0 1.0 1.0 1.0 0.3 0.5 0.5 2.0 1.0 1.0 0.5 1.0 1.0 1.0
T   Electric/Grass      1.0 1.0 1.0 2.0 1.0 1.0 2.0 1.0 0.5 2.0 0.5 0.5 0.3 1.0 2.0 1.0 1.0 1.0
y   Electric/Psychic    1.0 0.5 0.5 1.0 2.0 1.0 2.0 2.0 0.5 1.0 1.0 1.0 0.5 0.5 1.0 1.0 2.0 1.0
p   Electric/Ice        1.0 2.0 0.5 1.0 2.0 2.0 1.0 1.0 1.0 2.0 1.0 1.0 0.5 1.0 0.5 1.0 1.0 1.0
e   Electric/Dragon     1.0 1.0 0.5 1.0 2.0 1.0 1.0 1.0 0.5 0.5 0.5 0.5 0.3 1.0 2.0 2.0 1.0 2.0
    Electric/Dark       1.0 2.0 0.5 1.0 2.0 1.0 2.0 0.5 0.5 1.0 1.0 1.0 0.5 0.0 1.0 1.0 0.5 2.0
    Electric/Fairy      1.0 0.5 0.5 2.0 2.0 1.0 0.5 1.0 1.0 1.0 1.0 1.0 0.5 1.0 1.0 0.0 0.5 1.0

```

The best dual type charts I've found is here, don't forget to list even the non-existent combinations, by clicking 'Show all types'. Types combine by multiplication, except for the same time (eg. electric/electric which is actually electric/-). White space in the output is only important between columns and rows (to remain legibility).

This is code golf so shortest bytes wins.

# Answer
> 4 votes
## JavaScript (ES6), 666 bytes

```
p=>(a=[18611524949,21853721688,27323097365,27406984278,23191686421,37066245461,26177987925,66127746385,37356070566,22827115926,22906831253,21627185429,23913388373,27196216913,18594420117,22906579204,18608379736,26936956281].map(n=>[...n.toString(4)].map(c=>(4>>c)/2)),t=`Normal,Fighting,Flying,Poison,Ground,Rock,Bug,Ghost,Steel,Fire,Water,Grass,Electric,Psychic,Ice,Dragon,Dark,Fairy`.split`,`,n=t.indexOf(p),w=` `.repeat(l=n<0?16:24),w+` `.repeat(28)+`Attacking Type
`+w+t.map(s=>s[0]+s[1]).join`  `+`
`+t.map((s,i)=>(`  Defending Type  `[i]+`   `+(n<0?s:n-i?p+`/`+s:p+`/--------`)+w).slice(0,l)+a[i].map((e,j)=>(i==n|n<0?e:e*a[n][j]).toFixed(1)).join` `).join`
`)

```

Explanation:

```
a=[18611524949,
   21853721688,
   27323097365,
   27406984278,
   23191686421,
   37066245461,
   26177987925,
   66127746385,
   37356070566,
   22827115926,
   22906831253,
   21627185429,
   23913388373,
   27196216913,
   18594420117,
   22906579204,
   18608379736,
   26936956281].map(n=>[...n.toString(4)].map(c=>(4>>c)/2)),

```

These are base 4 encoded numbers where each base 4 digit represents the effectiveness. The mapping is 0 - super effective, 1 - normally effective, 2 - not very effective, 3 - immune. This mapping is chosen because Normal is not super effective against any type and therefore each number will have 18 digits in base 4, but also allowing the effectiveness to be relatively easy to compute.

`t` is just an array of types (split from a string to save bytes). `n` is the index of the passed-in type, this is the easiest way to detect whether a type has been passed in but also saves a byte when checking the current row. `l` is the indentation of the main array, and `w` a string of spaces of length `l`. The first line is therefore just `w` plus a further 28 spaces plus the phrase "Attacking Type". The second line is `w` plus the first two characters of each type, with each pair separated by two spaces. Each row of the array is then generated. The header column is calculated using the appropriate character of phrase "Defending type", three spaces, the relevant types, and enough spaces to pad to length `l`. The columns are then calculated and formatted to 1 decimal place and joined with a single space as required.

There are probably further golfing opportunities but I stopped at 666 bytes because I have spent too much time on this already today.

# Answer
> 3 votes
# Python 2 - ~~2163~~, ~~1648~~, ~~1642~~, ~~1580~~, ~~1560~~, ~~1490~~, 1390 bytes

```
s=[[1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,2,1,1,.5,.5,1,1,1,1,1,1,2,1,1,.5,2],
[1,.5,1,1,0,2,.5,1,1,1,1,.5,2,1,2,1,1,1],
[1,.5,1,.5,2,1,.5,1,1,1,1,.5,1,2,1,1,1,.5],
[1,1,1,.5,1,.5,1,1,1,1,2,2,0,1,2,1,1,1],
[.5,2,.5,.5,2,1,1,1,2,.5,2,2,1,1,1,1,1,1],
[1,.5,2,1,.5,2,1,1,1,2,1,.5,1,1,1,1,1,1],
[0,0,1,.5,1,1,.5,2,1,1,1,1,1,1,1,1,2,1],
[.5,2,.5,0,2,.5,.5,1,.5,2,1,.5,1,.5,.5,.5,1,.5],
[1,1,1,1,2,2,.5,1,.5,.5,2,.5,1,1,.5,1,1,.5],
[1,1,1,1,1,1,1,1,.5,.5,.5,2,2,1,.5,1,1,1],
[1,1,2,2,.5,1,2,1,1,2,.5,.5,.5,1,2,1,1,1],
[1,1,.5,1,2,1,1,1,.5,1,1,1,.5,1,1,1,1,1],
[1,.5,1,1,1,1,2,2,1,1,1,1,1,.5,1,1,2,1],
[1,2,1,1,1,2,1,1,2,2,1,1,1,1,.5,1,1,1],
[1,1,1,1,1,1,1,1,1,.5,.5,.5,.5,1,2,2,1,2],
[1,2,1,1,1,1,2,.5,1,1,1,1,1,0,1,1,.5,2],
[1,.5,1,2,1,1,.5,1,2,1,1,1,1,1,1,0,.5,1]]
e=["Normal ","Fighting","Flying  ","Poison ","Ground ","Rock   ","Bug    ","Ghost  ","Steel  ","Fire   ","Water  ","Grass  ","Electric","Psychic","Ice    ","Dragon ","Dark   ","Fairy  "]
x="\t"
t="No  Fi  Fl  Po  Gr  Ro  Bu  Gh  St  Fi  Wa  Gr  El  Py  Ic  Dr  Da  Fa"
r=range
for i in r(0,18):
  n=""
  for b in r(0,18):n+=str(float(s[i][b]))+" "
  print e[i],x,n
c=s[input()]
print x*6+"Attacking Types"
print x*3+t
for i in r(0,18):
  a=e[s.index(c)]
  n=a+"/"+e[i]+x
  if e[i]==a:n=a+"/--------"+x
  if c!=s[i]:z=[round(float(a*b),1)for a,b in zip(c,s[i])]
  else:z=c
  for b in r(0,18):n+=str(float(z[b]))+" "
  print n

```

Try it here!

**This program has 765 bytes from hard-coding the data of the effectiveness of each type down in `s`**. Example Output:

The chart with single types (last line is where you type in the input):  The chart with dual types:

**Explanation**

`s` holds the effectiveness stats in list per defending element (first is for the effectiveness against Normal, next against Fighting, etc.)

```
s=[[1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,2,1,1,.5,.5,1,1,1,1,1,1,2,1,1,.5,2],
[1,.5,1,1,0,2,.5,1,1,1,1,.5,2,1,2,1,1,1],
[1,.5,1,.5,2,1,.5,1,1,1,1,.5,1,2,1,1,1,.5],
[1,1,1,.5,1,.5,1,1,1,1,2,2,0,1,2,1,1,1],
[.5,2,.5,.5,2,1,1,1,2,.5,2,2,1,1,1,1,1,1],
[1,.5,2,1,.5,2,1,1,1,2,1,.5,1,1,1,1,1,1],
[0,0,1,.5,1,1,.5,2,1,1,1,1,1,1,1,1,2,1],
[.5,2,.5,0,2,.5,.5,1,.5,2,1,.5,1,.5,.5,.5,1,.5],
[1,1,1,1,2,2,.5,1,.5,.5,2,.5,1,1,.5,1,1,.5],
[1,1,1,1,1,1,1,1,.5,.5,.5,2,2,1,.5,1,1,1],
[1,1,2,2,.5,1,2,1,1,2,.5,.5,.5,1,2,1,1,1],
[1,1,.5,1,2,1,1,1,.5,1,1,1,.5,1,1,1,1,1],
[1,.5,1,1,1,1,2,2,1,1,1,1,1,.5,1,1,2,1],
[1,2,1,1,1,2,1,1,2,2,1,1,1,1,.5,1,1,1],
[1,1,1,1,1,1,1,1,1,.5,.5,.5,.5,1,2,2,1,2],
[1,2,1,1,1,1,2,.5,1,1,1,1,1,0,1,1,.5,2],
[1,.5,1,2,1,1,.5,1,2,1,1,1,1,1,1,0,.5,1]]

```

`e` holds the names of the types. There are spaces put in to maximize the usage of `\t` in later parts of the code.

```
e=["Normal ","Fighting","Flying  ","Poison ","Ground ","Rock   ","Bug    ","Ghost  ","Steel  ","Fire   ","Water  ","Grass  ","Electric","Psychic","Ice    ","Dragon ","Dark   ","Fairy  "]

```

This part prints the attacking types (literally too!)

```
print "\t\t\t\t\tAttacking Types"
print "\t\tNo  Fi  Fl  Po  Gr  Ro  Bu  Gh  St  Fi  Wa  Gr  El  Ps  Ic  Dr  Da  Fa"

```

This prints out the defending type and its respective stats according to the pre-made table and uses `\t` for uniform spacing:

```
for i in range(0, 18):
  n=""
  for b in range(0, 18):
    n+=str(float(s[i][b]))+" "
  print e[i],"\t",n

```

Take input. The input is an integer from 0 to 17 since there are 18 lists (one for each element). `0` returns `s[0]` which is the list for Normal type, `1` returns `s[1]` which is the list for Fighting type, etc. Notice how in the screenshot, 12 is used since `s[12]` is the list for the Electric type:

```
c = s[int(raw_input())]

```

Print out the attacking types (literally as well) again for second table:

```
print "\t\t\t\t\t\tAttacking Types"
print "\t\t\tNo  Fi  Fl  Po  Gr  Ro  Bu  Gh  St  Fi  Wa  Gr  El  Ps  Ic  Dr  Da  Fa"

```

This is where the second table starts to take place. To get the dual types' results, we must loop through every single list and prepare the string with the two types used:

```
for i in range(0, 18):
  n=e[s.index(c)] + "/"+e[i]+"\t"
  if e[i]==e[s.index(c)]:
    n=e[s.index(c)]+"/--------"+"\t"

```

Then we actually do the math. If the input matches the type the list belongs to, do nothing really. Else, start multiplying:

```
if c!=s[i]:
  z=[round(float(a*b), 1) for a,b in zip(c, s[i])]
else:
  z=c

```

Finish the table by printing out the string, `n`, for each dual type possibilty:

```
for b in range(0, 18):
  n+=str(float(z[b]))+" "
print n

```

**Thanks @DJMcMayhem for saving 515 bytes!** **Thanks @Rod for saving 20 bytes!** **Thanks @Qwerp-Derp for saving 70 bytes!**

---
Tags: code-golf, kolmogorov-complexity
---


title: Every prime bit must alternate

text:
# Question
Title: Every prime bit must alternate
A program is ***bit primed*** if bits in prime positions must alternate between zero and one, starting with one.

For example, this is a template for a bit primed program with \[0..47\] bits.

```
..10.1.0 ...1.0.. .1.0...1 .....0.1 .....0.. .1.0...1
01234567 89012345 67890123 45678901 23456789 01234567

```

---

**Create a bit primed program** that takes as input a string and checks if the string is bit primed. The string will be in ASCII and it will be a maximum of 1000 chars.

## Rules

* For the purposes of this challenge, the bit string for `ABCD` is

```
01000001 01000010 01000011 01000100

```
* This is , so the shortest answer in bytes wins.

# Answer
> 11 votes
# Mathematica, 5432 bytes

```
f[gQqGCStZu2yl3mIEL5mBpO43ulpBaJP4g2sCvYht09xS9XvYv2XK7aZ6P2yh47J2y2Z8s42u91aKQT8dDQ7NZQFDShTWXW7ldVB8IorrV2Fu6ItvMF2y285nz52GizM3X1q0t3F7KMa@Print[29RshFOc0Zh3HKaau;i=0;1Kv6jpY40n3fmIl0YYfiskcIZaATpT76lc6ph3FhR1INU2ptKd8SJ8GXC54akjX4s08vjnaliCS5AQcSh56YS8hQ3xe2xtCV36Gn6lTDAg1tX3cz6G1tn2NB5NLk9Nx4O7Ygfmf3fAs6mnD3PjIzFw2FAK5Qj6i4wW0Gq0RSo7K6aV93L8N75ioRr6oZlCBRzeq3fiQI71KXLADrcO9sJVh24vMZr84plVXqzo52bmuRO6v6LoP47mggmS00gFtCXnwr64YntzbVjNpiyxQMDLXJnd1vUeUvvy0P6CodeGolfib1psOCu9iMxiT2oGesnIoDrqnKHqExqxgh30kFJRwJJk6LvY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NRI97KiRHtsqGbNf70mvGj2lj1QF3Uv0sW1e7YliNp1w5M8lyHGpVVW7uBdyqKqXzGkqSa9DW527qbPHZPM1nCN;ToCharacterCode@#,wm;2,Yr3TLDuNJKQ2NHCv9;8])),hmPvHeg3R2mw02;Array[yruQ95uaGFdJu1;PrimeQ,Tr[GjbUXt;0l+1],Xxt;0]],8La1ktK9xi3XXf;#==(UISzsyNOrrXj0eSRMrbIzDOVjfKK0IazH6JdZQY7lzBolXGwU98mJjINCzp7pROIx1rwaTo1JdOSyw6Lw3KVXu85AxiKM7Q2EsvUEQaq8rMhAwdsgWYO21aAVLwuoz5Uz8NnASPJmW4f04z1kgUrAfMjZ0VAFaM2405222oU3y0yc5nxVmKd7AcA5gwCa3labMkKF7lMq5o8prUSy1AVTxNH7E46LVYWjxyw6Q6YRzNPSRJJWtjhVGt8tMkj;i=1-i)&]]Df]&

```

Takes a string as an input. Prints `True` or `False`. This works because Mathematica ignores undefined variables/functions. Because this code is so long, I stuck some easter eggs in there. :)

I'm sure this can be golfed more...

**Explanation**

Without all the gibberish (99 bytes):

```
AllTrue[Pick[l=Join@@IntegerDigits[ToCharacterCode@#,2,8],Array[PrimeQ,Tr[0l+1],i=0]],#==(i=1-i)&]&

```

---

```
ToCharacterCode@#

```

Convert the input into character codes.

```
IntegerDigits[ToCharacterCode@#,2,8]

```

Convert the character codes into binary numbers, length 8.

```
l=Join@@IntegerDigits[ToCharacterCode@#,2,8]

```

Flatten the result and store that in `l`. This generates the bit list of the input.

---

```
Tr[0l+1]

```

A short way to find the length of `l`.

```
Array[PrimeQ,Tr[0l+1],i=0]

```

Set `i` to 0. Create a list from 0 to (length l) - 1. Map primality test onto that list. In this list, only the prime positions are `True`.

---

```
Pick[l=Join@@...,Array[...]]

```

From the first argument (bit list), select ones whose corresponding element of the second argument (list whose prime positions are `True`) is `True`.

```
AllTrue[Pick[...],#==(i=1-i)&]

```

Check whether the resulting list is alternating 1 and 0, starting with 1. (each element is compared to `i`, and `i` alternates between 1 and 0 (`i=1-i`) each iteration).

**Testing**

```
f[gQqGCStZu2yl3mIEL5mBpO43ulpBaJP4g2sCvYht09xS9XvYv2XK7aZ6P2yh47J2y2Z8s42u91aKQT8dDQ7NZQFDShTWXW7ldVB8IorrV2Fu6ItvMF2y285nz52GizM3X1q0t3F7KMa@Print[29RshFOc0Zh3HKaau;i=0;1Kv6jpY40n3fmIl0YYfiskcIZaATpT76lc6ph3FhR1INU2ptKd8SJ8GXC54akjX4s08vjnaliCS5AQcSh56YS8hQ3xe2xtCV36Gn6lTDAg1tX3cz6G1tn2NB5NLk9Nx4O7Ygfmf3fAs6mnD3PjIzFw2FAK5Qj6i4wW0Gq0RSo7K6aV93L8N75ioRr6oZlCBRzeq3fiQI71KXLADrcO9sJVh24vMZr84plVXqzo52bmuRO6v6LoP47mggmS00gFtCXnwr64YntzbVjNpiyxQMDLXJnd1vUeUvvy0P6CodeGolfib1psOCu9iMxiT2oGesnIoDrqnKHqExqxgh30kFJRwJJk6LvY4M3ZCkKn43oFERtHe7d5qO7AvaF9T4o9T4Cf97MN1anz4TEPlR7FjoqQXaBVV57a5NfSZW97EFeIVn8LsqHjCgg72Vl6usW8L3RWlIo05Lfd8u7jUD0B8SP1fWymaP7kwYNLCg5OUQtLk479hUsE8bJungHwanMinm1xV9naf97dMqobj6jVAM1EzvXguLOal4OXO6DBFtmhHNwzx6u47fVRy7f;AllTrue[XF2uhxta8qS5K0ZeL9pmX3Zhrqn4IHD2hNTdEb9rsQw8raVJvbgSP1uk9OByu;Pick[l=(2EOFI4khaVxpn5d01z8kaARZNiz1oNZkcniL0sD13Sfqrapri0sq9AV12Wh9F1NtYjwbvHtM73G;Join@@(XX9giynmc3Y6ZScD3SIq0QdKvDHh30p3JAlYizir8xzW4d1AfMEIGKom1Hn3m4oGmSZACY012g1a1YRGaFY6YvI5zuzoseFjEDOn002W0qTCFdsmFMO0Wq05jPvEotODJ688d1Ef2iknRra301eEwXtCYAigA294p3Rn1i6dFvhOuIm9Om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lVVkrKeyvrDOQpT2rEIgsnDoTiy2jRZig0RmPA2718281828459045235w5f9780gQetd63mnIF4sg4tkhx0g2lR9ZNn70ZUZNzkxvIYfO4jnMPtcM7a1ek8f2rp0znURrnA8VB1Ak0uY3AmK9DoEHcJmodGNGliF7L5LVP7ABzPfKKMCdtAu6zZgW0XsPPs4WYy9jlkG25973qp678lKmN0LAdOaHT72lFrr9frau1402jqCHZqIy4qcRYyeCOrD0IkqZT9izDv59Z3b9fdkyoo5sO8AWFGerJ9vVT5m5mSzd8bWZZ7dss4XYHk3UORyLi1gpbKlT1QZbypPx0eF18TA6wuban93JZmfOngzx2kTNoRXa911ififrUt56nIuRtY324NPpvt7Rixl4X2YZzbOLm4L5kew9fv1BZvZQOPtLuQ7If368aUQnpV04D7TAkb1qbQbOKmkOVPgA7d0LMtlYwZbNRI97KiRHtsqGbNf70mvGj2lj1QF3Uv0sW1e7YliNp1w5M8lyHGpVVW7uBdyqKqXzGkqSa9DW527qbPHZPM1nCN;ToCharacterCode@#,wm;2,Yr3TLDuNJKQ2NHCv9;8])),hmPvHeg3R2mw02;Array[yruQ95uaGFdJu1;PrimeQ,Tr[GjbUXt;0l+1],Xxt;0]],8La1ktK9xi3XXf;#==(UISzsyNOrrXj0eSRMrbIzDOVjfKK0IazH6JdZQY7lzBolXGwU98mJjINCzp7pROIx1rwaTo1JdOSyw6Lw3KVXu85AxiKM7Q2EsvUEQaq8rMhAwdsgWYO21aAVLwuoz5Uz8NnASPJmW4f04z1kgUrAfMjZ0VAFaM2405222oU3y0yc5nxVmKd7AcA5gwCa3labMkKF7lMq5o8prUSy1AVTxNH7E46LVYWjxyw6Q6YRzNPSRJJWtjhVGt8tMkj;i=1-i)&]]Df]&"]

```

> `True`

Feeding the program to itself does print `True`.

```
f[gQqGCStZu2yl3mIEL5mBpO43ulpBaJP4g2sCvYht09xS9XvYv2XK7aZ6P2yh47J2y2Z8s42u91aKQT8dDQ7NZQFDShTWXW7ldVB8IorrV2Fu6ItvMF2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mbM5AcQB52zXgy7pSVvlXdrLqdFwGrFRDrQ03DXm0r9ZbRitrU2tEzVmE9og9AKeAq7pZb68ypniGn5VVBM3mUMZjAACaVmgn5uZS0xsQcE84rblzkK1DAIa2yQ6ixAkGdlezfe6o94B3SJIgjujkBb876db31RXQVSX7aCLWm9DXr1ie7hc2U1M3y3Y3LK4eFbzM69Bg6B5TWVmY6AfBJsC8iYpfICgCpCNDUgGx53EzoWhatALongProgramuqO6XCaRvMePL0QFjx8ojo8IHbEIwbbat4DtRF4vTgRC0wQFzzSyrx2XoajV2DX70042W3x1o99Y4ms9dHATupNeeA57BtUU6rJ2li2i9mQHb1EftkNG5fnSSxWORLqdxw1uki88bxwf2sb7e1Sv4DHEA81ixwR74lT7k2FQ8qvL8ZyPN1iLn1NbpgOFXKAXOioKpoW2OHX6RNDRrL0rOBuLLugIiPg3SJ4n7kr0Ozm5N6nrGNNY5XlVIzE3i7Fqw96cGL8L7bNJBr3AIBaK5Il7RuIQT1nsFPJS810Ery0N9Hi5k96xn90UI80Joqg5DF7QRCWJF314159265358979323846dTVFQxiECjT5nYFX6Uw47fS3lhiEApOtuy1ghNiQbJzpjm67LKaxiEq8bAEXDQeEneLlixqi8AlYgan30RVlWJz2WEykIYH5LMcykwgPGNXOrPBzy63MCS3TB71I9yYar9eMqGRc4sz30GzU19v3rNohnMX5iaPSlkVPQB7kY2qpWaHe4gDjkOi69vErtRXON0Xqo6mvr1a8Ce980LT3X9jreKoDX5q33lSVxjlYBBlDYrRzNIWqrZr1YYkupuZM0wn9q8P9W86iTGf5GR705WWj5OKUjE6f1Z7Ro3P838mqrqYImc3qMV8wbnQ8Ogz8Fkxscc7F7lq06q0DkpUK7BK5mxBe046QrtyiuEYj999qFdo4nA9Exfw9xvi77WofVQ31tTBu3HZJsB3ypyZp3Omn2I7gsOQm89nXrDXOXalI4N1nvGRARtExOo5tN3WIlVVkrKeyvrDOQpT2rEIgsnDoTiy2jRZig0RmPA2718281828459045235w5f9780gQetd63mnIF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2mbM5AcQB52zXgy7pSVvlXdrLqdFwGrFRDrQ03DXm0r9ZbRitrU2tEzVmE9og9AKeAq7pZb68ypniGn5VVBM3mUMZjAACaVmgn5uZS0xsQcE84rblzkK1DAIa2yQ6ixAkGdlezfe6o94B3SJIgjujkBb876db31RXQVSX7aCLWm9DXr1ie7hc2U1M3y3Y3LK4eFbzM69Bg6B5TWVmY6AfBJsC8iYpfICgCpCNDUgGx53EzoWhatALongProgramuqO6XCaRvMePL0QFjx8ojo8IHbEIwbbat4DtRF4vTgRC0wQFzzSyrx2XoajV2DX70042W3x1o99Y4ms9dHATupNeeA57BtUU6rJ2li2i9mQHb1EftkNG5fnSSxWORLqdxw1uki88bxwf2sb7e1Sv4DHEA81ixwR74lT7k2FQ8qvL8ZyPN1iLn1NbpgOFXKAXOioKpoW2OHX6RNDRrL0rOBuLLugIiPg3SJ4n7kr0Ozm5N6nrGNNY5XlVIzE3i7Fqw96cGL8L7bNJBr3AIBaK5Il7RuIQT1nsFPJS810Ery0N9Hi5k96xn90UI80Joqg5DF7QRCWJF314159265358979323846dTVFQxiECjT5nYFX6Uw47fS3lhiEApOtuy1ghNiQbJzpjm67LKaxiEq8bAEXDQeEneLlixqi8AlYgan30RVlWJz2WEykIYH5LMcykwgPGNXOrPBzy63MCS3TB71I9yYar9eMqGRc4sz30GzU19v3rNohnMX5iaPSlkVPQB7kY2qpWaHe4gDjkOi69vErtRXON0Xqo6mvr1a8Ce980LT3X9jreKoDX5q33lSVxjlYBBlDYrRzNIWqrZr1YYkupuZM0wn9q8P9W86iTGf5GR705WWj5OKUjE6f1Z7Ro3P838mqrqYImc3qMV8wbnQ8Ogz8Fkxscc7F7lq06q0DkpUK7BK5mxBe046QrtyiuEYj999qFdo4nA9Exfw9xvi77WofVQ31tTBu3HZJsB3ypyZp3Omn2I7gsOQm89nXrDXOXalI4N1nvGRARtExOo5tN3WIlVVkrKeyvrDOQpT2rEIgsnDoTiy2jRZig0RmPA2718281828459045235w5f9780gQetd63mnIF4sg4tkhx0g2lR9ZNn70ZUZNzkxvIYfO4jnMPtcM7a1ek8f2rp0znURrnA8VB1Ak0uY3AmK9DoEHcJmodGNGliF7L5LVP7ABzPfKKMCdtAu6zZgW0XsPPs4WYy9jlkG25973qp678lKmN0LAdOaHT72lFrr9frau1402jqCHZqIy4qcRYyeCOrD0IkqZT9izDv59Z3b9fdkyoo5sO8AWFGerJ9vVT5m5mSzd8bWZZ7dss4XYHk3UORyLi1gpbKlT1QZbypPx0eF18TA6wuban93JZmfOngzx2kTNoRXa911ififrUt56nIuRtY324NPpvt7Rixl4X2YZzbOLm4L5kew9fv1BZvZQOPtLuQ7If368aUQnpV04D7TAkb1qbQbOKmkOVPgA7d0LMtlYwZbNRI97KiRHtsqGbNf70mvGj2lj1QF3Uv0sW1e7YliNp1w5M8lyHGpVVW7uBdyqKqXzGkqSa9DW527qbPHZPM1nCN;ToCharacterCode@#,wm;2,Yr3TLDuNJKQ2NHCv9;8])),hmPvHeg3R2mw02;Array[yruQ95uaGFdJu1;PrimeQ,Tr[GjbUXt;0l+1],Xxt;0]],8La1ktK9xi3XXf;#==(UISzsyNOrrXj0eSRMrbIzDOVjfKK0IazH6JdZQY7lzBolXGwU98mJjINCzp7pROIx1rwaTo1JdOSyw6Lw3KVXu85AxiKM7Q2EsvUEQaq8rMhAwdsgWYO21aAVLwuoz5Uz8NnASPJmW4f04z1kgUrAfMjZ0VAFaM2405222oU3y0yc5nxVmKd7AcA5gwCa3labMkKF7lMq5o8prUSy1AVTxNH7E46LVYWjxyw6Q6YRzNPSRJJWtjhVGt8tMkj;i=1-i)&]]Df]&["ABC"]

```

> `False`

Checking `ABC` -- `False`

**Check for characters that work**

```
Catch[Block[
   {p, j = 1, i = 0, c = Characters@#, l, k = #2 - 1, max = 100000},
   p = AssociationMap[(i = 1 - i) &, Prime~Array~max];
   l = Length@c;
   While[k < max/8,
    Which[j > l,
       Throw[k - l + 1],
       MatchQ[IntegerDigits[ToCharacterCode[c[[j]]][[1]], 2, 8], #],
       j++,
       j > 1,
       k -= j - 1; j = 1
       ] &@Array[Lookup[p, #, _] &, 8, 8 k];
    k++
    ]; $Failed]] &

```

I wrote a simple code that checked where certain characters could be inserted (e.g. the first place to put `Print[` while keeping the code bit-primed is position 141, 1-indexed).

The first argument is the string in interest and the second argument is the starting position (also 1-indexed).

I used this code to find out where to put meaningful code and then filled the rest of the code with gibberish, but choosing characters that keep the code bit-primed; simple with `Prime` and `Partition` (and `RandomChoice`)

---
Tags: code-golf, restricted-source, primes, decision-problem, binary
---


# Question
Title: Thinking outside the box - Am I doing it right?
I keep hearing that thinking outside the box is a goal worth achieving, but how can I tell if I'm successfully doing it?

To solve this dilemma I have already wrote a *Brainwave-to-ASCII*-translator which in theory should produce outputs like

```
                    #
   +------------+   #
   |   thinking |   #
   |            |   #
   +------------+   #
                    #

```

or

```
                   #
 +------+          #
 |      | thinking #
 |      |          #
 |      |          #
 +------+          #
                   #

```

which make it fairly easy to tell whether one is thinking outside the box or not. (The `#` are not part of the output and represent new lines.)

However, due to a bug sometimes only a smaller section of the output is returned:

```
   |         |         #
   +---------+         #
    thinking           #

```

```
        #
       +#
       |#
inking |#

```

```
    #
    #

```

## The Task

Please help me to automatically classify the *Brainwave-to-ASCII*-translator output by writing a program or function which reads an ascii-reprensentation and returns whether `thinking` is in the box, outside of it or it could not tell from the input.

### Input

A set of same-length strings either as a list or delimited by newlines containing

* the string `thinking` or valid pre- or suffixes thereof
* the characters `+-|` forming a rectangular box or valid parts of it
* spaces
* **NO `#`**, those are only included in the challenge to mark the ends of the input lines.

### Output

* a *truthy* value if `thinking` is outside the box
* a *falsy* value if `thinking` is in the box
* a distinct third *maybe* value if it can not be determined from the input whether `thinking` is in the box or not

## Examples

**Truthy:**

```
                   #
 +------+          #
 |      | thinking #
 |      |          #
 |      |          #
 +------+          #
                   #

```

```
   |         |         #
   +---------+         #
    thinking           #

```

```
        #
       +#
       |#
       |#
inking |#

```

```
thinking #
-------+ #

```

```
 ++ # (thinking is not in the box, so it must be outside)
 ++ # (this is also the smallest possible box)

```

```
+ #
 t#

```

```
+----+# (The box is not wide enough to contain "thinking")

```

```
---# (The box is not high enough to contain "thinking")
---#

```

As string input:

```
"                   \n +------+          \n |      | thinking \n |      |          \n |      |          \n +------+          \n                   "
"   |         |         \n   +---------+         \n    thinking           "
"        \n       +\n       |\n       |\ninking |"
"thinking \n-------+ "
" ++ \n ++ "
"+ \n t"
"+----+"
"---\n---"
"g++"
"k\n+"

```

**Falsy:**

```
                    #
   +------------+   #
   |   thinking |   #
   |            |   #
   +------------+   #
                    #

```

```
  +---------------#
  |               #
  |               #
  |   thinking    #

```

```
      | #
king  | #
------+ #

```

```
+---#
|thi#
+---#

```

```
-#
n#
-#

```

As string input:

```
"                    \n   +------------+   \n   |   thinking |   \n   |            |   \n   +------------+   \n                    "
"  +---------------\n  |               \n  |               \n  |   thinking    "
"      | \nking  | \n------+ "
"+---\n|thi\n+---"
"-\nn\n-"

```

**Maybe:**

```
thinking#

```

```
g|#

```

```
think#
-----#

```

```
|          |# (box large enough to possibly contain the string)
|          |#

```

```
   +--#
   |  #

```

```
# (empty input)

```

As string input:

```
"thinking"
"g|"
"|t"
"-\ni"
"h\n-"
"think\n-----"
"|          |\n|          |"
"   +--\n   |  "
""

```

## Rules

* This is , so try to use as few bytes as possible.
* The *maybe* value can be chosen freely as long as it's different from the truthy/falsy value and is the same for all maybe-inputs. It can also be an error.
* You can assume that the input is always valid (eg. contains no other chars than `+-ghiknt|`, no more than one box, ...).

# Answer
> 11 votes
# Javascript (ES6), ~~274~~ 263 bytes

```
f=(a,b=(b,c="")=>a=a.replace(b,c),c=b=>b.test(`,${a},`))=>(b(/\w+/,5),b(/\+/g,1),b(/\-/g,2),b(/\|/g,3),b(/\n/g,4),c(/[13][2 ]{0,7}[13]|[12] *4 *[12]/)||(b(/ /g),b(/43+(?=4)/g),!c(/353|24542|12+435|21453|35412|5342+1/)&&(!c(/^([^1]*|([^15]*1){1,2}[^15]*)$/)||-1)))

```

The function `f` returns `true`, `false`, or `-1` as its "maybe" value. It should be called with one argument: the input. The other two parameters only exist to shorten the code.

Here's a less golfed version with comments:

```
var f = (input) => {
    var replace = (re, s) => input = input.replace(re, s);
    var test = re => re.test(input);

    /*
        Replace some "special" characters with ones that are shorter to put in a regex.
        "+" --> "1"
        "-" --> "2"
        "|" --> "3"
        "\n" --> ","
    */
    replace(/\+/g,1);
    replace(/\-/g,2);
    replace(/\|/g,3);
    replace(/\n/g,',');

    /*
        Shorten the word, if there is one, to just a single character "a".
    */
    replace(/[a-z]+/g,'a');

    /*
        Append a newline to the beginning and end of the input.
    */
    input = ','+input+',';

    /*
        Test the size of the box. These are the cases covered:
        /[13][2 ]{0,7}[13]/ : A horizontal edge or middle section has an inner width of fewer than 8 characters.
        /[12] *, *[12]/     : There are two horizontal edges in a row, with no space between.

        If either of these match, the word must be outside of the box. Return the truthy value (true).
    */
    if (test(/[13][2 ]{0,7}[13]|[12] *, *[12]/)) return true;

    /*
        Remove any spacing from the input. It it unnecessary from this point onwards.
    */
    replace(/ /g,'');

    /*
        Remove any lines with only vertical bars. These are also unnecessary.
    */
    replace(/,3+(?=,)/g,'');

    /*
        Edge / corner cases (heh). These are the cases covered:
        /3a3/    : two vertical bars with the word between.
        /2,a,2/  : two horizontal bars with the word between.
        /12+,3a/ : word inside the top left corner.
        /21,a3/  : word inside the top right corner.
        /3a,12/  : word inside the bottom left corner.
        /a3,2+1/ : word inside the bottom right corner.

        If any of these match, the word is inside the box. Return the falsy value (false).
    */
    if (test(/3a3|2,a,2|12+,3a|21,a3|3a,12|a3,2+1/)) return false;

    /*
        "Maybe" cases. These are the cases covered:
        /^[^1]*$/                : Input contains no corners, and may or may not contain a word.
        /^([^1a]*1){1,2}[^1a]*$/ : Input contains 1 or 2 corners, and no word.

        If either of these match, assuming the previous test cases have not been hit,
        we cannot tell if the word is inside or outside the box. Return the maybe value (-1).
    */
    if (test(/^([^1]*|([^1a]*1){1,2}[^1a]*)$/)) return -1;

    /*
        If none of the previous cases matched, the word must be outside of the box. Return the truthy value (true).
    */
    return true;
};

```

Had a lot of fun with this one. Thanks!

Edit: Saved 6 bytes thanks @L. Serné by modifying `b` to use a default argument, saving 3 bytes, and changing `[a-z]` to `\w`, saving 3 more bytes. Also saved 5 more bytes by making the word replacement non-global, saving 1 byte, and changing `"a"` to `5` and `","` to `4`, saving 4 bytes.

# Answer
> 8 votes
# Python 2.7, ~~532~~ ~~494~~ 453 bytes

This one sure had a lot of special cases. My truthy and falsy values are the strings "True" and "False" respectively. My maybe value is an Index Error, as they're easy to trigger and one of my test cases triggers it if the input is an empty string, which is a maybe case anyway. I made use of regular expressions quite a bit.

I don't golf in python often, so I'm sure this could be golfed down more, but here's my code:

```
import re
def e(s):exit(str(s))
i=input()
T=1<2
F=2<1
a=len(i)+1
c=i.count('+')
s='[a-z]'
x=re.search
p=x(s,i)
k=x('\+.*'+s,i)
l=x(s+'.*\|',i)
r=x('\|.*'+s,i)
f=i.find('+')
g=i[f-1]=='-'and f>0
if x('\-.*\n.*\-',i):e(T)
if x('\+.{0,7}\+',i):e(T)
if c>1 and not p:i[a]
if c>3:e(not(r and l))
if c>0:
 if r and l:e(F)
 if g:
    if l:e(F)
    if p or k:e(T)
    i[a]
 if r or k:e(F)
 if p:e(T)
 i[a]
if x('-.*\s[a-z].*\s-',i):e(F)
if x('\|.*[a-z].*\|',i):e(F)
i[a]

```

In my golfed version, I display the True/False answer by calling `exit(bool as string)`. Here's a commented version, in which the exit statements are replaced with return statements, and everything's been moved into a function:

```
import re
i=input()
T=True
F=False
def z():
    # some variables and shortcuts useful for testing

    # length of input +1. Used to throw an index out of bounds error on 'maybe'
    a=len(i)+1
    # c for i.Count()
    c=i.count
    # string used in regular expressions often
    s='[a-z]'
    # shorten regeX calls
    x=re.search
    # p is true is 'thinking' is Present on canvas
    p=x(s,i)
    # k is true if 'thinking' is Right of a 'Korner' (corner)
    k=x('\+.*'+s,i)
    # l is true if 'thinking' is Left of a pipe (|)
    l=x(s+'.*\|',i)
    # r is true if 'thinking' is right of a pipe
    r=x('\|.*'+s,i)
    # f is First corner (+) index
    f=i.find('+')

    # g is true if box is facing riGht (i.e. there is a dash before the first +)
    # for example, '---+' indicates the box faces right. if the + is the 0th
    # character, then the box must be facing left.
    # Note that this assignment also checks for the empty string 'maybe'
    # case, which is signalled by an IndexOutofBounds error
    # CASE 1: Empty Input
    # ex: ''
    g=i[f-1]=='-' and f>0

    # Begin testing all possible scenarios

    # CASE 2: Box is too short (vertically)
    # ex: ------
    #     ------
    if x('\-.*\n.*\-',i):return T

    # CASE 3: box is too short (horizontally)
    # ex: ||
    if x('\+.{0,7}\+',i):return T

    # CASE 4: box is not too short yet no corners (+) or text are present on canvas
    # ex:
    # |       |         --------
    # |       |   or
    # |       |         --------
    # this is a maybe case, so throw out of bounds error
    if c('+')>1 and not p:i[a]

    # CASE 5: Four corners visible (whole box visible)
    # ex: +---+
    #     | X |
    #     +---+
    # return false if text is both right of and left of pipes (i.e. in box)
    if c('+')>3:return not(r and l)

    # CASE 6: one or two corners visible
    # ex:
    # ----+        |    |          |
    #     |    or  +----+   or  ---+  etc
    # ----+
    # in this case, we idenify which way the box faces
    if c('+')>0:

        # CASE 6-A: Text is between two pipes
        # ex:
        #     |   X   |
        #     +-------+
        # if text is between pipes (box is extending from top or bottom of
        # canvas), then it is inside box
        if r and l:return F

        # CASE 6-B: Box faces right
        # if the box is riGht-facing, ex:
        # ----+
        #     |    or  ----+  etc
        # ----+            |
        if g:

            # CASE 6-B-a: Letters are left of a pipe or a + in a right facing box
            # ----+
            #  X  |   or  ----+
            # ----+         X |
            if l :return F

            # CASE 6-B-b: Letters are right of a pipe or + in a right facing box
            # ----+
            #     | X  or  ----+
            # ----+            | X
            if p or k:return T

            # CASE 6-B-c: right-facing otherwise
            # otherwise, it is a 'maybe' case
            # use an index out of bounds error to signal 'maybe'
            i[a]

        # CASE 6-C: Box faces left (or letters are on canvas yet not inside box)
        # ex:
        #   +----
        #   |        or   +---  or
        #   +----         |
        else:

            # CASE 6-C-a: Letters are right of a pipe or a + in a left facing box
            # if letters are right of pipe, they are inside box, ex:
            #   +----
            #   | X       or   +---  or X +---
            #   +----          | X        |
            if r or k:return F

            # CASE 6-C-b: Letters are left of a pipe in a left facing box
            # ex:
            #     +----
            #   X |        or     +---
            #     +----         X |

            # CASE 6-C-c: Letters are on canvas yet not left or right of
            # a pipe or a + (they must therefore be outside the box)
            # ex:
            #  |     |
            #  +-----+
            #     X
            if p:return T

            # CASE 6-C-d: text is not visible on canvas, and only part of the box is
            # ex:
            #  |     |
            #  +-----+
            #
            # this is a 'maybe' case, as text is off canvas
            # use an index out of bounds error to signal 'maybe'
            i[a]

    # CASE 7: No corners visible, nonempty input

    # CASE 7-A: No corners visible, letters sandwitched between dashes
    # ex:
    # -----
    #   X
    # -----
    # if there are no corners, yet letters are sandwitched between dashes,
    # then word is in box
    if x('-.*\s[a-z].*\s-',i):return F

    # CASE 7-B: No corners visible, letters sandwitched bewteen pipes
    # ex: |  X  |
    # in this case, word is inside box
    if x('\|.*[a-z].*\|',i):return F

    # If none of the above cases are met, it is a maybe, so throw the error
    i[a]

print z()

```

My solution assumes that the input is valid, i.e. 'Thinking' (or its substrings) are spelled correctly, there is only a single box, etc.

Edit: Saved 10 bytes thanks to @ais523's suggestion to change `c` to `i.count('+')`, 3 bytes thanks to @Pavel's suggestion of replacing `True` with `1<2` and `False` with `2>1`, 23 bytes by removing an unneeded else block, and 2 bytes by removing some spaces.

Edit 2: Saved 36 bytes thanks to @Wheat Wizard who kindly pointed out that my 'tabs' were actually 5 spaces (D'oh!) and suggested some other improvements.

# Answer
> 8 votes
# Befunge, 535 bytes

This isn't pretty, and doesn't come close to competing with the existing answers, but it's the best I could achieve in Befunge.

Returns `1` if thinking outside the box, `0` if thinking inside the box, and `-1` for *maybe*.

```
p10p20p130p140p150p9-:60p70p"~":80p90pvp8p04+1:g04p03:$p9g04+g9g\<<
0$$$$"xxxx"5p041p031p$_v#!-+55:_v#`0:~<p05+1g
v01g04$_v#*`\"|"\`"-"::<>0g\8\p"0"-!!40g1-\8\p:4-!:00g0`*!:00g\6\p40g\8\p00g!*4v
>p50g20p>8%:30g88+*+:3-v4v\-1g05!!*-"3"\-"4"::p\7\g05!!-3:+*+88g8g04:p00+g00*g0<
v!*-"3"\-"5"::p\6\g04!!<!>>7\p::"C"-\"3"-*!!50g\9\p"0"-!!50g1-\9\p:5-!:40g9g48*v
>!40g1-\6\p::"S"-\"3"-*!^>0#4g#p9#\g#94#\8#g*#0-#5!#p*#\5#70#\g#-*^#84g9g04:!*`<
>80g60g-8`90g70g-1`**+!:10g80g`60g10g`20g90g`70g20g`+++!!*\!-.@
^!g01***`"}"g09`"}"g08`g070`g060<

```

Try it online!

---
Tags: code-golf, ascii-art, classification
---


title: Sums of 24-hour time

text:
# Question
Title: Sums of 24-hour time
Given an integer between 0 and 141 (inclusive), list all 24-hour times whose hour, minute, and second units add to that integer.

**Rules of addition**

Numbers are added by their time units, not by single digits.

For example, take 17:43:59

17+43+59=119

Remember, that is an example of digits being *added.* In reality, you would enter 119, and 17:43:59 would be one of the results. Output should be given as HH:MM:SS or H:MM:SS.

Also keep in mind the highest number possible is 141, being 23:59:59. This is code golf, so the lowest amount wins. Trial and error is permitted, but there may be a better way to go about this.

Edit: Please specify where in your code the input value is.

# Answer
> 8 votes
# Jelly, ~~16~~ ~~30~~ ~~29~~ 20 bytes

Now with the correct output format! Many thanks to Dennis for his help in debugging this answer. Golfing suggestions welcome. Try it online!

**Edit:** +14 bytes from using the correct output format. -1 byte from removing an extra space. -3 from changing from `24,60,60` to `“ð<<‘`. -6 bytes from changing `+100DḊ€€` to `d⁵`.

```
“ð<<‘Œp’S=¥Ðfd⁵j€”:Y

```

**Explanation**

```
“ð<<‘Œp’S=¥Ðfd⁵j€”:Y  Main link. Argument: n

“ð<<‘                 Jelly ord() the string `ð<<` to get [24, 60, 60]. Call this list z.
     Œp               Cartesian product of z's items.
                        Since each item of z is a literal,
                        Jelly takes the range [1 ... item] for each item.
       ’              Decrements every number in the Cartesian product
                        to get lowered ranges [0 ... item-1].
        S=¥           Create a dyadic link of `sum is equal to (implicit n)`.
           Ðf         Filter the Cartesian product for items with sum equal to n.
             d⁵       By taking divmod 10 of every number in each item,
                        we get zero padding for single-digit numbers
                        and every double-digit number just turns into a list of its digits.
               j€”:   Join every number with a ':'.
                   Y  Join all of the times with linefeeds for easier reading.

```

# Answer
> 8 votes
# Bash, 71

* 8 bytes saved thanks to @hvd

```
for t in {0..23}+{00..59}+{00..59};{((${t//+0/+}-$1))||echo ${t//+/:};}

```

Try it online.

# Answer
> 6 votes
# Perl 6, ~~62~~ 56 bytes

```
{map *.fmt('%02d',':'),grep $_==*.sum,(^24 X ^60 X ^60)}

```

Just checks all possible combinations in the cross product of all hours, minutes, and seconds.

# Answer
> 4 votes
# PowerShell, ~~87~~ 77 bytes

Saved 10 bytes thanks to John L. Bevan

```
$d=date;0..86399|%{$d+=1e7l;"$d".Split()[1]}|?{("{0:H+m+s}"-f$d|iex)-in$args}

```

Try it online! (this will time out, it's very slow)

### Explanation

Pretty simple, starting with the current `[datetime]`, add 1 second 86,399 times, format as a string, then keep only the ones where sum adds up.

# Answer
> 4 votes
# Python 3, 91 bytes

```
def f(n):
 for k in range(86400):t=k//3600,k//60%60,k%60;sum(t)==n!=print('%d:%02d:%02d'%t)

```

There are shorter solutions using `exec` (Python 2) or recursion (Python 3), but both require an unreasonable amount of memory.

Try it online!

# Answer
> 3 votes
## Haskell, 77 bytes

```
f x=[tail$(':':).tail.show.(+100)=<<t|t<-mapM(\x->[0..x])[23,59,59],sum t==x]

```

# Answer
> 2 votes
## Haskell, 90 bytes

```
p x=['0'|x<10]++show x
i=[0..59]
f x=[p h++':':p m++':':p s|h<-[0..23],m<-i,s<-i,h+m+s==x]

```

Returns a list of HH:MM:SS strings, e.g. `f 140` -\> `["22:59:59","23:58:59","23:59:58"]`.

It's three simple loops through the hours, minutes and seconds. Keep and format all values where the sum is the input number `x`.

# Answer
> 2 votes
# Pyth - 30 bytes

Takes all possible times then filters.

```
mj\:%L"%02d"dfqsTQsM*U24*KU60K

```

Test Suite.

# Answer
> 2 votes
# Julia 0.5, 69 bytes

```
!n=[h+m+s==n&&@printf("%d:%02d:%02d
",h,m,s)for s=0:59,m=0:59,h=0:23]

```

Try it online!

# Answer
> 2 votes
## Batch, 168 bytes

```
@for /l %%t in (0,1,86399)do @call:c %1 %%t
@exit/b
:c
@set/ah=%2/3600,m=%2/60%%60,s=%2%%60,n=%1-h-m-s
@set m=0%m%
@set s=0%s%
@if %n%==0 echo %h%:%m:~-2%:%s:~-2%

```

Outputs single-digit hours.

# Answer
> 2 votes
## Mathematica, 79 bytes

```
Cases[Tuples@{(r=Range)@24-1,x=r@60-1,x},t_/;Tr@t==#:>DateString@TimeObject@t]&

```

# Answer
> 1 votes
# Octave, ~~83~~ , 87 bytes

```
@(a){[H,M,S]=ndgrid(0:23,s=0:59,s);printf("%d:%02d:%02d\n",[H(x=H+M+S==a),M(x),S(x)]')}

```

Try it Online!

# Answer
> 1 votes
## QBIC, ~~82~~ 72 bytes

```
:[0,23|[0,59|[0,59|~b+c+d=a|?!b$+@:`+right$(@0`+!c$,2)+A+right$(B+!d$,2)

```

This hits an unfortunate spot in QBasic, with casting to number, trimming and prepending a `0` when necessary is really costly.

Sample output:

```
Command line: 119
1:59:59
2:58:59
2:59:58
3:57:59
[... SNIP 270 lines ...]
23:58:38
23:59:37

```

~~Explanation~~ I wrote a novel about it:

```
:           Get N, call it 'a'
[0,23|      Loop through the hours; this FOR loop is initialised with 2 parameters
            using a comma to separate FROM and TO, and a '|' to delimit the argument list
[0,59|      Same for the minutes
[0,59|      And the seconds
            QBIC automatically creates variables to use as loop-counters:
            b, c, d (a was already taken by ':')
~b+c+d=a    IF a == b+c+d
|           THEN
 ?          PRINT
  !         CAST
   b        'b'
    $       To String; casting num to str in QBasic adds a space, this is trimmed in QBIC
+@:`        Create string A$, containing ":"
+right$      This is a QBasic function, but since it's all lowercase (and '$' is
            not a function in QBIC) it remains unaltered in the resulting QBasic.
(@0`+!c$,2) Pad the minutes by prepending a 0, then taking the rightmost 2 characters.
+A          Remember that semicolon in A$? Add it again
+right$     Same for the seconds
(B+!d$,2)   Reusing the 0-string saves 2 bytes :-)

```

# Answer
> 1 votes
# PowerShell, 67 ~~79~~ Bytes (nasty version)

Since the rules say nothing about completing in a certain time (or at all), and nothing about no duplicates, here's a horrific solution:

```
for(){if(("{0:H+m+s}"-f($d=date)|iex)-in$args){"{0:H:mm:ss}"-f$d}}

```

# Answer
> 0 votes
# PowerShell, 91 ~~97~~ bytes (including input)

```
param($x)1..864e3|%{($d=date($_*1e7l))}|?{("{0:H+m+s}"-f$_|iex)-eq$x}|%{"{0:H:mm:ss}"-f$_}

```

~~`param($x)0..23|%{$h=$_;0..59|%{$m=$_;0..59|?{$h+$m+$_-eq$x}|%{"{0:0}:{1:00}:{2:00}"-f$h,$m,$_}}}`~~

or

`param($x)0..23|%{$h=$_;0..59|?{($s=$x-$h-$_)-le59-and$s-ge0}|%{"{0:0}:{1:00}:{2:00}"-f$h,$_,$s}}` \<\s\>

Expanded & commented

```
param($x)
#loop through the hours
0..23 | %{
    $h=$_
    #loop through the minutes
    0..59 | %{
        $m=$_
        #loop through the seconds
        0..59 | ?{ #filter for those where the sum matches the target
            $h + $m + $_ -eq $x
        } | %{
            #format the result
            "{0:#0}:{1:00}:{2:00}" -f $h, $m, $_
        }
    }
}

```

NB: Surpassed by @Briantist's version: https://codegolf.stackexchange.com/a/105163/6776

# Answer
> 0 votes
# JavaScript, ~~122~~ 120 bytes

Takes one additional empty string as input, ~~which I presume doesn't count towards the size~~. *Updated bytecount (including historical) to add two bytes for the string's initialization.*

```
console.log((
//Submission starts at the next line
i=>o=>{for(h=24;h--;)for(m=60;m--;)for(s=60;s--;)if(h+m+s==i)o+=`${h}:0${m}:0${s} `;return o.replace(/0\d{2}/g,d=>+d)}
//End submission
)(prompt("Number:",""))(""))
```

# Answer
> 0 votes
## Racket 39 bytes

```
(for*/sum((h 24)(m 60)(s 60))(+ h m s))

```

Ungolfed:

```
(for*/sum      ; loop for all combinations; return sum of values for each loop
   ((h 24)     ; h from 0 to 23
    (m 60)     ; m from 0 to 59
    (s 60))    ; s from 0 to 59
  (+ h m s))   ; sum of all 3 variables

```

# Answer
> 0 votes
# MATL, 29 bytes

```
24:q60:qt&Z*t!si=Y)'%i:'8:)&V

```

Try it online!

### Explanation

```
24:q     % Push [0 1 ... 23]
60:q     % Push [0 1 ... 59]
t        % Duplicate
&Z*      % Cartesian product of the three arrays. This gives a matrix with each
         % on a different row Cartesian tuple
t!       % Push a transposed copy
s        % Sum of each column
i=       % Logical mask of values that equal the input
Y)       % Select rows based on that mask
'%i:'    % Push this string
8:)      % Index (modularly) with [1 2 ... 8]: gives string '%i:%i:%i'
&V       % Convert to string with that format specification. Implicitly display

```

# Answer
> 0 votes
# JavaScript (ES6), 110

```
v=>eval("o=[];z=x=>':'+`0${x}`.slice(-2);for(m=60;m--;)for(s=60;s--;h>=0&h<24&&o.push(h+z(m)+z(s)))h=v-m-s;o")

```

*Less golfed*

```
v=>{
  o=[];
  z=x=>':' + `0${x}`.slice(-2);
  for(m = 60; m--;)
    for(s = 60; s--; )
      h = v - m - s,
      h >= 0 & h < 24 && o.push(h + z(m) + z(s))
  return o
}

```

**Test**

```
F=
v=>eval("o=[];z=x=>':'+`0${x}`.slice(-2);for(m=60;m--;)for(s=60;s--;h>=0&h<24&&o.push(h+z(m)+z(s)))h=v-m-s;o")

function update() {
  O.textContent=F(+I.value).join`\n`
}

update()
```

```
<input id='I' value=119 type=number min=0 max=141 oninput='update()'><pre id=O></pre>
```

# Answer
> 0 votes
# JavaScript, 96 bytes

```
v=>{for (i=86399;i;[a,b,c]=[i/3600|0,i%3600/60|0,i--%60]){v-a-b-c?0:console.log(a+":"+b+":"+c)}}

```

Expanded view:

```
v => {
    for (i = 86399; i;
        [a, b, c] = [i / 3600 | 0, i % 3600 / 60 | 0, i-- % 60]) {
        v - a - b - c ? 0 : console.log(a + ":" + b + ":" + c)
    }
}

```

Loop through all possible times by looping 86399 to 1,

* convert the integer to time by dividing by 3600 to get the first digit
* the 2nd digit by taking the integer mod 3600 and then dividing by 60
* and the last digit is the integer mod 60

Subtract all 3 numbers from the input value to return a falsey value if the three numbers add up to the input value. If the value is falsey, output the value.

# Answer
> 0 votes
# bash, 78 bytes (using a BSD utility) or 79 bytes (non-BSD also)

This is a little longer than @DigitalTrauma and @hvd's nice 71-byte bash solution, but I kind of liked the idea here of using numbers in base 60; I'm curious if anybody can golf this down a little more.

With the BSD-standard jot utility:

```
jot '-wx=`dc<<<60do3^%d+n`;((`dc<<<$x++'$1'-n`))||tr \  :<<<${x:3}' 86400 0|sh

```

With the more universally available seq utility:

```
seq '-fx=`dc<<<60do3^%.f+n`;((`dc<<<$x++'$1'-n`))||tr \  :<<<${x:3}' 0 86399|sh

```

The idea is to generate the numbers from 0 to 83699 and use dc to convert them into base 60. The "digits" in dc's base-60 output are 2-digit numbers from 00 to 59, with spaces separating the "digits", so this lists all the desired times from 00 00 00 to 23 59 59 in almost the format needed.

If you literally carry that out, though, numbers below 60^2 aren't 3-digit numbers in base 60, so the initial 00 or 00 00 is missing. For that reason, I'm actually generating the numbers from 60^3 to 60^3+83699; this ensures that all the numbers generated are exactly 4 digits long in base 60. This is OK as long as I eventually throw away the extra first digit (01) that isn't needed.

So, once the desired times are generated, I just take each quadruple from 01 00 00 00 to 01 23 59 59, add the last three numbers and subtract the argument $1. If that's 0, I then take everything in the quadruple from the 3rd character on (throwing away the "01 "), use tr to convert spaces to colons, and print the result.

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


title: Arnold's Cat Map

text:
# Question
Title: Arnold's Cat Map
### Challenge

Given a colour raster image\* with the same width and height, output the image transformed under *Arnold's cat map*. (\*details see below)

### Definition

Given the size of the image `N` we assume that the coordinates of a pixel are given as numbers between `0` and `N-1`.

*Arnold's cat map* is then defined as follows:

A pixel at coordinates `[x,y]` is moved to `[(2*x + y) mod N, (x + y) mod N]`.

This is nothing but a linear transform on torus: The yellow, violet and green part get mapped back onto the initial square due to the `mod N`.

This map (let's call it `f`) has following properties:

* It is *bijective*, that means reversible: It is a linear transformation with the matrix `[[2,1],[1,1]]`. Since it has determinant `1` and and it has only integer entries, the inverse also has only integer entries and is given by `[[1,-1],[-1,2]]`, this means it is also bijective on integer coordinates.
* It is a *torsion* element of the group of bijective maps of `N x N` images, that means if you apply it sufficiently many times, you will get the original image back: `f(f(...f(x)...)) = x` The amount of times the map applied to itself results in the identity is guaranteed to be less or equal to `3*N`. In the following you can see the image of a cat after a given number of iterated applications of *Arnold's cat map*, and an animation of what a repeated application looks like:

### Details

* Your program does not necessarily have to deal with images, but 2D-arrays/matrices, strings or similar 2D-structures are acceptable too.
* It does not matter whether your `(0,0)` point is on the bottom left or on the top left. (Or in any other corner, if this is more convenient in your language.) **Please specify what convention you use in your submission.**

### Testcases

In matrix form (`[1,2,3,4]` is the top row, `1` has index `(0,0)`, `2` has index `(1,0)`, `5` has index `(0,1)`)

```
 1     2     3     4
 5     6     7     8
 9    10    11    12
13    14    15    16

maps to:

 1    14    11     8
12     5     2    15
 3    16     9     6
10     7     4    13

 --------------------

 1     2     3
 4     5     6
 7     8     9

 map to:

 1     8     6
 9     4     2
 5     3     7

```

As image (bottom left is `(0,0)`):

# Answer
# Jelly, 9 bytes

```
Zṙ"JC$µ2¡

```

Try it online! The coordinates are as in the answer.

## Explanation

```
      µ2¡   Twice:
Z             Transpose, then
 ṙ"           Rotate rows left by
   JC$          0, -1, -2, -3, …, 1-n units.

```

This wrap-shears the matrix in one direction, then the other.
> 10 votes

# Answer
# MATL, 23 bytes

```
tt&n:qt&+&y\tb+&y\b*+Q(

```

The `(0,0)` point is upper left, as in the examples in the challenge text.

Try it online!

### Explanation

A matrix in MATL can be indexed with a single index instead of two. This is called **linear indexing**, and uses **column-major** order. This is illustrated by the following 4×4 matrix, in which the value at each entry coincides with its linear index:

```
1   5   9  13
2   6  10  14
3   7  11  15
4   8  12  16

```

There are two similar approaches to implement the mapping in the challenge:

1. Build an indexing matrix that represents Arnold's **inverse mapping** on linear indices, and use it to **select** the values from the original matrix. For the 4×4 case, the indexing matrix would be

```
 1  8 11 14
15  2  5 12
 9 16  3  6
 7 10 13  4

```

telling that for example the original `5` at *x*=2, *y*=1 goes to *x*=3, *y*=2. This operation is called **reference indexing**: use the indexing matrix to tell which element to pick from the original matrix. This is functon `)`, which takes two inputs (in its default configuration).
2. Build an indexing matrix that represents Arnold's **direct mapping** on linear indices, and use it to **write** the values into the original matrix. For the 4×4 case, the indexing matrix would be

```
 1 10  3 12
 6 15  8 13
11  4  9  2
16  5 14  7

```

telling that the entry *x*=2, *y*=1 of the new matrix will be overwritten onto the entry with linear index `10`, that is, *x*=3, *y*=2. This is called **assignment indexing**: use the indexing matrix, a data matrix and the original matrix, and write the data onto the original matrix at the specified indices. This is function `(`, which takes three inputs (in its default configuration).

Method 1 is more straightforward, but method 2 turned out to be shorter.

```
tt     % Take the input implicitly and push two more copies
&n     % Get its size as two (equal) numbers: N, N
:qt    % Push range [0  1 ... N-1] twice. This represents the original x values
&+     % Matrix of all pairwise additions. This represents x+y
&y     % Push a copy of N onto the top of the stack
\      % Modulo. This is the new y coordinate: y_new
t      % Push another copy
b+     % Bubble up the remaining copy of [0 1 ... N-1] and add. This is 2*x+y
&y     % Push a copy of N onto the top of the stack
\      % Modulo. This is the new x coordinate: x_new
b*+    % Bubble up the remaining copy of N, multiply, add. This computes
       % x_new*N+y_new, which is the linear index for those x_new, y_new
Q      % Add 1, because MATL uses 1-based indexing
(      % Assigmnent indexing: write the values of the original matrix into
       % (another copy of) the original matrix at the entries given by the
       % indexing matrix. Implicitly display the result

```
> 9 votes

# Answer
# Mathematica, 44 bytes

```
(n=MapIndexed[RotateLeft[#,1-#2]&,#]&)@*n

```

A port of Lynn's fantastic algorithm. There's an invisible 3-byte character, U+F3C7 in the UTF-8 encoding, before the last `]`; Mathematica renders it as a superscript `T`, and it takes the transpose of a matrix.

# Mathematica, 54 bytes

```
Table[#2[[Mod[2x-y-1,#]+1,Mod[y-x,#]+1]],{x,#},{y,#}]&

```

Unnamed function taking two arguments, a positive integer `#` and a 2D array `#2` of dimensions `#`x`#`, and returning a 2D array of similar shape. As in the given test case, the point with coordinates {0,0} is in the upper left and the x-axis is horizontal. Straightforward implementation using the inverse `[[1,-1],[-1,2]]` mentioned in the question, with a `-1` in the first coordinate to account for the fact that arrays are inherently 1-indexed in Mathematica. If we're not allowed to take the dimension of the matrix as an additional argument, then this solution becomes nine bytes longer (replace the first `#`—not the `#2`—with `a=Length@#` and all the subsequent `#`s with `a`s).
> 5 votes

# Answer
## Python 2, ~~89~~ ~~82~~ ~~77~~ 73 bytes

```
def f(a):exec'a=[l[-i:]+l[:-i]for i,l in enumerate(zip(*a))];'*2;return a

```

Input is a list of lists
The string inside the exec transpose the list of lists and cyclically rotate each list by the line index (0 based - 3rd line is rotated 2 times to the right).
This process is done 2 times to the input.

### +4 bytes that will do the transformation N times

```
def f(a,n):exec'a=[l[-i:]+l[:-i]for i,l in enumerate(zip(*a))];'*2*n;return a

```
> 3 votes

# Answer
## Haskell, 55 bytes

```
m#n|r<-[0..n-1]=[[m!!mod(2*y-x)n!!mod(x-y)n|x<-r]|y<-r]

```

Usage example: `[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]] # 4` -\> `[[1,14,11,8],[12,5,2,15],[3,16,9,6],[10,7,4,13]]`.

`0,0` is the upper left corner. This uses the inverse transformation.
> 2 votes

# Answer
# ImageJ macro, 29 bytes

```
v=getPixel((x+y)%w,(2*y+x)%h)

```
* Open image of Lena
* From Process menu select Math / Macro...
> 1 votes

# Answer
## Python, 69 bytes

```
lambda M:eval("[r[-i:]+r[:-i]for i,r in enumerate(zip(*"*2+"M))]))]")

```

An improvement on Rod's transpose-and-shift-twice method. Applies the operation `M -> [r[-i:]+r[:-i]for i,r in enumerate(zip(*M))]` twice by creating and evaluating the string

```
[r[-i:]+r[:-i]for i,r in enumerate(zip(*[r[-i:]+r[:-i]for i,r in enumerate(zip(*M))]))]

```

This narrowly beats out a direct transformation (70 bytes), assuming the image is square and its length can be taken as input:

```
lambda M,n:[[M[(2*j-i)%n][(i-j)%n]for i in range(n)]for j in range(n)]

```
> 1 votes

# Answer
# Java, 160

Golfed:

```
int[][]f(int[][]m){int x=0,y,l=m.length,r[][]=new int[l][];for(;x<l;++x)r[x]=new int[l];for(x=0;x<l;++x)for(y=0;y<l;++y)r[(x+y)%l][(2*x+y)%l]=m[y][x];return r;}

```

Ungolfed:

```
  int[][] f(int[][] m) {
    int x = 0, y, l = m.length, r[][] = new int[l][];
    for (; x < l; ++x) {
      r[x] = new int[l];
    }
    for (x = 0; x < l; ++x) {
      for (y = 0; y < l; ++y) {
        r[(x + y) % l][(2 * x + y) % l] = m[y][x];
      }
    }
    return r;
  }

```
> 0 votes

---
Tags: code-golf, graphical-output, image-processing, linear-algebra, repeated-transformation
---