Verfolgen Sie Listen zu Zeitplänen

25

Einführung

Hassen Sie es nicht, wenn jemand ein Album, das Sie mögen, auf YouTube hochlädt, aber die Beschreibung nur eine Titelliste enthält ? So was:

1. Everything in Its Right Place - 4:11
2. Kid A - 4:44
3. The National Anthem - 5:50
4. How to Disappear Completely - 5:55
5. Treefingers - 3:42
6. Optimistic - 5:16
7. In Limbo - 3:31
8. Idioteque - 5:09
9. Morning Bell - 4:29
10. Motion Picture Soundtrack - 6:59

Jetzt wissen Sie nicht, wann die Morgenglocke beginnt, es sei denn, Sie haben ein paar Male im Kopf! Normalerweise werden einige gute Seele kommen durch und lassen Sie eine handliche Zeittabelle in der (gefürchteten) Kommentaren, die etwa wie folgt aussieht:

(0:00:00) Everything in Its Right Place
(0:04:11) Kid A
(0:08:55) The National Anthem
(0:14:45) How to Disappear Completely
(0:20:40) Treefingers
(0:24:22) Optimistic
(0:29:38) In Limbo
(0:33:09) Idioteque
(0:38:18) Morning Bell
(0:42:47) Motion Picture Soundtrack

Spezifikation

  • Ihre Aufgabe ist es, ein Programm oder eine Funktion zu schreiben, die eine Titelliste als Eingabe und eine Zeittabelle als Ausgabe verwendet.

    • Sie können Eingaben aus STDIN, einer Argumentzeichenfolge oder einer Argumentliste von Zeilen lesen. Ebenso können Sie die Ausgabe auf STDOUT drucken oder eine Zeichenfolge oder eine Liste von Zeilen zurückgeben. Wenn Sie dies nicht tun, tun Sie, was für Ihre Sprache sinnvoll ist.
  • Sie können davon ausgehen, dass jede Eingabezeile das Format hat (\d+)\. [A-Za-z0-9 ]{1,100} - (\d+):(\d\d). Für Regex-Betroffene bedeutet dies im Wesentlichen, dass Sie davon ausgehen können, dass jede Zeile gut formatiert ist (wie oben) und dass Songtitel nur aus alphanumerischen ASCII-Zeichen und Leerzeichen bestehen und nicht länger als 100 Byte sind.

  • Die Länge einer Spur beträgt immer mindestens 0:01und höchstens 59:59.
  • Die Titelnummern nehmen in aufsteigender Reihenfolge ab 1und zählen bis maximal 99.
  • Die Gesamtlänge eines Albums beträgt nicht mehr als 9:59:59.

Das ist , also gewinnt der kürzeste Code (in Bytes).

Testfall

Ihr Programm sollte die in der Einführung beschriebene Konvertierung korrekt ausführen (Radiohead's Kid A ). Hier ist ein größerer Testfall (Sufjan Stevens ' Illinois 1 ) mit langen Zeichenketten, an denen Ihr Programm auch arbeiten sollte:

1. Concerning the UFO Sighting Near Highland Illinois - 2:08
2. The Black Hawk War - 2:14
3. Come On Feel the Illinoise - 6:45
4. John Wayne Gacy Jr - 3:19
5. Jacksonville - 5:24
6. A Short Reprise for Mary Todd Who Went Insane but for Very Good Reasons - 0:47
7. Decatur or Round of Applause for Your Stepmother - 3:03
8. One Last Whoo Hoo for the Pullman - 0:06
9. Chicago - 6:04
10. Casimir Pulaski Day - 5:53
11. To the Workers of the Rock River Valley Region - 1:40
12. The Man of Metropolis Steals Our Hearts - 6:17
13. Prairie Fire That Wanders About - 2:11
14. A Conjunction of Drones Simulating the Way - 0:19
15. The Predatory Wasp of the Palisades Is Out to Get Us - 5:23
16. They Are Night Zombies They Are Neighbors They Have Come Back from the Dead Ahhhh - 5:09
17. Lets Hear That String Part Again Because I Dont Think They Heard It All the Way Out in Bushnell - 0:40
18. In This Temple as in the Hearts of Man for Whom He Saved the Earth - 0:35
19. The Seers Tower - 3:53
20. The Tallest Man the Broadest Shoulders - 7:02
21. Riffs and Variations on a Single Note - 0:46
22. Out of Egypt into the Great Laugh of Mankind and I Shake the Dirt from My Sandals as I Run - 4:21

Die korrekte Ausgabe ist:

(0:00:00) Concerning the UFO Sighting Near Highland Illinois
(0:02:08) The Black Hawk War
(0:04:22) Come On Feel the Illinoise
(0:11:07) John Wayne Gacy Jr
(0:14:26) Jacksonville
(0:19:50) A Short Reprise for Mary Todd Who Went Insane but for Very Good Reasons
(0:20:37) Decatur or Round of Applause for Your Stepmother
(0:23:40) One Last Whoo Hoo for the Pullman
(0:23:46) Chicago
(0:29:50) Casimir Pulaski Day
(0:35:43) To the Workers of the Rock River Valley Region
(0:37:23) The Man of Metropolis Steals Our Hearts
(0:43:40) Prairie Fire That Wanders About
(0:45:51) A Conjunction of Drones Simulating the Way
(0:46:10) The Predatory Wasp of the Palisades Is Out to Get Us
(0:51:33) They Are Night Zombies They Are Neighbors They Have Come Back from the Dead Ahhhh
(0:56:42) Lets Hear That String Part Again Because I Dont Think They Heard It All the Way Out in Bushnell
(0:57:22) In This Temple as in the Hearts of Man for Whom He Saved the Earth
(0:57:57) The Seers Tower
(1:01:50) The Tallest Man the Broadest Shoulders
(1:08:52) Riffs and Variations on a Single Note
(1:09:38) Out of Egypt into the Great Laugh of Mankind and I Shake the Dirt from My Sandals as I Run

Bestenliste

Damit Ihre Partitur auf der Tafel erscheint, sollte sie in folgendem Format vorliegen:

# Language, Bytes

1. Entschuldigung an Sufjan, dessen erstaunliche Spurnamen ich ein wenig zerfleischen musste, um sie an das einfache Format anzupassen, auf das sich dieses Problem beschränkt.

Lynn
quelle
Darf die Ausgabe nachgestellte Leerzeichen enthalten?
Martin Ender
1
Radiohead und Sufjan Stevens? Meh :-P
Luis Mendo
Nee; Das Format für jede Zeile ist (h:mm:ss) Track Name, unmittelbar gefolgt von einer neuen Zeile.
Lynn
@LuisMendo Sie können gerne Ihren überlegenen Musikgeschmack in Ihrer Antwort demonstrieren ...?
Lynn
Hahaha. Das ist eine gute zusätzliche Motivation, um zu antworten. Übrigens, ich mochte die Herausforderung und ich habe sie hochgestuft
Luis Mendo

Antworten:

12

CJam, 60 57 55 Bytes

Danke an Sp3000 für das Speichern von 2 Bytes.

qN/{T60bZ0e["(%d:%02d:%02d) "e%\S/1>)':/60bT+:T;W<S*N}/

Teste es hier.

Erläuterung

qN/{      e# Read input and split into lines.
  T60b    e# Push T (initially zero, we use this to keep track of the total time in
          e# seconds), and convert it to base 60.
  Z0e[    e# Pad it with zeroes to 3 digits to get hours, minutes, seconds.
  "(%d:%02d:%02d) "e%
          e# Get the (h:mm:ss) part using a format string.
  \S/     e# Pull up the current line, split on spaces.
  1>      e# Discard the first segment, i.e. the track number.
  )':/    e# Pull off the last segment, i.e. the time, and split on colons.
  60b     e# Interpret the two parts as base-60 digits to get the amount of seconds
          e# for the track.
  T+:T;   e# Add this to T and discard it.
  W<      e# Discard the last segment of the remaining string (the hyphen).
  S*N     e# Join the song name back together with spaces and push a line feed.
}/
Martin Ender
quelle
16
goddammit Martin
cjfaure
6

Perl, (93 Zeichen plus -p) 94 Bytes

s!\d+\. (.+) - (\d+:(\d+))!sprintf"(%d:%02d:%02d) $1",$n/3600,$n%3600/60,$n%60,$n+=$3+60*$2!e

Zu rennen:

perl -pe 's!\d+\. (.+) - (\d+:(\d+))!sprintf"(%d:%02d:%02d) $1",$n/3600,$n%3600/60,$n%60,$n+=$3+60*$2!e' <<< '<input>'
Dom Hastings
quelle
5

C ++, 212 209 202 189 Bytes

C ++ weil .. warum nicht?

#include<iostream>
long d,t,u;main(){std::string a,b(8,0);while(getline(std::cin>>t>>a[0],a,'-')>>t>>b[0]>>u){strftime(&b[0],9,"%T",gmtime(&d));b[0]='(';std::cout<<b+")"+a+'\n';d+=t*60+u;}}

Leben: 212 209 202 189

Wendelbsilva
quelle
5

Python 2, 170 160 Bytes

Es ist schon eine Weile her, dass ich Golf gespielt habe, hoffentlich ist das nicht schlecht: P

t=0
for i in input().split('\n'):i=i.split(' - ');print'(%d:%02d:%02d)'%(t/3600,t%3600/60,t%60),i[0].split('. ')[1];k=i[-1].split(':');t+=int(k[0])*60+int(k[1])

Die Eingabe sollte von Anführungszeichen umgeben und durch Zeilenumbrüche wie folgt aufgeteilt werden:

"1. Concerning the UFO Sighting Near Highland Illinois - 2:08\n2. The Black Hawk War - 2:14\n3. Come On Feel the Illinoise - 6:45\n4. John Wayne Gacy Jr - 3:19\n5. Jacksonville - 5:24\n6. A Short Reprise for Mary Todd Who Went Insane but for Very Good Reasons - 0:47\n7. Decatur or Round of Applause for Your Stepmother - 3:03\n8. One Last Whoo Hoo for the Pullman - 0:06\n9. Chicago - 6:04\n10. Casimir Pulaski Day - 5:53\n11. To the Workers of the Rock River Valley Region - 1:40\n12. The Man of Metropolis Steals Our Hearts - 6:17\n13. Prairie Fire That Wanders About - 2:11\n14. A Conjunction of Drones Simulating the Way - 0:19\n15. The Predatory Wasp of the Palisades Is Out to Get Us - 5:23\n16. They Are Night Zombies They Are Neighbors They Have Come Back from the Dead Ahhhh - 5:09\n17. Lets Hear That String Part Again Because I Dont Think They Heard It All the Way Out in Bushnell - 0:40\n18. In This Temple as in the Hearts of Man for Whom He Saved the Earth - 0:35\n19. The Seers Tower - 3:53\n20. The Tallest Man the Broadest Shoulders - 7:02\n21. Riffs and Variations on a Single Note  - 0:46\n22. Out of Egypt into the Great Laugh of Mankind and I Shake the Dirt from My Sandals as I Run - 4:21"
Kade
quelle
4
Ich denke man kann nur %dfür den Stundenzähler (wenn ich die Regeln richtig verstehe!) -2!
Dom Hastings
Fügen Sie 4 Zeichen ( inputbis raw_input) hinzu, um das genaue Format zu akzeptieren. ansonsten halte ich es für ungültig, da es Zeilen in einem anderen Format annimmt.
RK.
3

Gema, 151 Zeichen

\B=@set{t;}
<D>. * - <D>\:<D>=(@div{$t;3600}:@fill-right{00;@div{@mod{$t;3600};60}}:@fill-right{00;@mod{$t;60}}) *@set{t;@add{@add{$t;$4};@mul{$3;60}}}

Probelauf:

bash-4.3$ gema '\B=@set{t;};<D>. * - <D>\:<D>=(@div{$t;3600}:@fill-right{00;@div{@mod{$t;3600};60}}:@fill-right{00;@mod{$t;60}}) *@set{t;@add{@add{$t;$4};@mul{$3;60}}}' tracklist.txt
(0:00:00) Concerning the UFO Sighting Near Highland Illinois
(0:02:08) The Black Hawk War
(0:04:22) Come On Feel the Illinoise
(0:11:07) John Wayne Gacy Jr
(0:14:26) Jacksonville
(0:19:50) A Short Reprise for Mary Todd Who Went Insane but for Very Good Reasons
(0:20:37) Decatur or Round of Applause for Your Stepmother
(0:23:40) One Last Whoo Hoo for the Pullman
(0:23:46) Chicago
(0:29:50) Casimir Pulaski Day
Mann bei der Arbeit
quelle
3

Python 2, 207 206 Bytes

h=m=s=0
for i in raw_input().splitlines():
 print("(%d:%.2d:%.2d) "%(h,m,s),i.split('-')[0].split('. ')[1])
 t=i.split('-')[1].split(':')
 m+=int(t[0]);s+=int(t[1]);r=s//60;s-=r*60;m+=r;r=m//60;m-=r*60;h+=r

Verwendung

$ python test.py
'1. Concerning the UFO Sighting Near Highland Illinois - 2:08\n2. The Black Hawk War - 2:14\n3. Come On Feel the Illinoise - 6:45'
(0:00:00) Concerning the UFO Sighting Near Highland Illinois 
(0:02:08) The Black Hawk War 
(0:04:22) Come On Feel the Illinoise 
Zach Gates
quelle
Welche Version von Python 3 verwenden Sie? Ich dachte, raw_inputnur in Python 2 existiert.
Lynn
Fest. Ich glaube, ich bin nur daran gewöhnt, "3" einzugeben. @ Mauris
Zach Gates
1

awk, 119 101 bytes

{split($NF,t,":");$1=$(--NF)="";--NF;print"("substr(strftime("%H:%M:%S",s,1),2)")"$0;s+=t[1]*60+t[2]}

Das ist viel länger als ich es wollte. Das Problem ist, dass %Hdie Stunden nicht wie gewünscht formatiert werden. Ich musste die Stunden selbst berechnen.

Ack, ich bin dumm. Die Ergebnisse von strftimewaren falsch, weil ich es anweisen musste, UTC-Zeit zu verwenden. Das hat 18 Bytes gekürzt!

119-Byte-Version

{split($NF,t,":");$1=$(--NF)="";--NF;print"("(h||0)":"strftime("%M:%S",s)")"$0;s=(r=s+t[1]*60+t[2])%3600;h=int(r/3600)}
kirbyfan64sos
quelle