title: Count without 3

text:
# Question
Title: Count without 3
### Background

When I was in elementary school, we used to play a game in math class that goes as follows.

All kids sit in a big circle and take turns counting, starting from **1**.

However, the following numbers must be skipped while counting:

* Numbers that are multiples of **3**.
* Numbers that have a **3** in its decimal representation.

The first 15 numbers the kids should say are

```
1 2 4 5 7 8 10 11 14 16 17 19 20 22 25

```

Whenever somebody gets a number wrong – says a number that isn't in the sequence or skips a number that is – he's removed from the circle. This goes on until there's only one kid left.

### Task

You're bad at this game, so you decide to cheat. Write a program or a function that, given a number of the sequence, calculates the next number of the sequence.

You don't have to handle numbers that cannot be represented using your language's native numeric type, provided that your program works correctly up to input **251** and that your algorithm works for arbitrarily large inputs.

Input and output can use any convenient base.

Since you have to conceal your code, it must be as short as possible. In fact, this is , so the shortest code in bytes wins.

### Test cases

```
  1 ->   2
  2 ->   4
 11 ->  14
 22 ->  25
 29 ->  40
251 -> 254

```

# Answer
# Brachylog, 10 bytes

```
<.='e3:I'*

```

Try it online!

### Explanation

```
(?)<.                Output > Input
    .=               Assign a value to the Output
    . 'e3            3 cannot be an element of the Output (i.e. one of its digits)
        3:I'*(.)     There is no I such that 3*I = Output

```
> 25 votes

# Answer
# JavaScript (ES6), 30 bytes

```
f=n=>++n%3*!/3/.test(n)?n:f(n)

```
> 15 votes

# Answer
# J, 24 bytes

```
3(]0&({$:)~e.&":+.0=|)>:

```

Straight-forward approach that just iterates forward from input *n* until it finds the next number that is valid by the rules.

Forms five smileys, `$:`, `:)`, `0=`, `=|`, and `>:`.

## Usage

```
   f =: 3(]0&({$:)~e.&":+.0=|)>:
   (,.f"0) 1 2 11 22 29 251
  1   2
  2   4
 11  14
 22  25
 29  40
251 254

```

## Explanation

```
3(]0&({$:)~e.&":+.0=|)>:  Input: integer n
                      >:  Increment n
3                         The constant 3
 (                   )    Operate dyadically with 3 (LHS) and n+1 (RHS)
                    |       Take (n+1) mod 3
                  0=        Test if equal to 0
             &":            Format both 3 and n+1 as a string
           e.               Test if it contains '3' in str(n+1)
                +.          Logical OR the results from those two tests
  ]                         Right identity, gets n+1
   0&(   )~                 If the result from logical OR is true
       $:                     Call recursively on n+1
      {                       Return that as the result
                            Else act as identity function and return n+1

```
> 9 votes

# Answer
## Python 2, 73 66 43 bytes

Thanks to xnor for telling me I was being silly by using 2 variables, and thanks to Mitch Schwartz too.

```
x=~input()
while'3'[:x%3]in`x`:x-=1
print-x

```
> 8 votes

# Answer
## Perl, 19 bytes

**18 bytes code + 1 for `-p`.**

```
++$_%3&&!/3/||redo

```

### Usage

```
perl -pe '++$_%3&&!/3/||redo' <<< 8
10

perl -pe '++$_%3&&!/3/||redo' <<< 11
14

```
> 8 votes

# Answer
# 05AB1E, 11 bytes

```
[>Ð3ås3Ö~_#

```

Try it online!

**Explanation**

```
               # implicit input
[              # start loop
 >             # increase current number
  Ð            # triplicate
          #    # break loop IF
         _     # logical negation of
   3å          # number has one or more 3's in it
        ~      # OR
     s3Ö       # number % 3 == 0

```
> 7 votes

# Answer
# Java 8, ~~57~~ ~~56~~ ~~55~~ 50 bytes

*Thanks to @Numberknot for 1 byte* *Thanks to @Kevin Cruijssen for 5 bytes*

```
i->{for(;++i%3<1|(i+"").contains("3"););return i;}

```

This is a `Function<Integer, Integer>`

**Explanation**

Naive implementation that simply increments until it reaches an acceptable number.

**Test Class**

```
public class CodeGolf {

    public static void main(String[] args) {
        Function<Integer, Integer> countingGame = i->{for(;++i%3<1|(i+"").contains("3"););return i;};
        int val = 1;
        for (int i = 0; i < 10; i++) {
            System.out.print(val + " ");
            val = countingGame.apply(val);
        }
    }

}

```

Output of Test Class:

```
1 2 4 5 7 8 10 11 14 16

```
> 6 votes

# Answer
# Python 2, ~~49~~ ~~44~~ 42 bytes

```
f=lambda x:'3'[:~x%3]in`~x`and f(x+1)or-~x

```

The other Python entry beats this (edit: not any more :-D), but I posted it because I rather like its recursive approach. Thanks to Mitch Schwarz and Erik the Golfer for helping me make this shorter.
> 6 votes

# Answer
# Japt, 18 bytes

```
°U%3*!Us f'3 ?U:ßU

```

**Test it online**

I finally have a chance to use `ß` :-)

### How it works

```
                    // Implicit: U = input integer
°U%3                // Increment U, and take its modulo by 3.
     !Us f'3        // Take all matches of /3/ in the number, then take logical NOT.
                    // This returns true if the number does not contain a 3.
    *               // Multiply. Returns 0 if U%3 === 0  or the number contains a 3.
             ?U     // If this is truthy (non-zero), return U.
               :ßU  // Otherwise, return the result of running the program again on U.
                    // Implicit: output last expression

```
> 5 votes

# Answer
## PowerShell v2+, 46 bytes

```
for($a=$args[0]+1;$a-match3-or!($a%3)){$a++}$a

```

Takes input `$args[0]`, adds `1`, saves into `$a`, starts a `for` loop. The conditional keeps the loop going while either `$a-match3` (regex match) `-or` `$a%3` is zero (the `!` of which is `1`). The loop simply increments `$a++`. At the end of the loop, we simply place `$a` on the pipeline, and output via implicit `Write-Output` happens at program completion.

### Examples

```
PS C:\Tools\Scripts\golfing> 1,2,11,22,29,33,102,251,254|%{"$_ --> "+(.\count-without-three.ps1 $_)}
1 --> 2
2 --> 4
11 --> 14
22 --> 25
29 --> 40
33 --> 40
102 --> 104
251 --> 254
254 --> 256

```
> 5 votes

# Answer
# R, 46 bytes

```
n=scan()+1;while(!n%%3|grepl(3,n))n=n+1;cat(n)

```
> 4 votes

# Answer
# Haskell, ~~50~~ 48 bytes

```
f n=[x|x<-[n..],mod x 3>0,notElem '3'$show x]!!1

```

Try it on Ideone. Saved 2 bytes thanks to @Charlie Harding.

Alternative: (50 bytes)

```
g=f.(+1)
f n|mod n 3<1||(elem '3'.show)n=g n|1<3=n

```
> 4 votes

# Answer
# Labyrinth, 117 102 bytes

```
?       """""""""""_
):_3    (         0/{!@
;  %;:}_';:_3-_10 1
"  1            %;_
""""_""""""""{;;'

```

Try it online!

Labyrinth is a two-dimensional, stack-based programming language and at junctions, direction is determined by the top of the stack (positive goes right, negative goes left, zero goes straight). There are two main loops in this programs. The first mods the integer input by 3 and increments if 0. The second repeatedly checks if the last digit is 3 (by subtracting 3 and modding by 10) and then dividing by 10 to get a new last digit.
> 4 votes

# Answer
# Lua, 58 Bytes

```
i=...+1while(i%3==0or(i..""):find"3")do i=i+1 end print(i)

```
> 3 votes

# Answer
## Pyke, 13 bytes

```
Whii3%!3`i`{|

```

Try it here!

```
              - i = input
W             - do:
 hi           -  i += 1
   i3%!       -    not (i % 3)
            | -   ^ or V
       3`i`{  -    "3" in str(i)
              - while ^

```
> 3 votes

# Answer
# C#, ~~56~~, 51 bytes.

This is surprisingly short for a C# answer!

```
x=>{while(++x%3<1|(x+"").Contains("3"));return x;};

```
> 3 votes

# Answer
# Pyth, 11 bytes

```
f&-I`T3%T3h

```

Try it online: Demonstration or Test Suite

### Explanation:

```
f&-I`T3%T3hQ   implicit Q at the end
f         hQ   find the smallest integer T >= input + 1 which fulfills:
  -I`T3           T is invariant under removing the digit 3
 &                and
       %T3        T mod 3 leaves a positive remainder

```
> 3 votes

# Answer
# Excel, ~~79~~ 66 bytes

It Taylor Rained 13 bytes

```
=MIN(LET(r,ROW(A:A),FILTER(r,ISERR(FIND(3,r))*MOD(r,3)*(r>A1)>0)))

```

Input is in the cell `A1`. Output is wherever the formula is.

The `LET()` function allows you to define variables for later reference so ti works in pairs of `variable,value`. The last argument is unpaired as it is the output.

* `r,ROW(A:A)` creates an array of 1 to whatever the last row is. In the latest version of Excel, that's 1,048,576.
* `g,FILTER(r,~*~*~>0)` takes that array and filters just for the values that aren't multiples of 3 and don't have a 3 in them. This done is by multiplying:
    + `ISERR(FIND(3,r))` which returns TRUE if if a 3 is *not* in the number and FALSE if it *is*
    + `MOD(r,3)` which returns 0 if it's a multiple of 3 and some positive integer if it isn't
    + `(r>A1)` creates an array of TRUE / FALSE where the first TRUE value will be the first term that's larger than the input.
    + When you do math on booleans, Excel uses TRUE=1 and FALSE=0 so the formula `~*~*~>0` only returns TRUE when the three pieces are TRUE (no 3 in number), some positive integer (not a multiple of 3), and TRUE (larger than the input).
* `MIN(LET(~))` finds the smallest value in the filtered array which only includes the "without 3" numbers larger than the input so the first value in the array is the next value in the sequence.
> 3 votes

# Answer
# Python 3, 49 48 bytes

-3 bytes thx to The Thonnu, I missed some spaces and swapping else x+1 and else-~x allowed another space to be taken out, not

+2 bytes bc I didn't know I need to count f= on a recursive function, thx xnor :)

seems clunky but i cant see more golfs, please lmk if you see something!

```
f=lambda x:f(x+1)if x%3>1or'3'in str(x+1)else-~x

```

Try it online!
> 3 votes

# Answer
## GolfSharp, 43 bytes

```
m=>r(m,m).w(n=>n%3>0&!n.t().I("3")).a()[1];

```
> 2 votes

# Answer
# PHP, ~~60~~ ~~55~~ ~~54~~ 46 bytes

Thanks to @user59178 for shaving off a few bytes, @AlexHowansky for a byte, @Titus for another few bytes

```
for(;strstr($i=++$argv[1],51)|$i%3<1;);echo$i;

```

Called from command line with `-r`. Naive method that loops while the number is a multiple of 3, or has 3 in its digits.
> 2 votes

# Answer
# Ruby, 47 bytes

```
i=gets.to_i;i while(i+=1)%3==0||"#{i}"=~/3/;p i

```

I really feel like this can be golfed further.
> 2 votes

# Answer
# MATL, 14 bytes

```
`Qtt3\wV51-hA~

```

Try it online!

### Explanation

```
`       % Do...while
  Q     %   Add 1. Takes input implicitly in the first iteration
  tt    %   Duplicate twice
  3\    %   Modulo 3
  wV    %   Swap, string representation
  51-   %   Subtract 51, which is ASCII for '3'
  h     %   Concatenate
  A~    %   True if any result was 0. That indicates that the number
        %   was a multiple of 3 or had some '3' digit; and thus a
        %   new iteration is needed

```
> 2 votes

# Answer
# PHP, ~~47~~ 41 bytes

inspired by Xanderhall, but the latest idea finally justifies an own answer.

```
while(strstr($n+=$n=&$argn%3,51));echo$n;

```

or

```
while(strpbrk($n+=$n=&$argn%3,3));echo$n;

```

This takes advantage from the fact that the input is also from the sequence: For `$n%3==1`, the new modulo is `2`. For `$n%3==2`, the new modulo is `4-3=1`. `$n%3==0` never happens.

Run as pipe with `-R` or try them online.
> 2 votes

# Answer
# Jelly, 11 bytes

```
D;Æf3ḟµ‘#2ị

```

Try it online!

### How it works

```
D;Æf3ḟµ‘#2ị  Main link. Argument: n

      µ      Combine the links to the left into a chain.
       ‘#    Execute the chain for k = n, n + 1, n + 2, ... until n + 1 matches
             were found. Yield the array of all n + 1 matches.
D            Decimal; yield the array of k's decimal digits.
  Æf         Yield the array of k's prime factors.
 ;           Concatenate both.
    3ḟ       Filter false; remove digits and factors from [3].
             This yields [3] (truthy) if neither digits nor factors contain 3,
             [] (falsy) if they do.
         2ị  Extract the second match. (The first match is n.)

```
> 2 votes

# Answer
# Perl 6, ~~27 25~~ 24 bytes

```
{max $_+1...{!/3/&$_%3}}

```

Try it online!

Finds the first number larger than the input that doesn't have a three and has a remainder when moduloed by 3. I was hoping to do something fancy with the condition, like `!/3/&*%3` but it doesn't work with the `!`. `:(`

### Explanation:

```
{                      }   # Anonymous code block
     $_+1                  # From the input+1
         ...               # Get the series
            {         }    # That ends when
             !/3/            # The number does not contain a 3
                 &           # and
                  $_%3       # The number is not divisible by 3
 max                       # And get the last element of the series

```
> 2 votes

# Answer
# Turing Machine Code, 390 bytes

```
0 * * r 0
0 _ _ l 1
1 1 2 l 2
1 2 3 r 0
1 3 4 l 2
1 4 5 l 2
1 5 6 l 2
1 6 7 l 2
1 7 8 l 2
1 8 9 l 2
1 9 0 l 1
1 * 1 l 2
2 * * l 2
2 _ _ r 3
3 1 1 r 4
3 4 4 r 4
3 7 7 r 4
3 2 2 r 5
3 5 5 r 5
3 8 8 r 5
3 _ _ l 1
4 1 1 r 5
4 4 4 r 5
4 7 7 r 5
4 2 2 r 3
4 5 5 r 3
4 8 8 r 3
5 1 1 r 3
5 4 4 r 3
5 7 7 r 3
5 2 2 r 4
5 5 5 r 4
5 8 8 r 4
* 0 0 r *
* 6 6 r *
* 9 9 r *
* 3 3 r 0
* _ _ * halt

```

Try it online.
> 2 votes

# Answer
# APL (Dyalog Unicode), ~~33~~ ~~28~~ ~~27~~ 19 bytesSBCS

```
1∘+⍣{('3'∊⍕⍺)<×3|⍺}

```

Try it online!

-6 thanks to Adám. -8 thanks to ngn.

Old Explanation:

```
1-⍨g⍣((×3|⊢)>'3'∊⍕)∘(g←+∘1)
                       +∘1  ⍝ curry + with 1, gives the increment function
                            ⍝ increments the left argument so we do not return the number itself
                    (g←   ) ⍝ assign to "g"
                   ∘        ⍝ compose g with the repeat
                 ⍕          ⍝ does parsing the argument to a string...
             '3'∊           ⍝ ...contain '3'?
        3|⊢                 ⍝ residue of a division by 3
      (×   )                ⍝ direction (0 if 0, 1 if greater, ¯1 is lower)
     (      >     )         ⍝ and not (we want the left side to be 1, the right side 0)
   g⍣                       ⍝ repeat "g" (increment) until this function is true ^
1-⍨                         ⍝ afterwards, decrement: inversed -

```

# APL (Dyalog Extended), ~~23~~ 17 bytesSBCS

```
1∘+⍣(3(×⍤|>∊⍥⍕)⊣)

```

Try it online!

Thanks to Adám. -6 thanks to ngn.

Old Explanation:

```
0+⍣(3(×⍤|>∊⍥⍕)⊢)⍢(1+⊢)⊢
0                       ⍝ the left argument (⍺)
 +⍣(3(×⍤|>∊⍥⍕)⊢)        ⍝ the left function (⍺⍺)
                 (1+⊢)  ⍝ the right function (⍵⍵)
                        ⍝     (increments its argument)
                      ⊢ ⍝ the right argument (⍵)
                        ⍝     (just returns the input)
                ⍢       ⍝ under:
                        ⍝     calls (⍵⍵ ⍵) first, which increments the input
                        ⍝     also (⍵⍵ ⍺) which gives 1
                        ⍝     then calls (⍺incremented ⍺⍺ ⍵incremented)
                        ⍝     afterwards, does the opposite of ⍵⍵, and decrements the result
  ⍣                     ⍝ ⍣ fixpoint: repeats the left operation until the right side is truthy
 +                      ⍝ calls + with ⍺incremented and the input (so, 1+input)
   (3(×⍤|>∊⍥⍕)⊢)        ⍝ right operation
    3                   ⍝ on its left, "3"
              ⊢         ⍝ on its right, the current iteration
      ×⍤|               ⍝ divisibility check: × atop |
        |               ⍝     starts with 3|⊢ (residue of ⊢/3)
      ×                 ⍝     then returns the direction (0 if 0, 1 if greater, ¯1 is lower)
          ∊⍥⍕           ⍝ contains 3:
            ⍕           ⍝    stringifies both its arguments (3 and ⊢)
          ∊⍥            ⍝    checks for membership
         >              ⍝ divisibility "and not" contains 3

```
> 2 votes

# Answer
# APOL, 51 bytes

`v(0 +(⧣ 1));w(|(!(%(⁰ 3)) c(t(⁰) '3')) ∆(0));-(⁰ 1)`
> 2 votes

# Answer
# Swift, 84 bytes

```
func f(_ n:Int)->Int{var n=n+1;while String(n).contains("3")||n%3==0{n+=1};return n}

```
> 2 votes

# Answer
# C, 81 bytes

```
f(int n){int m;l:if(++n%3){for(m=n;m>0;m/=10)if(m%10==3)goto l;return n;}goto l;}

```
> 1 votes

# Answer
# reticular, 30 bytes

```
in v
?v$>1+d3,qds:3@cQm*
;\$o

```

Try it online!

## Explanation

### 1: initialization

```
in v

```

This converts the `i`nput to a `n`umber, then goes down (`v`)

### 2: loop

```
?v$>1+d3,qds:3@cQm*
   >                 go right!              [n]
    1+               add 1                  [n+1]
      d3,            duplicate and mod 3    [n+1, (n+1)%3]
         qd          reverse and duplicate  [(n+1)%3, n+1, n+1]
           s         cast to string         [(n+1)%3, n+1, `n+1`]
            :3@c     count numbers of "3"   [(n+1)%3, n+1, `n+1`.count(3)]
                Qm*  negate and rotate      [n+1, continue?]
?v                   terminate if continue
  $                  drop continue

```

### 3: final

```
;\$o
 \$o  drop and output
;     terminate

```
> 1 votes

# Answer
# JavaScript, 35 bytes

```
f=n=>++n%3&&!(n+"").match(3)?n:f(n)

```

Try it online!
> 1 votes

# Answer
## Batch, 93 bytes

```
@set/pn=
:l
@set/an+=1,r=n%%3
@if %r%==0 goto l
@if not "%n:3=%"=="%n%" goto l
@echo %n%

```

Takes input on STDIN.
> 1 votes

# Answer
# CJam, 19 bytes

```
ri{)__3%!\`'3e=e|}g

```

ONLINE

Explanation:

```
ri{)__3%!\`'3e=e|}g
r                   Get token
 i                  Convert to integer
  {              }  Block
   )                 Increment
    _                Duplicate
     _               Duplicate
      3              Push 3
       %             Modulo
        !            NOT gate
         \           Swap
          `          String representation
           '3        Push '3'
             e=      Count occurrences
               e|    OR gate
                  g While popped ToS is true

```

If a less verbose explanation was asked, I would have done this:

```
ri{)__3%!\`'3e=e|}g
ri                  Get integer
  {              }  Block
   )                 Increment
    __               Triplicate
      3%!            Test non-divisibility with 3
         \           Swap
          `'3e=      Count occurrences of '3' in string repr
               e|    OR gate
                  g While popped ToS is true

```
> 1 votes

# Answer
# Pyth, 19 bytes

```
JhQW|!%J3/`J\3=hJ;J

```

Test suite

I am sure I can golf this... it's the same as my CJam answer.

Explanation:

```
JhQW|!%J3/`J\3=hJ;J
  Q                 Evaluated input
 h                  Increment
J                   Assign J to value
       J            Variable J
        3           Value 3
      %             Modulo
     !              Logical NOT
           J        Variable J
          `         String representation
            \3      Value "3"
         /          Count occurrences
    |               Logical OR
               h    Increment
                J   Variable J
              =     Apply function then assign
                 ;  End statement block
                  J Variable J

```
> 1 votes

# Answer
## Clojure, 73 bytes

```
(fn c[n](let[m(inc n)](if(or(=(rem m 3)0)(some #(=\3 %)(str m)))(c m)m)))

```

Recursively loops while `n` is divisible by 3, or contains a 3 in its string representation. Although I'm using unoptimized recursion, it was able to handle 2999999 as an input, so it should be ok.

Ungolfed

```
(defn count-without-3 [n]
  (let [m (inc n)]
    (if (or (= (rem m 3) 0)
            (some #(= \3 %) (str m)))
      (count-without-3 m)
      m)))

```
> 1 votes

# Answer
## Mathematica, 51 bytes

```
#+1//.t_/;t~Mod~3<1||!IntegerDigits@t~FreeQ~3:>t+1&

```

Try it online!
> 1 votes

# Answer
# Japt, 12 bytes

```
_%3«Zsø3}a°U

```

Run it online
> 1 votes

# Answer
# Ruby, 29 bytes

```
->n{0until"#{n+=n%3}"!~/3/;n}

```

Try it online!
> 1 votes

# Answer
# Stax, 9 bytes

```
ú╜H▌»NWì╤

```

Run and debug it

Unpacked, ungolfed, and commented it looks like this.

```
w       repeat rest of the program while the produced value is true
  ^c    increment and copy value
  E3#   (a) count number of digits that are 3
  n     copy incremented value
  3%!   (b) is multiple of 3?
  +     sum of (a) + (b) values

```

Run and debug this one
> 1 votes

# Answer
# Forth (gforth), 81 bytes

```
: f begin 1+ >r i i 3 mod 1 r> begin 10 /mod >r 3 <> * r> ?dup 0= until * until ;

```

Try it online!

### Explanation

1. Add 1
2. check if multiple of 3
3. check if contains a 3
4. if the result of step 3 or step 4 is true, repeat from step 1

### Code Explanation

```
: f               \ start a new word definition
  begin           \ start an indefinite loop
    1+            \ add 1 to current number
    >r i i        \ put current number on return stack, then place on normal stack twice
    3 mod         \ check if number is multiple of 3
    1 r>          \ place a 1 on the stack, then move the current number to the normal stack
    begin         \ start another indefinite loop
      10 /mod     \ get quotient and remainder of dividing by 10
      >r          \ put quotient on return stack
      3 <>        \ check if remainder does not equal 3
      *           \ multiply by accumulator (cheaper version of "and")
      r>          \ remove quotient from return stack
      ?dup 0=     \ if quotient does not equal 0, duplicate, else put -1 on stack
     until        \ end loop if top of stack does not equal 0
     *            \ multiply result of both checks (cheaper "and")
   until          \ end outer loop
 ;                \ end word definition

```
> 1 votes

# Answer
# TI-BASIC, ~~36~~ 35 bytes

```
Repeat fPart(Ans/3)max(3≠int(10fPart(Ans₁₀^(seq(-X-1,X,0,log(Ans:Ans+1:End:Ans

```

Input is in `Ans`.
Output is in `Ans` and is implicitly printed when the program completes.

**Examples:**

```
17
              17
prgmCDGFF
              19
299
             299
prgmCDGFF
             400

```

**Explantion:**
(Newlines added for readability. They do **not** appear in the source code.)

```
Repeat                                              ;loop until...
  fPart(Ans/3)                                      ; the current number is not
                                                    ;  a multiple of 3
  max(3≠int(10fPart(Ans₁₀^(seq(-X-1,X,0,log(Ans     ; and until it does not
                                                    ;  contain any 3s
Ans+1                                               ;add 1 to the current number
End
Ans                                                 ;leave the current number
                                                    ; in "Ans" and implicitly
                                                    ; print it

```

---

**Note:** TI-BASIC is a tokenized language. Character count does ***not*** equal byte count.
> 1 votes

# Answer
# Vyxal, 10 bytes

```
λ›D₃$3c∨[x

```

Try it Online!

It would be 9 bytes with  (parallel apply), but that seems to clear the stack, so that didn't work.

## How?

```
λ›D₃$3c∨[x
λ           # Open a lambda (for recursion)
 ›          # Increment
  D         # Triplicate, push three copies of a to the stack
   ₃        # Is it divisible by three?
    $       # Swap
     3c     # Does the number contain a three?
       ∨    # Is either of the top two things on the stack true?
        [x  # Then recurse

```
> 1 votes

# Answer
# Ruby, 39 bytes

```
f=->n{n+=1;(n%3<1||n.to_s=~/3/)?f[n]:n}

```

Try it online!
> 1 votes

# Answer
# Julia 1.0, 34 bytes

```
!n='3'∈"$(n+=1)"||n%3<1 ? !n : n

```

Try it online!
> 1 votes

# Answer
# Thunno 2 `+`, 11 bytes

```
(D3Ḋsd3Ƈ|;⁺

```

Attempt This Online!

#### Explanation

```
(D3Ḋsd3Ƈ|;⁺  # Implicit input
             # Increment
(            # While loop
 D           # (condition)  Duplicate
  3Ḋ         #              Divisible by 3?
    s        #              Swap
     d       #              Digits
      3Ƈ     #              Contains 3?
        |    #              Logical OR
         ;⁺  # (body)  Increment
             # Implicit input

```
> 1 votes

# Answer
# Go, 100 bytes

```
import(."strings";."fmt")
func f(n int)int{i:=n+1
for;i%3<1&&Contains(Sprint(i),"3");i++{}
return i}

```

Try it online!
> 1 votes

# Answer
# Vyxal 3, 9 bytes

```
э∥3c3Ḋ∵¬Ẇ

```

Try it Online!
> 1 votes

# Answer
# GNU sed `-E`, 148 bytes

Could be easier with a language with a modulo operator. Or division. Or counting. Or some idea about what numbers are. `sed` has neither, but it can solve the challenge much like a elementary school kid would:

```
s/^/0123456789-0/
:1
s/((.)(.).*)\2$/\1\3/
:2
s/((.)(.).*)\2-/\1\30/
t2
/-.*3/b1
h
:3
s/((.)(.).*-.*)\3/\1x\2/
s/x0*x0*x//
t3
/x/!{g;b1}
g
s/.*-0*//

```

Try it online!
> 1 votes

# Answer
# Google Sheets, 63 bytes

```
=+let(n,sequence(254),filter(n,n>A1,mod(n,3),iserr(find(3,n))))

```

Put the input in cell `A1` and the formula in `B1`.

The `filter()` gets all matching values above the value in `A1` and the unary plus `+` gets the first value from that list.
> 1 votes

# Answer
# C#, 49 bytes

```
int A(int n)=>(++n+"").IndexOf('3')*n%3<0?n:A(n);

```

Slightly different and shorter than the above c#, using recursion and another trick I came up with to condense the two conditions into one
> 0 votes

# Answer
# MathGolf, ~~10~~ 9 bytes

```
ö)_3‼╧÷+▲

```

Try it online!

## Explanation

The program loops until it finds a number that is neither divisible by 3 or contains the number 3.  is a new addition to MathGolf, and is newer than this challenge (and this answer). It has been an idea I had in mind for a while, but I finally got everything together to implement it.

```
ö           start block of length 7
 )          increment
  _         duplicate TOS
   3        push 3
    ‼       apply next two operators separately to the stack
     ╧      pop a, b, a.contains(b)
      ÷     is divisible
       +    pop a, b : push(a+b) (works as a logical OR)
        ▲   do while true with pop

```
> 0 votes

# Answer
## Perl 6, 39 bytes

```
{my$a=$_+1;$a++while $a%%3||$a~~/3/;$a}

```
> 0 votes

# Answer
# BotEngine, ~~770~~ 107x7 = 749 (740 bytes)

This can almost certainly be made rather more compact than it currently is, but I finally managed to get it working at least.

```
v  0 1 2 3 4 5 6 7 8 9 $ $   0 1 2 3 4 5 6 7 8 9 $  0 1 2 3 4 5 6 7 8 9 $> 0 1 2 3 4 5 6 7 8 9 $v$ $3
I>>S S S S S S S S S S S>S$v>S S S S S S S S S S S >S S S S S S S S S S S >S S S S S S S S S S S>e>SS~v
R  e1e2e3e4e5e6e7e8e9e0e1>e ^e0e1e2e3e4e5e6e7e8e9e$ e0e1e2e3e4e5e6e7e8e9>^ e0e1e2e3e4e5e6e7e8e9>^  Re3  $
$e^                  < e$   ^<     <     <     <        <     <     <        <     <     <         P>  >S~v
>^ >>>>>>>>>>>>>>>>>>>>>^ ~<   >     >     >       ^<     <     <     <        <     <     <      ^   <^  <
                                 >     >     >        >     >     >       ^<     <     <     <          e$
  ^                                              <                                                      <

```

Input and output is in standard big-endian decimal, although most of the program uses little-endian internally to make the increment cycle more straightforwards.
> 0 votes

# Answer
# APL(NARS), 54 chars, 108 bytes

```
r←h w;c
r←c←0
→3×⍳(0=3∣r)∨'3'∊⍕r⋄c+←1⋄→0×⍳r>w
r+←1⋄→2

```

I prefer this, the loop, to all recursive functions; test:

```
  h¨1 2 11 22 29 251
2 4 14 25 40 254
  h¨3 6 10
4 7 11

```
> 0 votes

# Answer
# Binary-Encoded Golfical, 80 bytes

This binary-encoded format can be converted to the standard graphical version using the encoder utility included in the github repo, or run directly using the interpreter by adding the `-x` flag.

Hexdump of binary encoding:

```
01 70 03 15 14 14 1b 1a 14 04 01 14 14 2c 14 14
00 03 14 14 0a 01 14 14 2f 14 14 53 2d 14 23 1d
14 32 14 14 1b 14 1a 00 0a 14 14 0a 01 14 14 2f
14 14 53 31 14 06 03 14 14 23 1d 14 00 0a 14 14
0a 01 1c 14 2d 17 14 3d 2d 14 23 1d 14 1c 2c 1d

```

Original image (23x3):

Magnified 20x:
> 0 votes

# Answer
# C, 59 bytes

```
n,m;f(){if(++n%3)for(m=n;m;m/=10)(m%10==3)?f():0;else f();}

```
> 0 votes

# Answer
# K (oK), ~~24~~ 23 bytes

**Solution:**

```
(1+)/[{(~3!x)|51in$x};]

```

Try it online!

**Explanation:**

Iterate from input+1 until valid number is found. Bit of a cheat dropping whitespace between `51` and `in`.

```
(1+)/[{(~3!x)|51in$x};] / the solution
    /[{             };] / iterate (/) while {} is true
                  $x    / string x, e.g. 12 => "12"
              51in      / is "3" (51 in ASCII) in the string?
             |          / or
       (    )           / do this together
         3!x            / x modulo 3
        ~               / not
 1+                     / add 1 to x (e.g. x++)

```
> 0 votes

---
Tags: code-golf, math, arithmetic, game
---


title: Drawing the Stack Overflow logo

text:
# Question
Title: Drawing the Stack Overflow logo
From here. Every new game is the first day of the month, 12:00 PM UTC.

The goal is to create the Stack Overflow logo using ASCII characters.

It looks like this.

The exact output should look like this:

```
        \\
          \\
     \=    \\
       \=    \\
         \=   \\
           \==  \\
    ¯¯¯       \==
       ¯¯¯¯¯
   _______  ¯¯¯¯
          ____
| ____________ |
|              |
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

```

It must be worth mentioning that it must represent the same form of the actual logo, wherein the lines' (which I would call sticks) layering should be aligned as the way of the one from the picture. You can use either spaces or newlines to add another line for drawing the logo.

Remember, 5 sticks facing different angles and 1 tray holding them.

Can you draw it with the least bytes possible?

# Answer
> 9 votes
# Python 3, ~~121~~ ~~120~~ 108 bytes

Inspired by @Enzo's answer, this works very similarly, except it encodes using a bytestring instead of an integer in base 36. Thanks also to @xnor for shaving 12 bytes off.

Each character in the encoding is equal to `chr(' |\\=_¯\n'.index(c) + 7*n + 28)` where a symbol `c` should be repeated `n` times; the `+ 28` is just so it's in the printable ASCII range. The last repetition is encoded as `¯` 8 times twice, instead of `¯` 16 times, for the same reason.

```
for x in b'T,)b,)?%&8,)M%&8,)[%&1,)i%-*,)86M%-)MD)1Q*=)b<)$#t#$)$~$)YY':print(end=' |\=_¯\n'[x%7]*(x//7-4))

```

Try it online!

# Answer
> 7 votes
# JavaScript (ES6), 154 bytes

```
_=>` 8#10#5\\= 4#7\\= 4#9\\= 3#11\\==  #4¯3 7\\==
 7¯5
 3_7  ¯4
 10_4
| _12 |
| 14|
¯16`.split`#`.join`\\2
 `.replace(/.(\d+)/g,(s,n)=>s[0].repeat(n))

```

Try it online!

# Answer
> 6 votes
# Splinter, ~~160~~ 153 bytes

```
A{\
}B{\ }C{BB}D{CC}E{DD}EF{\\}G{FFA}GCEGBDH{FI{\=}I}HDGR{BC}RDHDGEBHRGERHICGDK{\-}L{KK}KLRDHIARDM{LL}MKARN{\_}P{NNNN}NNNPCMAECPAQ{\|}QBPPPBQAQCDEQAMMMM

```

Try it online!

Note: Due to a bug in the interpreter, only 1-byte characters can be printed. If the interpreter worked properly, I could just replace the hyphen with an overline, printing the correct result.

# Answer
> 5 votes
# Python 3, 205 186 180 172 169 bytes

*-8 bytes* thanks to @kaya3

*-4 bytes* thanks to @Makonede

```
for i in range(58):m=int('7IPPQA9UU6JJAOWWU17I77P5ZEVJ0ASTQRZNTQCX7GD0BJ6Z2F6P6PBFO9DU4F4GFYC7ST87K89MCKVO9S08KDRI2O',36)>>i*8&255;print(end=' \\=¯_|\n'[m&7]*(m>>3&31))

```

Try it online!

Encodes the output into a integer in groups of 8 bits for each character. The first 5 bits represents the length of this character in the original output and the last 3 bits the character index in `s`.

Ungolfed:

```
g = int('7IPPQA9UU6JJAOWWU17I77P5ZEVJ0ASTQRZNTQCX7GD0BJ6Z2F6P6PBFO9DU4F4GFYC7ST87K89MCKVO9S08KDRI2O', 36)
s = ' \\=¯_|\n'                # Unique characters from the expected output
for i in range(58):
    m = g >> i*8 & 255         # Gets the i-th group of 8 bits from the encoded integer
    i = m & 7                  # The last 3 bits: index of s
    n = m >> 3 & 31            # The first 5 bits: length of this character
    print(s[i] * n, end='')    # Prints it

```

# Answer
> 4 votes
# Charcoal, ~~73~~ 70 bytes

```
Ｆ³«Ｆ²¶\\←»↙Ｆ⁵«←…=⊕‹ι²↖¹»Ｍ⁴↓Ｆ354⁺¶×¯Ｉι↙↓↓²←×¯¹⁶↗↑²↘→Ｇ→¹²_Ｆ47←⁺¶×_Ｉι

```

Try it online! Link is to verbose version of code. Note that there are only ~~69~~ 66 characters but I think `¯` actually requires three bytes to encode since it's not in Charcoal's code page. Output includes leading blank line. Explanation:

```
Ｆ³«Ｆ²¶\\←»

```

Print the top right stick of `\\`s.

```
↙Ｆ⁵«←…=⊕‹ι²↖¹»

```

Print the stick of `\=`s.

```
Ｍ⁴↓Ｆ354⁺¶×¯Ｉι

```

Print the stick of `¯`s.

```
↙↓↓²←×¯¹⁶↗↑²

```

Print the box.

```
↘→Ｇ→¹²_

```

Print the horizontal stick of `_`s.

```
Ｆ47←⁺¶×_Ｉι

```

Print the other stick of `_`s.

# Answer
> 3 votes
# Julia, ~~112~~ ~~108~~ 105 bytes

```
b"YEibUib-ad%ib=ad%ibMaduibUealmib%w=alb=/bu;m'bU#bfeSkefbfU%fbGG".|>b->print("\\
_= |¯"[b%8]^(b%88÷8))

```

Try it online!

each character of the string contains the next index of the character to print and the amount of it: `b%8` is the index of the character and `b%88÷8` is the amount (maximum 10)

the characters are generated as follows: `char = index + 8*amount + 88[if not printable]`

(very similar to kaya3's answer and Enzo's answer)

# Answer
> 3 votes
# Brainfuck ~~483~~ ~~479~~ 472 bytes

## -4 bytes and fix the code thanks to Makonede

Yes... brainfuck, the best language to do ascii art :)

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

```

Try it by yourself

"Beautiful" version:

```
+[->---[-<]>-]>                 Create \
<<++++[>++++++++<-]>>>          Create space
>>>+[-[<+>>]<-]<--              Create =
>++++++++++                     Create line jump
>>+[<+>---]<++++>               Create weird minus sign
>-[<++>-----]<-------           Create _
>>--[<+>--]<---                 Create |
[<]>                            Return to the start and draw
........>..>>.[<]>
..........>..>>.[<]>
.....>.>.<<....>..>>.[<]>
.......>.>.<<....>..>>.[<]>
.........>.>.<<...>..>>.[<]>
...........>.>..<<..>..>>.[<]>
....>>>>...<<<<.......>.>..>.[<]>
.......>>>>.....<.[<]>
...>>>>>.......<<<<<..>>>>....<.[<]>
..........>>>>>....<<.
>>>.[<]>.[>]<<............[<]>.[>]<.<<<.
>>>.[<]>..............[>]<.<<<.
>................

```

# Answer
> 3 votes
# V (vim), ~~85, 82~~, 81 bytes

```
i¸ \\3ñ2Ù2>jj>ñ2G6|4ñjR\= ñr=jS´ ³¯· \==
· µ¯
³ ·_  ´¯
± ´_
| ±²_ |
|±´ |ÙÒ¯

```

Try it online!

Hexdump:

```
00000000: 69b8 205c 5c1b 33f1 32d9 323e 6a6a 3ef1  i. \\.3.2.2>jj>.
00000010: 3247 367c 34f1 6a52 5c3d 20f1 723d 6a53  2G6|4.jR\= .r=jS
00000020: b420 b316 afb7 205c 3d3d 0db7 20b5 16af  . .... \==.. ...
00000030: 0db3 20b7 5f20 20b4 16af 0db1 20b4 5f0d  .. ._  ..... ._.
00000040: 7c20 b1b2 5f20 7c0d 7cb1 b420 7c1b d9d2  | .._ |.|.. |...
00000050: af                                       .

```

# Answer
> 2 votes
# JavaScript (Browser), 178 bytes

```
_='alert("~}}~ uw~}uw~w u}~su=  ~{¯su=ysv¯y}xx_  vy}sx_y| xxxx |y|}}s |yvvvv")~zzyww  {¯¯z\\\\y\\nx___w} v{{uz=s}w';for(i of'suvwxyz{}~')with(_.split(i))_=join(pop());eval(_)

```

Compressed using RegPack. A lot of JS1k submissions, including mine, went through RegPack to shave off some bytes.

# Answer
> 2 votes
# Python 3, 176 bytes

Fairly straightforward use of variables to repeat parts of the string. The only slightly clever parts are to do with spaces - the `print` function uses `' '` as a separator by default, so each `,` in the argument list for `print` results in a space, saving two bytes compared to `+s+` each time. The variables `v` and `w` are 3 and 8 spaces respectively, but `*v` with the unpacking operator results in 5 spaces.

I played around with it and found quite a lot of ways to make it 176 bytes, so there are probably a few more optimisations possible.

```
c,d,e,f,p,s,n='¯_=\\| \n'
a=f+f+n
b=f+e
v=s*3
w=s*8
print(w+a,w,a,v,b,v+a,*v,b,v+a+w,b+v+a+v+w+b+e+s,a,v+c*3,*v,b+e+n,*v,c*5+n+v+d*7+s,c*4+n,w,d*4+n+p,d*12,p+n+p,v,w,p+n+c*16)

```

Try it online!

# Answer
> 2 votes
# ///, 149 bytes

```
/0/¯¯¯//1/\\\\//2/   //3/22//4/__/3  11
 2311
  21= 211
 31= 211
231=   11
23  1==  11
 203 1==
 30¯¯
2_444  0¯
 3244
| 444444 |
|  33|
¯00000

```

Try it online!

# Answer
> 1 votes
# Vyxal, ~~246~~ 103 bytes

Try it online!

```
»Ẋ℅Ḋ↑↵S₈q⁋τGB¡:₀Ẏæ⁽₈;↔≬(ɾ₆^¾∑₂ġL4Ẋ>X¯[¹„⁋∵⟨⌈IR₅⌐∑wġb√AøĊd□≠⟇⅛]ṫ¯GȮd↓a«Ǐḣ1…9₍D€Cv↔₀:y-»»ø¾q»` \\=\¯|_
`Ŀ

```

Had to escape the dashes because otherwise string commpression: also doubled backslashes because they also need escaping. Apart from that, pretty clear (Edit 1: significantly golfed)

# Answer
> 1 votes
# 05AB1E, ~~85~~ 84 bytes

```
•Ñ,ó r∍$±‘VY'ā±θʒć×zX[¬Ñˆãт²Ó₅ï=viÜLyƶ7eÖ¸¢¼“†…λ)’üƵĀÿ¹;ΣÃĀPJ¯12Q¦cI)Ù₄Í•"\
=¯_|"Åв

```

Try it online!

```
•...•"..."Åв  # trimmed program
          Åв  # push list of characters in...
     "..."    # literal...
          Åв  # with indices in base-10 values of base length of...
     "..."    # literal...
          Åв  # digits of...
•...•         # 598068322507306753885876761229106573443829774776514490536123134274531939033031756234422473798677424533439086479188876552508052865203429750266756699838477188150403473080434
              # implicit output

```

# Answer
> 1 votes
# Jelly, 90 bytes

```
“£RƊsƇCṄʠUU¿¦ȦC@Ṗṛ¡Ṛȧw²{MXI⁼ḊĊƑ(ḅyỴɲṫ^ȦhİA_ḳGḶµBṙnYɓ@ƑSṚ)ṇƲẋ.ubƓ9ṚÄ²ɓɼÆÐƭ’ṃ“ \¶=_|”;175Ọ¤¤

```

Try it online!

non-ascii in an ascii-art challenge is kinda sus

# Answer
> 1 votes
# Vyxal 3, 78 bytes

```
"ᶜᵛYn₄#D)∵#Ḟ→κ₀ḞɠṚR₂ᴿ₉
Ċ»+ḣᴿ
5²ᵂp-Ṣġ{8~ṀḌ∑₃ᶳÞ∥ċṢYʀQjĖ£ṁQ '√ċ₈%ı∧₈I1“"\
=¯_|"y

```

Try it Online!

Can be golfed even better, any help would be greatly appreciated.

# Answer
> 0 votes
# V (vim), 117 112 bytes

```
8á 2á\3Äj2é j4hi\= <esc>Ä}bb2é Äj2é 3lxÄj2é elr=ÄjelD9h3é¯ï7é 5á¯ï3é 7á_2á 4á¯ÙÒ $6X4á_ÙÒ_r|lr A |<esc>Ù<M-S>_/
ÙÒ¯

```

Try it online!

-5 bytes from DJMcMayhem.

This feels a bit too long for Vim, which I thought would work well for this challenge. I want to at the very least, beat one of the compressed answers.

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


title: Golf an HQ9+ transpiler

text:
# Question
Title: Golf an HQ9+ transpiler
There was a prior question about golfing an HQ9+ compiler that translates HQ9+ code into the language it is written in, but that was closed as a duplicate of the interpreter challenge because converting an interpreter to a compiler is seen as trivial. This question is based on the closed one, but has some changes.

Write an HQ9+ transpiler in a language of your choice. Your submission should be written in some language X, and should take input of HQ9+ source and output a program in another language Y.

The `H` command prints `Hello, world!`.

`Q` outputs the program's code. For this challenge, it must print the transpiled code, not the HQ9+ source, and must not use cheating quine methods. This deviates from the HQ9+ "specification," but is intended to further distinguish this challenge from the interpreter one. For the avoidance of doubt, using `eval`-type functions or methods such as JavaScript's `function.toString()` are *not* considered cheating for the purpose of this challenge.

The `9` command prints the lyrics to "99 Bottles of Beer." You may use any reasonable variant of the lyrics.

In theory, `+` increments the accumulator. However, because the accumulator cannot be addressed, `+` is effectively a no-op.

`H`, `Q`, and `9` may, but are not required to, print trailing newlines. `+` must not produce any output, not even whitespace.

Input must be case-insensitive; `hq`, `hQ`, `Hq`, and `HQ` are the same program. Behavior with unrecognized characters is undefined.

## Rules

1. Language X should satisfy the traditional definition of a language
2. Standard loopholes disallowed
3. Your solution must be testable
4. Y cannot be HQ9+ or an extension of HQ9+
5. Score is calculated as length of transpiler, plus length of output for `H`, plus length of output for `Q`, plus length of output for `9`, plus length of output for `+`, plus length of output for `HQ9+`
6. Submissions compete by language pairs; and HQ9+ to JavaScript transpiler in Python does not compete with an HQ9+ to C transpiler also written in Python.

# Answer
> 6 votes
# RProgN 2 (outputs RProgN 2), 190 + 17 + 9 + 116 + 1 + 140 = 473 bytes

```
l]`qEL²"«` .x="w?]`9EL²"$99{]]1-'%i J on the wall
%i J!
You take one down, pass it around
%i J on the wall!'`J'bottles of beer'rF}Si`
.y="w?
'[^h9q]'Ør`h"'Hello, world!'p"r
`9'yp'r`q"xp"r` .

```

Try it online!

Uses an ultra simple 99 bottles representation. Includes newlines between commands, though instances of `p` can be swapped for `w` to remove them at no extra cost. Conditionally includes a the chunk of code for 99 bottles and the quine only if they're needed.

# Answer
> 5 votes
# Retina 0.8.2 (outputs Actually or Seriously), 14 bytes, score 23

```
T`l9+`LN_
\B
.

```

Try it online! Link includes test cases. Explanation: Port of @KevinCruijssen's 05AB1E answer.

```
T`l9+`LN_

```

Uppercase the input, change `9` to `N`, and delete `+`.

```
\B
.

```

Insert `.`s between pairs of letters. (This also means that the output for `+` is `.`, but it's worth it for the golfiness.)

# Answer
> 4 votes
# 05AB1E (outputs Actually or Seriously), score: 20

<sup>10 bytes \+ 2 for `H` \+ 2 for `Q` \+ 2 for `9` \- 1 since a trailing `.` is not necessary + 0 for `+` \+ 5 for `HQ9+`</sup>

```
u9'N:áS'.ý

```

Output language is either Actually or Seriously.
It'll output `Hello, World!` and the quine with a single trailing newline, and 99 bottles of beer with two trailing newlines.

Try it online.

Try the output for `Hq9+h` in Actually.
Try the output for `Hq9+h` in Seriously.

**Explanation:**

*05AB1E:*

```
u            # Uppercase all letters in the (implicit) input-string
 9'N:       '# Replace all 9s with "N"s
     á       # Remove the "+"s by only leaving letters
      S      # Convert the string to a list of characters
       '.ý  '# Join it back together with "." delimiter
             # (after which the result is output implicitly)

```

*Actually / Seriously:*

* `H`: Push "Hello, World!" to the stack
* `N`: Push the entire 99 bottles of beer lyrics (with trailing newline) to the stack
* `Q`: Push the program's source code to the stack
* `.`: Pop and print a string with trailing newline
* Implicitly print the trailing string on the stack which we haven't explicitly printed with a `.`

---
Tags: code-golf, code-generation, compiler
---


title: Write the date in abbreviated Latin

text:
# Question
Title: Write the date in abbreviated Latin
*Inspired by How do you write dates in Latin?*

## Challenge

Given a month-and-day date, output that date in abbreviated Latin, as explained below.

## Input

Input is flexible, following conventions from other and challenges. You may choose to:

* Take a date in mm/dd or dd/mm format or two separate month,day arguments;
* Take a date in your language's date format;
* Take an integer in interval \[0, 364\] corresponding to a day in the year;
* Take some other reasonable input that can encode all 365 days of the year;
* Take no user input but output the current day's date;
* Take no input and output all 365 days of the year in order;

Importantly, you only need to care about the month and day, not about the year, and you can assume that the year is not a leap year.

## Output

Output is the date in abbreviated Latin, as specified in this section in BNF, and as explained more verbosely in the next section.

```
<output> ::= <delay> <event> <month>
<event> ::= "Kal" | "Non" | "Eid"
<month> ::= "Ian" | "Feb" | "Mar" | "Apr" | "Mai" | "Iun" | "Iul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
<delay> ::= "" | <one-day-delay> | <n-days-delay>
<one-day-delay> ::= "prid"
<n-day-delay> ::= "a d" <roman-numeral>
<roman-numeral> ::= "III" | "IV" | "V" | "VI" | "VII" | "VIII" | "IX" | "X" | "XI" | "XII" | "XIII" | "XIV" | "XV" | "XVI" | "XVII" | "XVIII" | "XIX"

```

## How do you write dates in abbreviated Latin?

*Adapted from How do you write dates in Latin?*

There are 36 special days in the year.

* A date which is a special day is encoded by giving the name of that special day;
* A date which is just before a special day is encoded by writing `prid` followed by the name of that special day;
* Another day is encoded by writing `a d` followed by the number of days between that date and the next special day, **counting inclusively**, using Roman numerals, followed by the name of that special day.

Counting inclusively, there are for instance 3 days between January 3rd and January 5th.

The Roman counting system is oddly inclusive to modern taste. Whenever we would say that something is n days earlier, the Romans would have said n+1. The day just before the special day is two days before it (we'd say one day) and uses `prid` instead of numbering, so the unnamed days start their numbering at 3.

The 36 special days are:

* The Kalendae, first day of the month: `01/01, 02/01, ..., 12/01`, written `Kal <month>`, respectively: `Kal Ian`, `Kal Feb`, `Kal Mar`, `Kal Apr`, `Kal Mai`, `Kal Iun`, `Kal Iul`, `Kal Aug`, `Kal Sep`, `Kal Oct`, `Kal Nov`, `Kal Dec`;
* The Nonae, 5th or 7th day of the month: `01/05, 02/05, 03/07, 04/05, 05/07, 06/05, 07/07, 08/05, 09/05, 10/07, 11/05, 12/05`, written `Non <month>`, respectively: `Non Ian, Non Feb, Non Mar, Non Apr, Non Mai, Non Iun, Non Iul, Non Aug, Non Sep, Non Oct, Non Nov, Non Dec`;
* The Ides, 13th or 15th day of the month: `01/13, 02/13, 03/15, 04/13, 05/15, 06/13, 07/15, 08/13, 09/13, 10/15, 11/13, 12/13`, written `Eid <month>`, respectively: `Eid Ian, Eid Feb, Eid Mar, Eid Apr, Eid Mai, Eid Iun, Eid Iul, Eid Aug, Eid Sep, Eid Oct, Eid Nov, Eid Dec`.

Note the Nonae and Ides come two days later in the four months of March, May, July and October.

Because of these rules, only Roman numerals between 3 and 19 are required.

## Test cases

```
mm/dd  -->  abbrev. Lat.

01/01  -->  Kal Ian
01/02  -->  a d IV Non Ian
01/03  -->  a d III Non Ian
01/04  -->  prid Non Ian
01/05  -->  Non Ian
02/02  -->  a d IV Non Feb
02/27  -->  a d III Kal Mar
02/28  -->  prid Kal Mar
03/01  -->  Kal Mar
03/02  -->  a d VI Non Mar
04/02  -->  a d IV Non Apr
05/02  -->  a d VI Non Mai
06/02  -->  a d IV Non Iun
07/02  -->  a d VI Non Iul
08/02  -->  a d IV Non Aug
08/05  -->  Non Aug
09/02  -->  a d IV Non Sep
10/02  -->  a d VI Non Oct
10/15  -->  Eid Oct
10/12  -->  a d IV Eid Oct
10/13  -->  a d III Eid Oct
10/14  -->  prid Eid Oct
10/17  -->  a d XVI Kal Nov
11/02  -->  a d IV Non Nov
12/02  -->  a d IV Non Dec
12/14  -->  a d XIX Kal Ian
12/30  -->  a d III Kal Ian
12/31  -->  prid Kal Ian

```

## Rules

* This is code-golf, the shortest code in bytes wins!

# Answer
> 4 votes
# Charcoal, 163 bytes

```
Ｆ³⁶⁵⊞υωＦ¹⁹Ｆ¹²Ｆ³§≔υ⁺⁺Ｉ§⪪”)¶Ｏ↥…⊞H₂；≦'⪫⦃π0S｜”³κ∧λ⊗⁻×⁴λ∨№1358Ｉκ²ι⪫Φ⟦×‹ι¹⁷a d§⪪”{⧴,π⁶δυＷ≦χVM⪫mSＤfZ<hνＨm¬⍘ψc⎇⊖ＭlR5ρν” ι§⪪KalNonEid³λ§⪪”>-b∧⊖αθ?｜¬Ｙ≔⁼IΦ«wS▷ＮAº⁸Fω&↗”³κ⟧μ υ

```

Try it online! Link is to verbose version of code. Outputs all 365 days. Explanation:

```
Ｆ³⁶⁵⊞υω

```

Allocate an array of 365 days so that cyclic indexing will fill in some of the January values.

```
Ｆ¹⁹

```

Start from `a d XIX Kal Feb...a d XIX Kal Ian` and work forward to `Kal Feb...Kal Ian`.

```
Ｆ¹²

```

Loop from `Feb` to `Ian`. (This avoids a negative number below.)

```
Ｆ³

```

Loop over `Kal`, `Non` and `Eid`.

```
§≔υ⁺⁺Ｉ§⪪”...”³κ∧λ⊗⁻×⁴λ∨№1358Ｉκ²ι

```

Calculate the day of year that this day would be (if it existed).

```
⪫Φ⟦×‹ι¹⁷a d§⪪”...” ι§⪪KalNonEid³λ§⪪”...”³κ⟧μ

```

Overwrite it with the name of this day, made up of four optional parts: `a d`, the day number (or `prid`), the special day, and the month, joined with a space (which is at the end of the above line).

```
υ

```

Output all of the days of the year.

# Answer
> 1 votes
# JavaScript (ES6),  ~~268 ... 262~~  252 bytes

Expects `(month)(day)`.

```
m=>d=>([t=0,q=2384>>m&2^4,q+8,m-2?~-m%1.7^31:28].every(k=>(n=k+1-d)<0&&++t,A="KalNonEidIanFebMarAprMaiIunIulAugSepOctNovDecIanI II III IV V VI VII VIII IX  ".match(/[IVX]* |.../g))|n?n-1?"a d "+(n>8?"X":"")+A[n%10+16]:"prid ":"")+A[t%3]+" "+A[m+=2^t>2]

```

Try it online!

### Algorithm

The `every()` loop looks for the first 0-indexed special day that is greater than or equal to \\$d-1\\$.

Once completed:

* The number of days before the next special day is loaded in \\$n\in\[0\dots18\]\\$.
* The type of the special day is loaded in \\$t\in\[0\dots3\]\\$:
    + \\$t=0\\$ → first day of the current month
    + \\$t=1\\$ → Nonae
    + \\$t=2\\$ → Ides
    + \\$t=3\\$ → first day of the next month

### Formulas

* `q = 2384 >> m & 2 ^ 4` gives the 0-indexed day of the Nonae for month \\$m\\$ (either \\$4\\$ or \\$6\\$).
* `q + 8` gives the 0-indexed day of the Ides for month \\$m\\$ (either \\$12\\$ or \\$14\\$).
* `~-m % 1.7 ^ 31` gives the number of days in month \\$m\\$, except for February which is processed separately. I first used this decimal remainder trick in one of my solutions to this other challenge.

### Lookup string

Most substrings are stored into a single lookup string:

```
"KalNonEidIanFebMarAprMaiIunIulAugSepOctNovDecIanI II III IV V VI VII VIII IX  "
 \_______/\_____________________________________/\____________________________/
  special                 months                     Roman numeral suffixes
   days         (wrapping from Dec to Ian)           (followed by a space)

```

which is split with the following regular expression:

```
/[IVX]* |.../g  // either a Roman numeral suffix followed by a space
                // or 3 characters

```

# Answer
> 1 votes
# Jelly, 125 bytes

```
“Y8ṁ`yƈʋIƊĠSṖḶ⁾İ2’ṃ“XVI ”Ḳ“a d ”;Ɱ““prid”;
“-gBƥ]ṢḲ@’b6s2+“¢Ñ‘j€8FRUị¢ṭ€"“¡Qḟ8i,ȷıƊḳė¦øsÑNpq>ė7 “¢Zıƒ>ɠ’ṃØas€3ŒtƊŒpṙ1¤Ẏ⁸ịṚ¹ƇK

```

Try it online!

A pair of links called as a monad, taking an integer from 0 to 364 and returning a string representing the relevant date. (Technically will also work for numbers outside that range since it uses a modular index into a list of all 365 possibilities.)

## Explanation

```
“Y8ṁ`yƈʋIƊĠSṖḶ⁾İ2’ṃ“XVI ”Ḳ“a d ”;Ɱ““prid”;                                          # Helper link: called as a nilad, generates the delay parts of the date
“Y8ṁ`yƈʋIƊĠSṖḶ⁾İ2’                                                                  # Base 250 integer 84034955351979905312914389471555862301
                  ṃ“XVI ”                                                           # Base decompress into "XVI "
                         Ḳ                                                          # Split on spaces
                          “a d ”;Ɱ                                                  # Prepend each with "a d "
                                  ““prid”;                                          # Prepend an empty string and then "prid"

“-gBƥ]ṢḲ@’b6s2+“¢Ñ‘j€8FRUị¢ṭ€"“¡Qḟ8i,ȷıƊḳė¦øsÑNpq>ė7 “¢Zıƒ>ɠ’ṃØas€3ŒtƊŒpṙ1¤Ẏ⁸ịṚ¹ƇK  # Main link: takes an integer and returns a string representing the date
“-gBƥ]ṢḲ@’                                                                          # Base 250 integer 2833073888199044565
          b6                                                                        # Convert to base 6
            s2                                                                      # Split into pieces of length 2
              +“¢Ñ‘                                                                 # Add 1 to the first member of each sublist and 16 to the second
                   j€8                                                              # Join each with 8
                      F                                                             # Flatten
                       R                                                            # Ranges from 1..z for each z in this list
                        U                                                           # Reverse each range
                         ị¢                                                         # Index into the helper link
                           ṭ€"                                            ¤         # Tag each member of each of the sublists of strings onto the corresponding sublist from the following:
                              “¡Qḟ8i,ȷıƊḳė¦øsÑNpq>ė7 “¢Zıƒ>ɠ’                       # Base 250 integers 302811639626768516702588802453858478870563499076533, 2309009953410
                                                                     Ɗ              # Following as a monad (used to avoid having to have ¤ after each of the nilads in the following)
                                                             ṃØa                    # - Base decompress into lowercase letters
                                                                s€3                 # - Split each into pieces length 3
                                                                   Œt               # - Convert to title case
                                                                      Œp            # Cartesian product
                                                                        ṙ1          # Rotate left one (moves Ian Kal to the end)
                                                                           Ẏ        # Join outer lists (after this step we have all 365 dates but with their component pieces in the wrong order and not yet joined with spaces)
                                                                            ⁸ị      # Index the main link’s argument into this
                                                                              Ṛ     # Reverse
                                                                               ¹Ƈ   # Keep only those that are non-empty (removes the space from before the exact special dates)
                                                                                K  # Join with spaces

```

Created with the help of Luminespire.

---
Tags: code-golf, date, roman-numerals
---


title: Ungolf the Wind

text:
# Question
Title: Ungolf the Wind
Weather conditions at airports are reported to pilots in METAR (METeorological Aerodrome Report) format. This format could be described as being "golfed." Here are some examples:

```
METAR KPDX 241653Z 16003KT 1/4SM R10R/4500VP6000FT FG SCT000 01/M01 A3040 RMK AO2 SLP293 FG SCT000 T00061006 $

METAR PAMR 241753Z 00000KT 10SM OVC080 00/M02 A2985 RMK AO2 SLP111 T00001017 10022 21006 55003

METAR KLAX 241653Z VRB05KT 10SM FEW030 SCT060 17/11 A2992 RMK AO2 SLP130 T01720106

METAR KBOS 241754Z 27012G19KT 10SM FEW045 SCT250 09/M05 A3000 RMK AO2 SLP158 T00941050 10094 20044 56020

```

These are all American METARs, which is all your program needs to accept. The international format is slightly different.

You only need the wind component, which is after the third space.

```
METAR KLAX 241653Z       | VRB05KT | 10SM FEW030 SCT060 17/11 A2992 RMK AO2 SLP130 T01720106
Things that don't matter | *Wind*  | More things that don't matter

```

However, your program will be given the entire METAR.

Let's take the METAR from KPDX as the first example. Its wind component is `16003KT`. When the code looks like this, it's simply indicating the wind direction and speed. The first three digits, `160`, are the direction in degrees; the last two, `03`, are the speed in knots (`KT`; a knot is a nautical mile per hour). In this case, the output should clearly indicate the direction and speed as separate values. You do not have to indicate units.

When there is no wind, it will look like the PAMR METAR: `00000KT`. This indicates zero knots; zero degrees is used as a placeholder, because there is, of course, no way to measure wind direction without wind. Just parse these the same as regular codes; your program does not have to treat this as a special case.

Sometimes, as was the case at KLAX at the time of writing, the wind direction is variable. This is encoded as `VRB05KT`. The direction is replaced with `VRB`, which your program must parse, and the speed is encoded normally.

Wind with gusts is encoded like this: `27012G19KT`. The `270` indicates the direction. The `12` indicates that the average wind speed is 12 knots, while `G19` indicates that gusts are reaching 19 knots.

I did not find a current METAR that actually had this, but your program must also handle variable winds with gusts, which would look like this: `VRB12G19KT`.

Your program must return or output three numbers. The first is the wind direction in degrees, or -1 if the wind is `VRB`. The second is the wind speed. The third is the gust speed if there are gusts, or `-1` otherwise. Leading zeros are not allowed.

Here are some test cases. They are the four real METARs from the start of the question, plus a constructed one to test for variable gusty winds.

```
METAR KPDX 241653Z 16003KT 1/4SM R10R/4500VP6000FT FG SCT000 01/M01 A3040 RMK AO2 SLP293 FG SCT000 T00061006 $
160 3 -1

METAR PAMR 241753Z 00000KT 10SM OVC080 00/M02 A2985 RMK AO2 SLP111 T00001017 10022 21006 55003
0 0 -1

METAR KLAX 241653Z VRB05KT 10SM FEW030 SCT060 17/11 A2992 RMK AO2 SLP130 T01720106
-1 5 -1

METAR KBOS 241754Z 27012G19KT 10SM FEW045 SCT250 09/M05 A3000 RMK AO2 SLP158 T00941050 10094 20044 56020
270 12 19

METAR KTVG 241754Z VRB12G19KT 10SM FEW045 SCT250 09/M05 A3000 RMK AO2 SLP158 T00941050 10094 20044 56020
-1 12 19

```

# Answer
# Google Sheets, 80 bytes

```
={iferror(--mid(A1,20,3),-1),mid(A1,23,2),ifna(--regexextract(A1,"G(\d\d)"),-1)}

```

Put the input in cell `A1` and the formula in `B1`. Output in cells `B1:D1`.

Simple text manipulation in an { array expression }.
> 5 votes

# Answer
# Jelly, ~~18~~ 15 bytes

```
Ḳ4ịs3ḣ3f€ØDȯ€-V

```

Try it online!

A monadic link taking a METAR-formatted string and returning a list of integers. (Has the side effect of sometimes outputting some zeros to STDOUT which is permitted as per this meta post.)

*Thanks to @JonathanAlkan for saving three bytes!*

## Explanation

```
Ḳ                   | Split at spaces
 4ị                 | 4th sublist
   s3               | Split into pieces of length 3
     ḣ3             | First three
       f€ØD         | Keep only digits
           ȯ€-      | Replace blanks with -1
              V     | Interpret as Jelly code

```
> 5 votes

# Answer
# Charcoal, ~~17~~ ~~16~~ 15 bytes

```
…ＩＥ⪪ε³⁻Σ⁺ψι›ια³

```

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

```
    ε           Fourth word of input
   ⪪ ³          Split into groups of three characters
  Ｅ             Map over groups
         ψ      Null byte
        ⁺       Concatenated with
          ι     Current group
       Σ        Extract embedded integer
      ⁻         Minus
            ι   Current group
           ›     Is greater than
             α   Predefined variable uppercase alphabet
 Ｉ              Cast to string
…              ³ Take the first three
                Implicitly print

```

In practice `-1` is only needed for `VRB` and `T` so comparing to any string between `99` and `T` would work.
> 5 votes

# Answer
# Retina 0.8.2, 39 bytes

```
4=M!`\w+
3M!`.{1,3}
%(`\D

^0+\B

^$
-1

```

Try it online! Outputs the values on separate lines but link is to test suite that joins on commas for convenience. Explanation:

```
4=M!`\w+

```

Extract the fourth word.

```
3M!`.{1,3}

```

Split it into three triplets.

```
3G`

```

Keep only three.

```
%(`

```

Apply the remainder of the script to each line independently.

```
\D

```

Delete non-digits.

```
^0+\B

```

Delete leading zeros.

```
^$
-1

```

Insert `-1` on empty lines.
> 4 votes

# Answer
# JavaScript, ~~54~~ 45 bytes

```
s=>[19,22,25].map(x=>~(-1-s.substr(x,x/7^1)))

```

Try it online!

−9 by using indices directly in the input string and the (deprecated) `String.prototype.substr` method.

---

* `[19,22,25].map(…)`: Produce an array of the results of calling the function inside with argument 19, 22, and 25.
* `s.substr(x,x/7^1)`: Take the substring starting at index `x`, of length 3 for `x`=19, or length 2 for the other values of `x`. This extracts the digits that make up the desired values; in the absence of a number, the substring is `VRB` from `x`=19 or `T`  from `x`=25.
* `(-1-…)`: Subtract it from −1, implicitly performing numeric coercion. If the string does not express a number, it becomes `NaN`, and the subtraction produces `NaN`.
* `~…`: Bitwise NOT. This reproduces the original number, while `NaN` becomes 0 when converted to a 32-bit integer, and then the bitwise NOT of 0 is −1.
> 4 votes

# Answer
# sed -E, ~~81~~ 75 bytes

*-6 bytes thanks to @Jordan*

```
s/.{19}(...)(..)(G(..))?.*/ \1 \2 \4/;s/ VRB| $/ -1/g;s/ 0*(\w)/ \1/g;s/ //

```

Attempt This Online!
> 3 votes

# Answer
# 05AB1E, 13 bytes

```
#3è3ô3£εþ®s‚à

```

Try it online or verify all test cases.

**Explanation:**

```
#             # Split the (implicit) input-string on spaces
 3è           # Pop and keep the (0-based) 3rd item (aka the fourth item)
   3ô         # Pop and split this substring into parts of size 3
     3£       # Pop and only keep the first three parts
       ε      # Map over this triplet of parts:
        þ     #  Only keep the digits of the current string-part
         ®s‚  #  Pair it with a leading -1 (push -1; swap; pair top two)
            à #  Pop and push the maximum of this pair, which serves two purposes:
              #  1. It will convert the values in the pair to integers to determine the
              #     max, removing the leading 0s from the digit-strings
              #  2. It will take the first item if the pair contains a non-number, hence
              #     the need for the swap `s` when pairing it to the empty string
              # (after which the resulting triplet of integers is output implicitly)

```
> 3 votes

# Answer
# Uiua 0.4.1, 80 bytes

```
⊐∵parse≡(⊂⊂∩□⊃((∘|"¯1")≍"VRB"⊔.↙3|⊃↙(□↘+1)⊗@G.(⊂:"G¯1"|∘)∊@G.↙-2⧻.↘3)⊔⊡3⊜□≠@ .⊔)

```

See it in action
> 2 votes

# Answer
# Python3, 104 bytes

```
lambda s:((-1 if'VRB'in(s:=s.split()[3])else s[:3]),s[3:5],s[(i:=s.index('G'))+1:i+3]if'G'in s else -1)

```

Try it online!

Another approach (much shorter and nicer):

# Python3, 83 bytes

Thanks to Jonathan!

```
lambda s:[int(''.join(c for c in s.split()[3][i:i+3]if':'>c)or'-1')for i in(0,3,6)]

```

Try it online!
> 2 votes

# Answer
# Perl 5 `-n`, 59 bytes

```
/ (...)(..)G?(..)?KT/;say for$1eq VRB?-1:$1*1,$2*1,$3*1||-1

```

Try it online!
> 2 votes

# Answer
# sclin, 33 bytes

```
w<>3:3/`3tk"\D"""\ /#1_.||# map N

```

Try it on scline!

## Explanation

Prettified code:

```
w<> 3: 3/` 3tk  .. get 4th word, chunk by 3s, take 3
"\D"""\ /#      .. (vectorized) remove non-digits
1_.||# map      .. replace empty (falsy) with -1
N               .. (vectorized) convert to number

```
> 1 votes

---
Tags: code-golf, parsing
---


title: Even or odd: three player

text:
# Question
Title: Even or odd: three player
It's a three players game, play with one hand.

At same time, each player show his hand with 0 to 5 fingers extended.

If all player show same kind of (even or odd) number, there is no winner. But else, the player showing different kind the two other win.

```
 P l a y e r s
A      B      C       Winner

Even   Even   Even    No winner
Odd    Odd    Odd     No winner
Even   Odd    Odd     Player A
Odd    Even   Even    Player A
Even   Odd    Even    Player B
Odd    Even   Odd     Player B
Odd    Odd    Even    Player C
Even   Even   Odd     Player C

```

The requested tool could use arguments (3 arguments as numeric between 0 and 5) or STDIN (3 values by line, separated by spaces).

There is no need to check input: Irregular input could produce unexpected output.

Arguments or values on line is given from left to right, from *player A* to *player C*.

Output must only contain `A`, `B` or `C` (capitalized) or the string `no one` (in lower case, with a regular space).

Tool may work only once or as a filter on all input lines.

Shortest code win.

# Answer
> 12 votes
## APL (~~34~~ 30)

```
(1⍳⍨+/∘.=⍨2|⎕)⊃'ABC',⊂'no one'

```

Explanation:

* `2|⎕`: read a line of input, take the mod-2 of each number (giving a list, i.e. `1 0 1`)
* `∘.=⍨`: compare each element in the vector to each element in the vector, giving a matrix
* `+/`: sum the rows of the matrix, giving for each element how many elements it was equal to. If there were two the same and one different, we now have a vector like `2 1 2` where the `1` denotes who was different. If they were all the same, we get `3 3 3`.
* `1⍳⍨`: find the position of the `1`. If there is no `1`, this returns one more than the length of the vector, in this case `4`.
* `⊃'ABC',⊂'no one'`: display the string at the given index.

# Answer
> 8 votes
# Mathematica, ~~45 43 42~~ 41 chars

```
f="no one"[A,B,C]〚Mod[Tr@#-#,2].{2,1,0}〛&

```

### Example:

```
f[{0 ,0, 0}]

```

> no one

```
f[{1, 3, 5}]

```

> no one

```
f[{2, 3, 5}]

```

> A

```
f[{2, 3, 4}]

```

> B

---

### Another solution with ~~43~~ 42 chars:

```
f=Mod[Tr@#-#-1,2].{A,B,C}/._+__->"no one"&

```

# Answer
> 5 votes
## Powershell, 65

```
param($a,$b,$c)"@ABCCBA@"[$a%2+$b%2*2+$c%2*4]-replace"@","no one"

```

# Answer
> 4 votes
## Befunge-98, ~~61 50~~ 45 characters

```
&&&:11p+2%2*\11g+2%+:"@"+#@\#,_0"eno on">:#,_

```

Uses Fors' clever expression to shave off yet a few more characters. Now single-line (i.e. Unefunge-compatible)! Reads until a game is won; add `@` at the end for a one-shot program.

~~Treats input mod 2 as a binary number, as with my JS answer, then relies on lookup for A-C and falls back to 'no one' if out-of-bounds (by testing if the character is ≥'A', which allows me to use nearby code as data :D).~~

~~Variation that reads a line of input, produces output, reads a new line of input, etc until a game is decided (i.e. not 'no one'):<br>```
&2%4*&2%2*&2%++1g:" "#@-#,_0"eno on">:#,_
 CBAABC

```~~

# Answer
> 4 votes
# C: 88 characters

Unfortunately C, as always, requires quite a lot of unnecessary junk. But still, in which other language can one write `=**++b+**(++` and it actually means something? Quite simply sublime.

```
main(int a,char**b){(a=**++b+**(++b+1)&1|2*(**b+**++b&1))?putchar(a+64):puts("no one");}

```

Simply pass three numbers as arguments, and voilà!

# Answer
> 4 votes
## APL, 30

```
(1+2=/2|⎕)⊃'BA'('C',⊂'no one')

```

If I am allowed to change system variables by configuration, 2 chars can be shaved off. (Specifically, changing index origin `⎕IO` to 0)

**The crucial bit**

If we represent all odds the same way and all evens the same way, then a pair-wise equality operation can distinguish all 4 cases: `0 0` for B wins, `0 1` for A wins, etc.

**Explanation**

`2|⎕` Takes input and mod 2
`2=/` Pair-wise equality
`1+` Add 1 for indexing (APL arrays are 1-based by default)

`'BA'('C',⊂'no one')` Nested array
Picks out the correct element from the nested array

# Answer
> 3 votes
## Ruby, 61 chars

```
w=0
$*.map{|p|w+=w+p.to_i%2}
$><<%w(no\ one C B A)[w>3?w^7:w]

```

# Answer
> 3 votes
## GolfScript (31 chars)

```
~]{1&}%.$1=!?)'no one
A
B
C'n/=

```

Very simple logic: reduce the input modulo 2, then sort a copy. The middle item of the sorted array is in the majority, so look for an index which is different (and hence in the minority).

# Answer
> 3 votes
# Ruby (function body), 42 chars

Assuming 3 numerical arguments `a`, `b`, and `c`:

```
['zCBAABCz'[a%2*4|b%2*2|c%2],'no one'].min

```

# Ruby (command line tool), 61 chars

Version 1 comes in at 62 chars:

```
$><<["zCBAABCz"[$*.reduce(0){|i,n|i*2|n.to_i%2}],'no one'].min

```

But, by piggybacking off of Darren Stone's answer, Version 2 gets down to 61 chars:

```
i=0;$*.map{|n|i+=i+n.to_i%2};$><<['zCBAABCz'[i],'no one'].min

```

# Answer
> 3 votes
# Python 2, 54

```
f=lambda a,b,c:[['no one','C'],'BA'][(a^b)&1][(a^c)&1]

```

# Answer
> 2 votes
### JavaScript (node), 87 characters

```
p=process.argv;console.log("ABC"[3-Math.min(x=p[2]%2*4+p[3]%2*2+p[4]%2,7-x)]||"no one")

```

To get the ball rolling... expects input as three extra arguments. Makes use of the following pattern for input/output (`/` represents "no-one"):

```
  A B C  res  #
 ───────────────
  0 0 0   /   0
  0 0 1   C   1
  0 1 0   B   2
  0 1 1   A   3
  1 0 0   A   4
  1 0 1   B   5
  1 1 0   C   6
  1 1 1   /   7

```

# Answer
> 2 votes
Perl, 84 characters.

```
$x=oct"0b".join"",map{$_%2}<>=~/(\d)/g;print"",('no one','C','B','A')[$x>=4?7-$x:$x]

```
* `<>=~/(\d)/g` parses the input line into distinct digits
* `map{$_%2` takes this list and computes value mod 2 (even or odd)
* `oct"0b".join"",` takes this list of mod values, joins them into a string, appends an octal specifier, and converts the string to a number.

Basically what I did was to create a truth table, and then carefully reordered it so I had an inversion operation around `$x == 4`. So if `$x >=4`, we did the inversion `[$x>=4?7-$x:$x]` which we used to index into the array `('no one','C','B','A')`

Its not the shortest possible code, but its actually not line noise ... which is remarkable in and of itself.

Perl: 74 characters + 3 flags = 77, run with `perl -anE '(code)'`

```
s/(\d)\s*/$1%2/eg;$x=oct"0b".$_;say"",("no one","C","B","A")[$x>3?7-$x:$x]

```

This is an improvement, by leveraging autosplit (the -a), say (the -E), and finally figuring out what was wrong with the comparison.

# Answer
> 2 votes
### GolfScript, 36 35 33 characters

```
~]0\{1&\.++}/'no one
C
B
A'n/.$+=

```

Takes input as described from STDIN. You can also test the code online.

# Answer
> 2 votes
## Haskell, 97

```
main=interact$(["no one","A","B","C"]!!).(\x->min x$7-x).foldr(\y x->x*2+mod y 2)0.map read.words

```

# Answer
> 2 votes
# Common Lisp, 114 106 70 chars

From the three values create a pair representing difference in parity between adjacent elements. Treat that as a binary number to index into result list.

```
(defun f(a b c)(elt'(no_one c a b)(+(mod(- b c)2)(*(mod(- a b)2)2)))))

```

Older algorithm:

```
(defun f(h)(let*((o(mapcar #'oddp h))(p(position 1(mapcar(lambda(x)(count x o))o))))(if p(elt'(a b c)p)"no one")))

```

# Answer
> 1 votes
# Mathematica ~~100 94~~ 89

```
f=If[(t=Tally[b=Boole@OddQ@#][[-1,2]])==1,{"A","B","C"}[[Position[b,t][[-1,1]]]],"no one"]&

```

---

**Testing**

```
f[{5, 3, 1}]
f[{2, 0, 4}]
f[{0, 1, 2}]
f[{0, 1, 3}]
f[{1, 3, 0}]

```

> "no one"
> "no one"
> "B"
> "A"
> "C"

# Answer
> 1 votes
## R 67

```
z="no one";c("A","B","C",z,z)[match(2-sum(x<-scan()%%2),c(x,2,-1))]

```

# Answer
> 1 votes
# C, 85 chars

```
main(int j,char**p){puts("C\0A\0B\0no one"+((**++p&1)*2+(**++p&1)^(**++p&1?0:3))*2);}

```

Not as short as my Ruby answer but I'm happy with it, considering the `main` cruft.

# Answer
> 1 votes
**Fish - 41**

```
:&+2%2*$&+2%+:"@"+!;$!o :?#"eno on"!;ooo<

```

Stole FireFly's befunge answer and ported it to fish because using registers in fish allows us to shave off some characters. Lost a few characters on not having the horizontal if operator though.

This takes parameters in through arguments.

```
python fish.py evenodd.fish -v 2 2 2
no one
python fish.py evenodd.fish -v 2 3 2
B
python fish.py evenodd.fish -v 2 3 3
A
python fish.py evenodd.fish -v 3 3 4
C

```

# Answer
> 1 votes
# Smalltalk, 128 characters

```
[:c|o:=c collect:[:e|e odd].k:=o collect:[:e|o occurrencesOf:e].u:=k indexOf:1.^(u>0)ifTrue:[#($a $b $c)at:u]ifFalse:['no one']]

```

send `value:` with a collection

# Answer
> 1 votes
# C ~~101~~ 96

C, probably the most trivial example (some ternary operations):

```
main(int v,char** c){(v=c[1]==c[2]?c[1]==c[3]?0:3:c[1]==c[3]?2:1)?puts("no one"):putchar(v+64);}

```

# Answer
> 1 votes
## JavaScript (ES6) / CoffeeScript, 50 bytes

Uses the truth table as per Firefly's answer but takes a more direct approach in character access:

```
f=(a,b,c)=>'CBAABC'[(a%2*4+b%2*2+c%2)-1]||'no one' // JavaScript

```

```
f=(a,b,c)->'CBAABC'[(a%2*4+b%2*2+c%2)-1]||'no one'  # CoffeeScript

```

### Demo

```
// Translated into ES5 for browser compatibility
f=function(a,b,c){return'CBAABC'[(a%2*4+b%2*2+c%2)-1]||'no one'}

//f=(a,b,c)=>'CBAABC'[(a%2*4+b%2*2+c%2)-1]||'no one'

for(i=6;i--;)
  for(j=6;j--;)
    for(k=6;k--;)
      O.innerHTML += i + ', ' + j + ', ' + k + ' => ' + f(i,j,k) + "\n"
```

```
<pre id=O></pre>
```

# Answer
> 1 votes
# Vyxal 3, 18 bytes

```
eB"0CBA"ṁi0"5FZᵃ”r

```

Try it Online!

-11 bytes thanks to @Aaroneous MIller

### Explanation (Outdated):

```
euL1=["5FZᵃ”|:1Cv[0Ḟ|1Ḟ}kAi
e                            ## Calculate every element of list if it's even
 uL1=                        ## Contains only even or odd integers?
     ["5FZᵃ”                 ## If so, print "no one"
            |                ## else
             :               ## duplicate
              1C             ## how many even integers the list has
                v            ## decremented
                 [0Ḟ         ## If the number of the even integers is 1, find 0
                    |1Ḟ}     ## if not, find 1
                        kA   ## uppercase alphabet
                          i  ## index

```

Created with the help of Luminespire.

# Answer
> 1 votes
# Perl 5 `-p`, 49 bytes

```
$_=(0,C,B,A,A..C)[oct"0b".s/./$&%2/ger]||"no one"

```

Try it online!

Takes input as three digits with no spaces between.

# Answer
> 0 votes
## Game Maker Language, 116

My new answer relies heavily on FireFly's formula:

```
a[1]="no one"a[2]='A'a[3]='B'a[4]='C'return a[(3-min(b=argument0 mod 2*4+argument1 mod 2*2+argument2 mod 2,7-b)||1)]

```

The **old** code compiled with uninitialized variables as 0, **183** characters:

```
a=argument0 mod 2b=argument1 mod 2c=argument2 mod 2if((a&&b&&c)||(!a&&!b&&!c))return "no one" else{if((a&&b)||(!a&&!b))return "C" else{if((a&&c)||(!a&&!c))return "B" else return "A"}}

```

**Edit #1** \- Whole different code

# Answer
> 0 votes
# Python 3, 115

```
l=[int(x)%2for x in input().split()];0if[print("ABC"[i])for i,x in enumerate(l)if l.count(x)%2]else print("no one")

```

# Answer
> 0 votes
## Two different method in two different languages + variations -\> 6 answers

There are essentially 2 way for this operation:

* **`array`** based: Built a binary number of 3 digit, than take answer from an array
* **`count`** based: Count even and odd, and look if there is a `count == 1`

### Perl 71 (array based + variation)

```
s/(.)\s*/$1&1/eg;$==oct"0b".$_;$==$=>3?7-$=:$=;say$=?chr 68-$=:"no one"

```

One of *my* shortest perl:

* `s/(.)\s*/$1&1/eg;` transform a string like `1 2 3` into `101`
* `$==oct"0b".$_;` transform binary to oct (same as dec, under 8)
* `$==$=>3?7-$=:$=;` if *`> 3`* oper `7-`. (From there `no one` == 0)
* `say$=?chr 68-$=:"no one"` if not `0`, print char from value, else print `no one`.

### Perl 71 (array based)

```
s/(.)\s*/$1&1/eg;$==oct"0b".$_;say@{["no one",qw{A B C}]}[$=>3?7-$=:$=]

```

slightly different in the print step: The output is based on an *'array'*.

### Perl 81 (count based)

```
$c=A;map{$a[$_%2]=$c++;$b[$_%2]++}split;say$b[0]==1?$a[0]:$b[0]==2?$a[1]:"no one"

```

Different meaning:

* `$c=A` Initialise a counter *c* with `A`.
* `map{$a[$_%2]=$c++;$b[$_%2]++}split` Counter *b* count even and odd, *a* only store which one
* `say$b[0]==1?$a[0]:` if *even* counter == 1 ? also print *even* player.
* `$b[0]==2?$a[1]:` if *even* counter == 2 ? also print *odd* player.
* `:"no one"` else print `no one`.

### Bash 85 (array based)

```
c=$((($1%2)<<2|($2&1)*2+($3%2)));((c>3))&&c=$((7-c));o=("no one" C B A);echo ${o[c]}

```

This is based on my second perl version:

* `c=$((($1%2)<<2|($2&1)*2+($3%2)))` make the index pos.
    + $1%2 transform first arg in binary by using `mod`
    + $2&1 transform second arg in binary by using `and`
    + \<\<2 *shift-to-the-left* is same than `*4`
    + \*2 *multiply by 2* is same than `<<1`.
* `((c>3))&&c=$((7-c))` if c \>= 4 then c = 7-c.
* `o=()` declare an array
* `echo ${o[c]}` based on array

### Bash 133 (count based)

```
a[$1&1]=A;a[$2&1]=B;a[$3&1]=C;((b[$1&1]++));((b[$2&1]++));((b[$3&1]++))
case $b in 1)echo ${a[0]};;2)echo ${a[1]};;*)echo no one;esac

```
* `a[$1&1]=A;a[$2&1]=B;a[$3&1]=C` store player into variable *a\[even\]* and *a\[odd\]*
* `((b[$1&1]++));((b[$2&1]++));((b[$3&1]++))` count *even/odd* into b.
* `case $b in 1) echo ${a[0]}` in case even counter==1 print even player
* `2)echo ${a[1]};;` case even counter==2 print odd player
* `*)echo no one;esac` else print `no one`.

### Bash 133 (count based)

```
a[$1&1]=A;a[$2&1]=B;a[$3&1]=C;((b[$1&1]++));((b[$2&1]++));((b[$3&1]++))
((b==1))&&echo ${a[0]}||(((b==2))&&echo ${a[1]}||echo no one)

```

Same version, using bash's condition and command group instead of `case ... esac`

# Answer
> 0 votes
# Python 3, 114

```
r=[0,3,2,1,1,2,3,0][int("".join(map(str,(int(x)%2for x in input().split()))),2)];print("ABC"[r-1]if r else"no one")

```

# Answer
> 0 votes
# Python 3, 80 chars

```
r=int(input().replace(' ',''),2)
print(['no one','C','B','A'][7-r if r>3 else r])

```

Note: input must be '1' \[odd\] or '0' \[even\]. For example:

```
> 1 1 0
C
> 1 1 1
no one

```

# Answer
> 0 votes
# Clojure, 116

```
(fn[& h](let[a(map #(bit-and % 1)h)](["no one"\A\B\C](+(.indexOf(map(fn[x](reduce +(map #(if(= x %)1 0)a)))a)1)1))))

```

# Answer
> 0 votes
## vba, 116

```
Function z(q,r,s)
a="A":b="B":c="C":d="no one"
z=Array(d,c,b,a,a,b,c,d)((q And 1)*4+(r And 1)*2+(s And 1))
End Function

```

call with `?z(1,2,3)` or assign to a variable with `q=z(1,2,3)`, or even use as a UDF within excel, and use `=z(1,2,3)` in your excel formula

# Answer
> 0 votes
Java, 226 chars

```
void func(int a, int b, int c){
    a = a%2;
    b = b%2;
    c = c%2;
    String out = "B";
    if((a+b+c)==0 || (a+b+c)==3)
        out = "no one";
    else if(a==b)
        out = "C";
    else if(b==c)
        out = "A";
    System.out.println(out);
}

```

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