Controllo marcia moto!


36

Alcuni di voi potrebbero avere familiarità con il modo in cui una moto cambia. Ma per quelli che non lo fanno, sembra così

6

5

4

3

2

N

1

Ora voglio sapere in quali attrezzi mi trovo dopo aver eseguito alcuni turni su e giù. Il programma dovrebbe funzionare da neutrale.

Input di esempio:

V^^

Uscita campione:

2

Come puoi vedere ho spostato una volta da N a 1 e ho spostato due volte in seconda marcia.

Questo è un codice golf. Vince la risposta più breve in byte.

Nota: l'ingresso può contenere 2 caratteri. Può essere U e D per su e giù o qualunque cosa tu voglia , deve essere una stringa . Non è possibile spostarsi oltre la 1a o la 6a marcia. Se sei al 6 ° posto e cambia di nuovo, rimarrà al 6 °. In bocca al lupo!


5
La prossima volta, si prega di inviare la sfida alla sandbox per ottenere un feedback prima di pubblicarlo su main
f 23nɛtɪk

1
@seshoumara gli unici due requisiti sono che deve essere una stringa e che puoi inserire solo 2 caratteri. Quindi potrebbe usare una newline come personaggio. ma se lo usassi per un altro motivo, non mi dispiace davvero. sarebbe interessante vedere cosa hai in mente. ma dai una breve spiegazione del perché l'hai fatto in questo modo se lo fai. GL!
Martijn Vissers,

4
È un peccato che questo non spieghi lo spostamento di mezzo passo tra 1 e N. Sarebbe bello poter non solo andare 2 N 1 N 2 3, ma anche andare 2 1 N 2 3
Cort Ammon

2
Sono d'accordo con @CortAmmon - c'è un singolo spostamento tra 1 e 2. È mezzo turno dove si trova il neutro.
Džuris,

2
non tutte le motociclette cambiano in questo modo. La maggior parte delle motociclette senza frizione cambiano in N-1-2-3-4 (o N-1-2-3 su alcuni veicoli molto antichi). Non hanno equipaggiamento 5 o 6 e usano un ingranaggio rotondo, cioè quando è 4 aumentando l'ingranaggio lo farà avvolgere su N.
phuclv

Risposte:


15

JavaScript (ES6), 49 48 47 46 byte

si attende:

  • 1 per giù
  • 7 Fino
f=([c,...s],g=2)=>c?f(s,g-c&7||g):'1N'[--g]||g

Formattato e commentato

f = (                   // f is a recursive function which takes:
  [c,                   // - c = next character in input string
      ...s],            // - s = remaining characters
  g = 2                 // - g = current gear, with default = neutral = 2
) =>                    //
  c ?                   // if there's still a character to process:
    f(                  //   do a recursive call with:
      s,                //     - the remaining characters
      g - c & 7 ||      //     - the updated gear if it is valid
      g                 //       or the previous gear if not
    )                   //
  :                     // else:
    '1N'[--g] ||        //   decrement g and output '1' for g = 0, 'N' for g = 1,
    g                   //   or simply the corresponding digit for other values

Gli ingranaggi sono mappati come segue:

g MOD 8 = 0 1 2 3 4 5 6 7
          ---------------
gear    = X 1 N 2 3 4 5 6       (where 'X' is an invalid state)

Ciò ci consente di verificare facilmente la validità dell'attrezzatura attuale con:

(g & 7) != 0

dimostrazione


7

05AB1E , 22 20 byte

Îvy<+®‚Z5‚W}6LÀ'N¸ìè

Provalo online!

Spiegazione

Î                      # push 0 (accumulator) and input
 v         }           # for each in input
  y<+                  # decrement current element and add to accumulator
     ®‚Z               # take maximum of current value and -1
        5‚W            # take minimum of current value and 5
            6L         # push the range [1 ... 6]
              À        # rotate left
               'N¸ì    # prepend the letter "N" producing the list [N, 2, 3, 4, 5, 6, 1]
                   è   # index into this list with the value produced by the loop

6

MATL, 32 28 23 byte

5 byte salvati grazie a @Luis

'234561N'j!Uq[aA]&Ys0))

Questa soluzione utilizza '2'per up-shift e '0'down-shift.

Provalo su MATL Online

Spiegazione

'234561N'   % Push the string literal to the stack
j           % Grab the input as a string
!U          % Convert the input to a numeric array based on the characters.
q           % Subtract 1 to turn '2' into 1 and '0' into -1
[aA]        % Push the array [-1 5] to the stack
&Ys         % Compute the cumulative sum using the array [-1, 5] as
            % the upper and lower limits at each point
0)          % Get the last value from the cumulative sum
)           % Use this to index into the initial string literal.
            % Implicitly display the result

@Lifeless Aggiornato con una spiegazione
Suever

Molto bella! posso chiedere perché la stringa è 234561N anziché 1n23456 o 65432n1? Ho anche trovato un difetto! Se continui a cambiare marcia dovrebbe rimanere in sesta marcia ma restituisce N
Martijn Vissers il

1
Bello! Non sapevo del trucco dei limiti in cumsum
B. Mehta,

1
@ B.Mehta Neanche a me! Luis lo ha raccomandato
Suever

1
@ B.Mehta Inoltre, sentiti libero di unirti a noi nella chat room MATL !
Suever

6

V , 20 , 15 byte

:sil!î¬61énÀxVp

Provalo online!

L'input è una stringa di caratteri h(su) e l(giù).

Grazie a @nmjcman per aver salvato 5 byte e avermi insegnato su una funzione vim che non avevo mai saputo!

Se potessimo presumere che l'input non esca mai dai limiti, sarebbe semplicemente di 9 byte:

¬61énÀxVp

Ma sfortunatamente non è permesso.

Spiegazione:

:sil!           " If the cursor goes out of bounds, ignore it and continue
     î          " Run the following keystrokes as V code, rather than vimscript:
      ¬61       "   Insert the string "654321". This will leave the cursor on the '1'
         én     "   Insert an 'n'
           À    "   Run the first arg as V code. This will move left and right a bunch of times
            x   "   Delete whatever character we ended up on
             V  "   Select this whole line,
              p "   And replace it with the character we just deleted

2
Inoltre, provalo online! Compressione V Questo è figo.
nmjcman101,

In realtà, penso che questo non funzioni perché andare oltre o sotto 1/6 rompe la macro: /
nmjcman101

Perché la risposta a 9 byte non è consentita?
Albert Renshaw,

@AlbertRenshaw Non riesce se si tenta di passare oltre la 1a o la 6a marcia. Ad esempio Provalo online! dovrebbe produrre n, no 1.
DJMcMayhem

Oh, vedo, ho pensato che per input sia sempre valido intendevi personaggi non mobili. Ancora una bella risposta anche se non valida
Albert Renshaw,

6

Java 7, 106 105 103 byte

char c(String s){int r=1;for(int c:s.toCharArray())r+=c<99?1:-1;return"1N23456".charAt(r<0?0:r>6?6:r);}

Spiegazione:

char c(String s){                // Method with String input and character return-type
  int r = 1;                     // Result-index (0-indexed and starting at 1)
  for(int c : s.toCharArray()){  // Loop over all characters in the input String
    r += c < 99 ?                //  If the current character is '^':
           1                     //   Raise the result-index by 1
         :                       //  If it is 'v' instead:
           -1;                   //   Decrease the result-index by 1
  }
  return "1N23456".charAt(       // Return the character based on the return-index:
           r < 0 ?               //  If the result-index is below 0
                  0              //   Use 0 instead
                 : r > 6 ?       //  Else-if the result-index is above 6
                          6      //   Use 6 instead
                         :       //  Else
                          r);    //   Use the result-index
}

Codice di prova:

Provalo qui.

class M{
  static char c(String s){int r=1;for(int c:s.toCharArray())r+=c<99?1:-1;return"1N23456".charAt(r<0?0:r>6?6:r);}

  public static void main(String[] a){
    System.out.println(c("v^^"));
    System.out.println(c("^^^^^^^^"));
    System.out.println(c("vvvv^^^vvvv"));
    System.out.println(c("^v^v^v^v"));
  }
}

Produzione:

2
6
1
N

5

Haskell, 59 53 51 byte

("1N23456"!!).foldl(\l c->max 0$min 6$l+read[c]-1)1

Utilizza 0per down e 2up. Esempio di utilizzo:

(("1N23456"!!).foldl(\l c->max 0$min 6$l+read[c]-1)1) "0002"

Grazie a @xnor per il decollo di 6 byte! Inoltre, risulta che non ho bisogno di un nome di funzione o parentesi quindi sono altri 2 byte.


Se prendi i caratteri di input come 0 e 2, puoi farlo read[c]-2.
xnor

Benvenuti in PPCG! Anche le funzioni anonime vanno bene, quindi non è necessario g=.
Laikoni,

@Laikoni Dovrei avvolgerlo tra parentesi, giusto? Ciò non cambierebbe il conteggio dei byte, quindi ho pensato di lasciare il g=perché è più chiaro
user1472751


4

JavaScript (ES6), 48 58 byte

s=>"1N23456"[[1,...s].reduce((a,b)=>a?a<6?+b?a+1:a-1:6:0)]

uso

Assegnalo a una funzione e quindi chiamalo. L'input è una stringa che contiene a 1per uno spostamento verso l'alto e a 0per uno spostamento verso il basso.

f=s=>"1N23456"[[1,...s].reduce((a,b)=>a?a<6?+b?++a:a--:6:0)]
f("011")
-> "2"
f("0")
-> "1"
f("01")
-> "N"

f (0) restituisce 1 non N ... e il codice restituisce indefinito se si sposta da 6 in su o in basso da 1
fəˈnɛtɪk

Buona pesca. Risolto al costo di due byte
Luca,

Non funziona input come quello f("001")che dovrebbe restituire N (marcia in basso a 1, marcia in basso rimanendo a 1, marcia in alto fino a N)
Emigna,

Non dovrebbe andare in giro. Dovrebbe rimanere a 6 se spostato da 6 a 6 e rimanere a 1 se spostato da 1. Inoltre, dà comunque indefinito se si
passa

4

PHP 7.1, 71 byte

for(;$c=$argv[1][$i++];))$g=max(-1,min($g+=$c<=>X,5));echo N234561[$g];

passa $gda -1 a 5, usa un offset di stringa negativo per la prima marcia.
Esegui con -nr, fornisce lo spostamento della stringa come argomento della riga di comando.


4

Gelatina , 17 14 byte

1;r2ị$¥/CỊ¡o”N

Utilizza 6per su e 0giù.

Provalo online!

Come funziona

1;r2ị$¥/CỊ¡o”N  Main link. Argument: s (string of 6's and 0's)

1;              Prepend a 1 (integer) to the string/character array s.
       /        Reduce the result by the following dyadic link.
                Let's call the arguments x and y.
      ¥           Create a dyadic chain of 2 links:
  r                 Construct the range [x, ..., y] (increasing or decreasing).
                    y will be a character, but 'r' casts both argument to int.
                    This is intended for use with floats, but it works just as well
                    when the argument is a digit.
     $              Create a monadic chain of two links:
   2ị                 Take the second element of the constructed range.
                  When y = 6 > x, this gives x + 1.
                  When y = 0 < x, this gives x - 1.
                  When y = x, the range is a singleton array, so this gives x.
          ¡     Conditional application:
         Ị        If the previous result is insignificant (0 or 1):
        C           Subtract it from 1.
                This swaps 0 and 1 without affecting the other potential outcomes.
           o”N  Logical OR with 'N', replacing 0 with that character.

2

Rubino, 58 byte

->s{a=1;s.chars{|b|a-=[a<=>0,a<=>6][b<=>?v]};"1N23456"[a]}

L'input previsto è 'v' per uno spostamento verso il basso e '^' per uno spostamento verso l'alto


2

Elaborazione JS (modificato) 121 byte

var g="1N23456",a="",c=0; for(var i=0;i<a.length;i++){if(a[i]==="d"&&c>0){c--;}else if(c<6&&a[i]==="u"){c++;}}println(g[c]);

Ungolfed

var g=[1,"N",2,3,4,5,6],a="",c=0;
for(var i=0;i<a.length;i++)
{if(a[i]==="d"&&c>0)
{
    c--;

}else if(c<6&&a[i]==="u")
{
    c++;

}

}
println(g[c]);

Provalo online!

Sono andato con i pigiami perché lo conosco bene. L'unico problema è che la versione che uso è molto tipizzata. Non posso tralasciare parentesi e molti altri trucchi. È abbastanza semplice L'input dovrebbe andare nella variabile ae richiede lettere minuscole u d. Il programma esegue il ciclo fino a quando non raggiunge la fine della stringa e ogni iterazione controlla se è au o a d. Se lo è e non proverà a "passare" oltre dove puoi, cambia. Alla fine stampo i risultati!


Se la tua versione consente agli operatori ternari, potresti essere in grado di riscrivere i tuoi if in un modo molto più breve, credo.
Bojidar Marinov,

The input should go into the variable aL'uso dell'input codificato non è un metodo di input predefinito, vedere qui .
Laikoni,

@Laikoni davvero? Questo è sciocco. Non ho modo migliore. Se devo rifarlo, saranno circa 100 byte più lunghi
Christopher,

Non puoi semplicemente racchiudere il tuo codice in una funzione? Per esempio. void f(String[] a){...}Sono quasi 100 byte.
Laikoni,

@Laikoni In Khan Academy ProcessingJS, è puro JS, e quindi non ha String o vuoto. Ma hai ragione, una funzione sarebbe molto più breve
Kritixi Lithos il

2

k, 25 byte

"1N23456"@{6&0|x+y-92}/1,

Prende l'input come stringa e lo usa [per il downshift e] per l'upshift, perché sono situati convenientemente.

"1N23456"@                / the numbers 0 to 6 are used for the gears,
                          / this turns them into the correct number/letter
                       1, / prepend 1 because this is our initial gear
          {          }/   / fold the function through the list
                          / x is before, y is the next character
                 y-92     / subtract 92, which is between "[" and "]"
                          / "[" becomes -1 and "]" becomes 1
               x+         / add it to what we had before
           6&0|           / use max and min to set boundaries 6 and 0

Esempi:

 shift:"1N23456"@{6&0|x+y-92}/1,
 shift"[]]"
"2"
 shift"]]]]]]]]"
"6"
 shift"[[[[]]][[[["
"1"
 shift"[][][][]"
"N"
 shift"[[[[[[[[]"
"N"
 shift"]]]]]]]]["
"5"

2

GNU sed , 89 87 + 1 (flag r) = 88 byte

Poiché sed non ha tipi interi o operazioni aritmetiche, la soluzione viene raggiunta usando solo espressioni regolari.

s:$:65432Nx1:
:
/6x/!s:^U(.*)(.)x:\1x\2:
s:^D(.*)x(.):\1\2x:
t
s:U|D::
t
s:.*(.)x.*:\1:

It works by sliding the pointer x based on each input shift, left (for Up) or right (for Down), along a non-wrapping tape that contains only the cells 65432N1. The answer at the end is the value in the cell left of the pointer.

Example run: or Try it online!

sed -rf gear.sed <<< "UUUUUUD"
5

Explanation:

s:$:65432Nx1:              # assign initial tape and pointer
:                          # start loop
/6x/!s:^U(.*)(.)x:\1x\2:   # if shift 'U', slide `x` to left, but not past the edge
s:^D(.*)x(.):\1\2x:        # if shift 'D', slide `x` to right, -||-
t                          # repeat
s:U|D::                    # if a shift couldn't be applied, delete it "manually",
t                          # and jump to the start of the loop again
s:.*(.)x.*:\1:             # print value left of pointer `x` (answer)

Here is 76 bytes, but it outputs in unary.
Riley

@Riley Unary, of course! Well, your solution is different, so why not post it!
seshoumara

Yours gave me the inspiration for it. I figured I'd let you use it if you wanted.
Riley

@Riley Then I'll make a separate section with your version and credit you.
seshoumara

I'll just post my own :)
Riley

2

GNU sed, 76 73 bytes

Includes +1 for -r

s/$/1/
:
/1{6}/!s/^U(.*)/\11/
s/^D(.*)1/\1/
t
s/U|D//
t
s/^1$/N/
s/^$/1/

Output is in unary except neutral, which is still N (see this consensus).

Try it online!

This basically counts up and down in unary then converts 1 to N and 0 to 1.

s/$/1/               # add 1 to the end (the starting value)
:                    # loop start
/1{6}/!s/^U(.*)/\11/ # If the string starts with 'U' and doesn't have 6 ones, increment
s/^D(.*)1/\1/        # If the string starts with 'D' decrement (but not past 0)
t                    # if something changed loop back
s/U|D//              # if the U or D couldn't be applied, remove it.
t                    # if something changed loop back
s/^1$/N/             # replace 1 with N
s/^$/1/              # if "0", replace with 1

Your sed version can be shorter by 4 bytes I think, if you work with 1 as the starting value, as N, and nothing as 1. s/$/1/;:;/1{6}/!s/^U(.*)/\11/;s/^D(.*)1/\1/;t;s/U|D//;t;s/^1$/N/;s/^$/1/
seshoumara

2

Rebol, 96 93 bytes

f: func[s][g: next"1N23456"parse s[any["D"(g: back g)|"U"(unless tail? x: next g[g: x])]]g/1]

Ungolfed:

f: func [s] [
    g: next "1N23456"
    parse s [
        any [
              "D" (g: back g)
            | "U" (unless tail? x: next g [g: x])
        ]
    ]
    g/1
]

Example usage (in Rebol console):

>> print f "DUU"         
2

>> print f "DDDUU"
2

>> print f "UUUUUUUUU"  
6

>> print f "UUUUUUUUUD"
5

2

><>, 35 bytes

An enthusiastic piece of code that encourages you to drive above the speed limit.

Accepts any two inputs whose code modulo 3 are 0 and 2, for example 0 and 2.
For extra fishiness, I recommend the use of < and >.

1i:0(?;3%1-+:0(?0:6)?6:1go!
1N23456

Explanation :

1i:0(?;3%1-+:0(?0:6)?6:1go!
1                             # initial position
 i                            # read the next char
  :0(?;                       # copies it, test copy against 0, if lower stops (EOF detection)
       3%1-                   # map the char to -1 or 1
           +                  # add it to the position
            :0(?0             # if the new position is lower than 0, set to 0
                 :6)?6        # if the new position is greater than 6, set to 6
                      :1go    # output a character from line 1 at the position
                          !   # loops and skip the position initialisation

You can try it here !


1

SpecBAS - 102

1 g=2: INPUT s$
2 FOR i=1 TO LEN s$
3 g+=(s$(i)="^" AND g<7)-(s$(i)="v" AND g>1)
4 NEXT i
5  ?"1N23456"(g)

Moves the index of the string depending on input and prints the relevant character.


1

Pyth, 32 bytes

J1VQ=JhtS[06+J-qNbqNd;?qJ1\N?JJ1

Uses space and newline for down and up.

Explanation

J1VQ=JhtS[06+J-qNbqNd;?qJ1\N?JJ1
J1                                 Initialize J to 1
  VQ                 ;             For each character in the input
            +J-qNbqNd              Increment or decrement J
      htS[06                       Get the middle sorted value of [0,6,J]
    =J                             Assign it to J
                      ?qJ1\N?JJ1   Change 1 to 'N' and 0 to 1

There's almost certainly a better way to do the incrementing and the output.


1

CJam, 24 22 bytes

"1N23456"1q{~0e>6e<}/=

Uses ( for down and ) for up.

Try it online!

Explanation

"1N23456"               e# Push the string containing all gears
         1              e# Push 1, the initial index
          q             e# Push the input
           {            e# For each character in the input
            ~           e#   Eval that character. ( is decrement and ) is increment.
             0e>        e#   Take the maximum of (0, index)
                6e<     e#   Take the minimum of (6, index)
                   }/   e# (end of block)
                     =  e# Take that index of the string

1

Batch, 144 bytes

@set/ps=
@set g=1
:l
@if %g% neq %s:~,1% set/ag+=%s:~,1%/3-1
@set s=%s:~1%
@if not "%s%"=="" goto l
@if %g%==1 (echo N)else cmd/cset/ag+!g

Takes input on STDIN, using 0 to go to a lower gear and 6 to go to a higher gear. These numbers were chosen to make it easy to ignore the current gear. Finally if the gear is 1 then N is printed otherwise 0 is converted to 1 and the gear is printed.


0

Javascript ES6 nonstrict, 136 120 chars

136 chars for V^

with({get x(){return Math.max(0,Math.min(y,6))},set x(v){y=v}})f=s=>eval(s.replace(/(V)|./g,(m,v)=>`x${"-+"[+!v]}=1,`,y=1)+'"1N"[x]||x')

with({get x(){return Math.max(0,Math.min(y,6))},set x(v){y=v}})
f=s=>eval(s.replace(/(V)|./g,(m,v)=>`x${"-+"[+!v]}=1,`,y=1)+'"1N"[x]||x')
console.log(f("V^^"))

120 chars for -+

with({get x(){return Math.max(0,Math.min(y,6))},set x(v){y=v}})f=s=>eval(s.replace(/./g,m=>`x${m}=1,`,y=1)+'"1N"[x]||x')

with({get x(){return Math.max(0,Math.min(y,6))},set x(v){y=v}})
f=s=>eval(s.replace(/./g,m=>`x${m}=1,`,y=1)+'"1N"[x]||x')
console.log(f("-++"))


0

Retina, 65 bytes

^
1 N23456
+(` (.)?(\w*6)u
$1 $2
)`(.)? (\w*6)d
 $1$2
.* (.).*
$1

Uses u and d for up and down.

Try it online!

Explanation

This program works by keeping 1N23456 behind the sequence of instructions. It keeps track of the current gear by having a space behind it. Then it takes one instruction at a time until there's no more.

^
1 N23456

Start by putting 1 N23456 before the input. The space before N indicates that N is the current gear.


+(` (.)?(\w*6)u
$1 $2
)`(.)? (\w*6)d
 $1$2

These are two replacement stages, grouped together, and run until they stop changing the string:

 (.)?(\w*6)u
$1 $2

The first one handles shifting the gear up. It will look for any number of gears after the space, followed by a 6, then followed by u (u indicates the instruction to gear shift up). If there were characters before the 6, it swaps the space with the character immediately after it, deletes the u, and leaves the rest of the string intact. Since the 6 is mandatory in the match, it will only swap the space with any character before the 6. It will never swap with the 6.

(.)? (\w*6)d
 $1$2

The second stage handles gear shifting down, and works similarly. It looks optionally for a character before the space, then some other gears after ending in 6, followed by d. It swaps the space with the character before it, deletes the d, and leaves the rest intact. If the space was at the start of the string, there was no match for a character before the space, so no swap occurs.


.* (.).*
$1

After neither of the above replacements can be done anymore, all gear shifts have been completed. The line is cleared of everything except the gear immediately after the space. This is the final gear.


0

Powershell, 112 87 85 bytes

$i=1;switch([char[]]$args[0]){'^'{if(5-gt$i){$i++}}'v'{if(1-le$i){$i--}}}'1N2345'[$i]

ungolfed

$i=1;                                # index which gear we are in
switch([char[]]$args[0]){            # loop over all elements using a switch
  '^'{if(5-gt$i){$i++}}             # if there is a ^ and we are not in sixth yet, shift up
  'v'{if(1-le$i){$i--}}             # if there is a v and we are not in first, shift down
}
'1N2345'[$i]                         # print the output

saved 25 bytes by reading the powershell codegolf tips

saved 2 bytes by flipping the gt/le operators


0

Perl 6, 144 bytes

my enum C <1 N 2 3 4 5 6>;my $n=prompt("");my $p=1;for split("",$n) ->$l {$l eq "u" && $p < 6 ?? ++$p !! 0;$l eq"d"&&$p>0 ?? --$p!!0};say C($p);

Works as it should, i believe. Improvements are welcome. First time using Perl for anything, but i loved the thought of the language, so i had to try.


0

Clojure, 74 bytes

#((vec "1N23456")(reduce(fn[c s](max 0(min 6((if(= s \^)inc dec)c))))1 %))

Folds over the shift string, maintaining an index as the accumulator. Each iteration it either increases or decreases the index, then clamps it to the range 0-6. Finally, a string holding the gears is indexed and returned.

Returns a Clojure character representing the current gear. Gear 1 is returned as \1, and gear 'N' is returned as \N.

Pre-golfed explanation. Follow the numbers, since it doesn't read well top-down.

; Expects ^ for shift-up, and V (or anything else) for shift down
; Returns a character representing the current gear
(defn shift [shift-str]
  ((vec "1N23456") ; 4. Then index the gear list with the calculated index, and return
   (reduce (fn [current-gear s] ; 1. Fold over the shift symbols
             (max 0 (min 6 ; 3. Clamp it to the range 0-6 so we don't overflow
                      ((if (= s \^) inc dec) ; 2. If the shift is up, increase, else decrease
                       current-gear))))
           1
           shift-str)))

0

Python 3, 67 63 bytes

k=1
for i in input():k+=[k<6,-(k>0)][i<'1']
print('1N23456'[k])

Pretty straightforward solution.

-4 bytes thanks to @ovs!

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.