Leer una línea de tiempo

11

Inspirado en Dibujar una línea de tiempo .

Dada una línea de tiempo de eventos, envíe la fecha para cada evento.

Se dará un cronograma en el formulario

    2000
--AF-C-------E--D---B--

Donde la primera línea muestra un punto en el tiempo conocido. El año conocido es siempre el carácter debajo del primer dígito del año conocido.

Puedes asumir:

  • En la línea de tiempo, cada personaje representa un año.
  • Siempre habrá al menos un evento
  • Los eventos no tienen que estar en orden
  • Puede asumir que todos los caracteres en el rango entre Ay el personaje más alejado está presente
  • Habrá a lo sumo 26 eventos
  • El punto conocido no tendrá ningún relleno a la derecha.
  • Puede haber números negativos tanto en el punto conocido como en la salida
  • No tendrá que manejar números mayores que 2 ^ 32
  • No tendrá que manejar rangos mayores de 2 ^ 8
  • Puede tomar la entrada como letras minúsculas en lugar de mayúsculas

Debe escribir un programa que tome una línea de tiempo en este formulario y muestre las fechas clave en orden (A, B, C, D ...)

Puede imprimir en una forma conveniente, pero debe tomar la entrada en el formato dado.

Casos de prueba:

    2000
--AF-C-------E--D---B--
[1998, 2016, 2001, 2012, 2009, 1999]

     10
--C-AB--D
[9, 10, 7, 13]

     0
--ABCDEFG--
[-3, -2, -1, 0, 1, 2, 3]

          5
--ABCDEFG--
[-3, -2, -1, 0, 1, 2, 3]
Azul
fuente
1
... entrada en el formato dado. ¿Es decir? ¿Una sola cadena con una nueva línea? o 2 cuerdas?
edc65
1
2 cadenas o una cadena con una nueva línea
Azul

Respuestas:

1

Pyth, 16 bytes

Toma la entrada como letras minúsculas en lugar de mayúsculas.

VS@GJw+-sz/zdxJN
drobilc
fuente
2

05AB1E , 19 18 bytes

Código:

ð¢>UágF²N>.bkX-¹+,

Explicación:

ð¢                   # Count the number of spaces before the year starts
  >                  # Increment by 1
   U                 # Pop and store this into X
    á                # Keep the alphabetic characters of the second input
     g               # Take the length
      F              # For N in range(0, length), do...
       ²             #   Take the second input
        N>           #   Push N and increment by 1
          .b         #   Converts 1 to A, 2 to B, etc.
            k        #   Find the index of that letter in the second input
             X       #   Push X
              -      #   index - X
               ¹     #   Get the first input, which contains the year
                +    #   Add to the difference of the index
                 ,   #   Pop and output the sum

Pruébalo en línea!

Utiliza la codificación CP-1252 .

Adnan
fuente
1

JavaScript (ES6), 72

(a,b,r=[])=>[...b].map((x,i)=>r[parseInt(x,36)-10]=+a+i-a.search`\\d`)&&r

Prueba

f=(a,b,r=[])=>[...b].map((x,i)=>r[parseInt(x,36)-10]=+a+i-a.search`\\d`)&&r

console.log=x=>O.textContent+=x+'\n'

;[['    2000','--AF-C-------E--D---B--'],
['     10','--C-AB--D'],
['     0','--ABCDEFG--'],
['          5','--ABCDEFG--']]
.forEach(t=>{
  var a=t[0],b=t[1],r=f(a,b)
  console.log(a+'\n'+b+'\n'+r+'\n')
})  
<pre id=O></pre>

edc65
fuente
1

Bash + coreutils, 68

La línea 1 se ingresa como una opción de línea de comando entre comillas y la línea 2 se ingresa desde STDIN:

s="${1//[0-9]}"
fold -1|nl -v$[$1-${#s}]|sort -k2|sed '/-$/d;s/.$//'
Trauma digital
fuente
1

Perl, 58 + 1 = 59 bytes

/\d/;$b=<>;for$c(A..Z){($z=index$b,$c)>-1&&say$_+$z-$-[0]}

Descompostura:

/\d/;                    # Match first digit in input string, this will set $-[0]
$b=<>;                   # Read next line (--A--CB--...) into $b
for $c (A..Z){           # Iterate over A, B, C, ... Z
  ($z=index$b,$c) >-1 && # If the character is found inside $b
  say $_+$z-$-[0]        #   then print
}

Requiere -ny el libre -M5.010:

# Added line breaks for each test case
$ perl -nE'/\d/;$b=<>;for$c(A..Z){($z=index$b,$c)>-1&&say$_+$z-$-[0]}' tl
1998
2016
2001
2012
2009
1999

9
10
7
13

-3
-2
-1
0
1
2
3

-3
-2
-1
0
1
2
3
$ cat tl
    2000
--AF-C-------E--D---B--
     10
--C-AB--D
     0
--ABCDEFG--
          5
--ABCDEFG--
andlrc
fuente
0

Pyth, 22 bytes

V+r\AJeSKwJ+xKN-izT/zd

No, no escribí esto antes de publicar el desafío.

Explicación:

                       - autoassign z = input()
 +r\AJeSKwJ            -  create range of letters
        Kw             -      autoassign K = input()
      eS               -     sorted(K)[-1] (get the biggest character)
     J                 -    autoassign J = ^
  r\A                  -   range("A", ^)
 +        J            -  ^ + J
V                      - for N in ^: V
               -izT/zd - Get the number at the start
                izT    -   int(z, 10)
               -       -  ^-V
                   /zd -   z.count(" ")
           +           - V+^
            xKN        -  K.index(N)

Pruébalo aquí

Azul
fuente
0

Pitón 3, 118

Hombre, hoy es el día de las largas respuestas de Python.

def f(p,l):o=sum(x<'0'for x in p);e={x:i-o+int(p[o:])for i,x in enumerate(l)if'@'<x};return list(map(e.get,sorted(e)))
Morgan Thrapp
fuente
0

En serio, 40 bytes

' ,c,;)l@;±)@-(x@;╗@Z`i3╤τ+@┐`MX╜ú∩S`└`M

Pruébalo en línea!

Explicación para venir más tarde después de más golf.

Mego
fuente
0

Perl, 80 79 71 67 bytes

($a=<>)=~/\d/;$b=<>;say$a+$_-$-[0]for grep{$_+1}map{index$b,$_}A..Z

¡Gracias a @ dev-null por 12 bytes!

($a=<>)=~/\d/;  # read first line of input, find position of first digit
                # (saved in the $- variable)
$b=<>;          # read the second line
                                           A..Z  # generate range 'A','B',...
                            map{index$b,$_}      # find index for each
                  grep{$_+1}                     # select only those != -1
              for                                # foreach of remaining...
say$a+$_-$-[0]                                   # calculate proper date
Pomo de la puerta
fuente