Write your own Death Note

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.


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.


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));}

Tags:

Code Golf