14
\$\begingroup\$

Kira needs your help!


Input format:

Date [and/or Time]
Name
Gender
Reason

Output format:

<Last Name, First Name> <will die/died> on the <DD><st/nd/rd/th> of <MMM, YYYY> [at <hh:mm:ss TT>].
<He/She> <will die/died> of <Reason>.


Details, Details:


Your program should account for at least the following date input formats:

9 November 2003
9/11/2003
November 9, 2003

Time formats:

hh tt
hh TT
hh:mm tt
hh:mm TT
hh:mm:ss tt
hh:mm:ss TT
HH
HH:mm
HH:mm:ss

The following name input formats:

first        // Stephen
last         // Harper
first last   // Stephen Harper
last, first  // Harper, Stephen


Test cases:


Input:

2 September 1973
J.R.R. Tolkien
Male
pneumonia

Output:

Tolkien, J.R.R. died on the 2nd of September, 1973.

He died of pneumonia.


DISCLAIMER: If he actually dies on this date, it's Kira's fault, not mine.

UPDATE: Stephen Harper did not die on the listed date

Input:

21/12/12 23:59:59             // DD/MM/YY HH:mm:ss
Harper, Stephen               // Last, First
Unknown                       // Gender
a heart attack for no reason  // Reason

Output:

Harper, Stephen will die on the 21st of December, 2012 at 11:59:59 PM.

Harper, Stephen will die of a heart attack for no reason.



Bonus:

July 21, 1969 02:56:15 GMT
Armstrong, Neil
Male
poisoned moon cheese

--

January 19, 2038 03:14:08 GMT
Everyone
Unknown
Y2K38

Add <st/nd/rd/th> at the end of DD for input.

\$\endgroup\$
  • \$\begingroup\$ Ahaha I just finished reading this series :D Shouldn't it be "heart attack" for "no reason" then? \$\endgroup\$ – Ry- May 3 '11 at 1:45
  • \$\begingroup\$ Um, September 2nd is 2/9/11, not 2/7/11 ;) \$\endgroup\$ – Ry- May 3 '11 at 1:48
  • \$\begingroup\$ Does the gender not have any effect on the output? \$\endgroup\$ – Peter Olson May 3 '11 at 2:14
  • \$\begingroup\$ Also, do we have to accept dates before 1970? \$\endgroup\$ – Peter Olson May 3 '11 at 2:18
  • 5
    \$\begingroup\$ How do we disambiguate between input with DD/MM/YYYY and MM/DD/YYYY? \$\endgroup\$ – Peter Olson May 3 '11 at 6:42
6
\$\begingroup\$

Javascript (561)

This can probably be reduced significantly, but here goes:

i=i.split("\n");d=new Date(i[0]);t=d.getDate();z=t%10;t+=z==1?"st":z==2?"nd":z==3?"rd":"th";m=['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()];y=d.getFullYear();a=d.getHours();b=d.getMinutes();c=d.getSeconds();l=a&&b&&c?" at "+a+":"+b+":"+c:"";g=d>new Date()?"will die":"died";n=i[1].split(" ");n[1]?n[0][n[0].length-1]==","?n=i[1]:n=n[1]+", "+n[0]:n[0];s=i[2]=="Male"?"He":i[2]=="Female"?"She":n;document.write(n+" "+g+" on the "+t+" of "+m+", "+y+l+".<br>"+s+" "+g+" of "+i[3]+".");

Sample I/O:

2 September 1973
J.R.R. Tolkien
Male
pneumonia

Tolkien, J.R.R. died on the 2nd of September, 1973. He died of pneumonia.

January 19, 2038 03:14:08 GMT
Everyone
Unknown
Y2K38

Everyone will die on the 18th of January, 2038 at 21:14:8. Everyone will die of Y2K38.

Try it out on JsFiddle.

\$\endgroup\$
  • \$\begingroup\$ Just want to point out that i="9 November 2003 03:14:08 GMT\nDouglas Adams\nMale\nI forgot"; gives me the 8th of November. \$\endgroup\$ – Mateen Ulhaq May 3 '11 at 6:59
  • 4
    \$\begingroup\$ @muntoo That's because it adjusts to your timezone. If you live in the GMT timezone, it should give you 9th. \$\endgroup\$ – Peter Olson May 3 '11 at 12:43
  • \$\begingroup\$ I'm going to blame you if I die on my birthday. :P \$\endgroup\$ – nyuszika7h Jul 3 '14 at 11:48
5
\$\begingroup\$

VB.NET, 727 695

Okay, golfed a bit. Requires Option Strict Off.

Module M
Sub Main
Dim d=Date.Parse(Console.ReadLine),n=Console.ReadLine,o=Date.Now,g=Console.ReadLine,r=Console.ReadLine,i=n.IndexOf(" "),f=d.Day Mod 10+(d.Day\10=1)*5,a=Array.IndexOf("male|female|he|she|him|her|guy|girl|boy|lady|man|woman".Split("|"), g.ToLower),b="|st|nd|rd".Split("|"),m="|January|February|March|April|May|June|July|August|September|October|November|December".Split("|")
If n.IndexOf(",")<0 Then n=n.Substring(i+1)&", "&n.Substring(0,i)
g=If(a<0,n,If(a Mod 2,"She","He"))
Console.Write("{0} {11} on the {1}{2} of {3}, {4} at {5}:{6:00}:{7:00}.{8}{9} {11} of {10}.",n,d.Day,If(f<4,b(f),"th"),m(d.Month),d.Year,d.Hour,d.Minute,d.Second,vbCrLf,g,r,If(o<d,"will die","died"))
End Sub
End Module

It accepts the dates in all the test cases, and many other formats thanks to Date.Parse. It accepts many genders (as you can see) as well. If Kira decides to put only the person's first or last name, the program will crash.

\$\endgroup\$
  • \$\begingroup\$ looks like you may be able to drop quite a few bytes by replacing your split argument with a MonthName(d.Month) call \$\endgroup\$ – Taylor Scott Jun 2 '17 at 15:24
2
\$\begingroup\$

CSharp - 463 chars

void Main(){Func<String>c=()=>Console.ReadLine();var d=DateTime.Parse(c());var n=c();if(!n.Contains(",")&&n.Contains(" "))n=n.Split(' ')[1]+", "+n.Split(' ')[0];n+=" ";var g=c().ToLower();g=g.Contains("male")?g.Replace("female","She").Replace("male","He"):"They";var r=c();var f=(DateTime.Now<d);Console.Write(String.Format(n+"{0} on the {1} {2}\n{3} {0} of {4}",(f?"will die":"died"),d.ToString("dddd 'of' MMMM, yyyy"),d.Date==d?"":d.ToString("hh:mm:ss"),g,r));}
\$\endgroup\$
1
\$\begingroup\$

PHP, 509 474 462 461 characters

<?for($l=0;$l<4;)$i[$l++]=chop(fgets(STDIN));
putenv('TZ=GMT');
$t=strtotime(preg_match("/(\d+)\/(\d+)\/(\d+)(.*)/",$i[0],$q)?"$q[1]-$q[2]-".($q[3]<100?19+1*($q[3]<70):"").$q[3].$q[4]:$i[0]);
$z=$t<time()?" died":" will die";
$f="jS \of F, Y".($t%86400?" \a\\t g:i:s A":"");
$n=strpos($i[1],',')?$i[1]:explode(" ",$i[1]);
if(is_array($n))$n=$n[1]!=""?$n[1].", ".$n[0]:$n[0];?>
<?=$n."$z on the ".date($f,$t)."\n\n".($i[2][0]==M?He:($i[2][0]==F?She:$n))."$z of ".$i[3];

I've added newlines after each ; but not counted them as they don't need to be there.
Whether the code handles dates beyond January 19, 2038 03:14:07, depends on whether it's run on a 64bit machine.

\$\endgroup\$
1
\$\begingroup\$

VBA, 384 366 Bytes

Golfed

Full subroutine that takes input of expected type Variant\String and outputs the associated deathnote message to the VBE immediates window

Note: VBA is incapable of handling Timezones without declaring Windows API functions, so as these are not necessary for the question, they have been excluded

Sub x(d,n,g,r)
e=CDate(d)
f=Day(e) Mod 10
w=IIf(e>Now," will die"," died")
i=InStr(1,n," ")
n=IIf(InStr(1,n,","),n,Mid(n,i+1)&", "&Mid(n,1,i-1))
g=LCase(g)
Debug.?n;w" on the "Day(e)Split("th|st|nd|rd","|")(IIf(f>3,0,f))" of "MonthName(Month(e))", "Year(e)IIf(InStr(1,d,":")," at "&TimeValue(d),"")"."vbCr;IIf(g="male","He",IIf(g="female","She",n))w" of "r".
End Sub

Bonus Verison, 394 376 Bytes

Slightly modified version of the above that handles all of the bonus cases with the exception of timezones (Correction for handling mononyms)

Sub x(d,n,g,r)
e=CDate(d)
f=Day(e) Mod 10
i=InStr(1,n," ")
w=Space(0 ^i)&IIf(e>Now,"will die","died")
n=IIf(InStr(1,n,",")^i,n,Mid(n,i+1)&", "&Mid(n,1,i))
g=LCase(g)
Debug.?n;w" on the "Day(e)Split("th|st|nd|rd","|")(IIf(f>3,0,f))" of "MonthName(Month(e))", "Year(e)IIf(InStr(1,d,":")," at "&TimeValue(d),"")"."vbCr;IIf(g="male","He",IIf(g="female","She",n))w" of "r".
End Sub

Usage

input and output sequence of the example problems as seen from the VBE immediate window

?Now
01-Jun-17 1:59:35 PM

x "2 September 1973", "J.R.R. Tolkien", "Male", "pneumonia"
Tolkien, J.R.R. died on the 2nd of September, 1973.
He died of pneumonia.

x "21/12/12 23:59:59", "Harper, Stephen", "Unknown", "a heart attack for no reason"
Harper, Stephen died on the 21st of December, 2012 at 11:59:59 PM.
Harper, Stephen died of a heart attack for no reason.

x "July 21, 1969 02:56:15", "Armstrong, Neil", "Male", "poisoned moon cheese"
Armstrong, Neil died on the 21st of July, 1969 at 2:56:15 AM.
He died of poisoned moon cheese.

## Using Bonus Version

x "January 19, 2038 03:14:08","Everyone","Unknown","Y2K38"
Everyone will die on the 19th of January, 2038 at 3:14:08 AM.
Everyone will die of Y2K38.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.