Skip to main content
5 of 6
Put correct submarine code in
VisualMelon
  • 3.9k
  • 18
  • 39

C# 1124 1128bytes

Once a week, a shoddy ASCII submarine should appear for an hour below the waterline, and increase my byte count noticeably hopefully this code will actually work now. I dread to think what happens on Saturdays at 11:00 in December...

using System;class P{static string G(DateTime t){Func<int,int>K=new Random().Next;int i,j,D=t.Day,H=t.Hour,W=19-H%12,E=(int)t.DayOfWeek;var M=new char[60,19];Func<int,int,int,string,bool>T=(x,y,w,s)=>{for(i=0;i<s.Length;)if(M[(x+i%w)%60,y+i++/w]>0)return 0>1;for(;i-->0;)M[(x+i%w)%60,y+i/w]=s[i];return 1>0;};T(t.Minute,W-5,9,@"    _       /|\     / | \   /__|__\ ____|____\_______/");while(M[j=K(59-D),W]+M[j+D+1,W]>0){}M[j+D+1,W]=M[j,W]='-';for(j=60;j-->0;)T(j,W,1,"~");for(;++j<E;)while(!T(K(53),K(W-3),8,"   ___   _(   ) (___)__)")){}var N=H<6|H>=18;for(j=0;j++<t.Month*(N?3:1);)while(!T(K(60-(N?1:3)),K(W-1),3,N?"*":"-.-")){}if(H==18&E==4)T(K(59),W+2,17,@"    __            __/  \_________ (_______________)");var res=" ________________________________________________________________\n|\\ ____________________________________________________________ /|\n| |";for(j=0;j<19;j++){for(i=0;i<60;i++)res+=M[i,j];res+="| |\n| |";}return res+"____________________________________________________________| |\n|/______________________________________________________________\\|";}static void Main(){Console.Write(G(DateTime.Now));}}

Somewhat formatted code (which re-draws every 15seconds because I mis-read the spec):

using System;

class P
{
    static string G(DateTime t)
    {
        Func<int,int>K=new Random().Next;
        int i,j,D=t.Day,H=t.Hour,W=19-H%12,E=(int)t.DayOfWeek;
        var M=new char[60,19];
        
        Func<int,int,int,string,bool>T=(x,y,w,s)=>
        {
            for(i=0;i<s.Length;)
                if(M[(x+i%w)%60,y+i++/w]>0)
                    return 0>1;
            for(;i-->0;)
                M[(x+i%w)%60,y+i/w]=s[i];
            return 1>0;
        };

        T(t.Minute,W-5,9,@"    _       /|\     / | \   /__|__\ ____|____\_______/");

        while(M[j=K(59-D),W]+M[j+D+1,W]>0){}
        M[j+D+1,W]=M[j,W]='-';
        
        for(j=60;j-->0;)
            T(j,W,1,"~");
        
        for(;++j<E;)
            while(!T(K(53),K(W-3),8,"   ___   _(   ) (___)__)")){}
        
        var N=H<6|H>=18;
        for(j=0;j++<t.Month*(N?3:1);)
            while(!T(K(60-(N?1:3)),K(W-1),3,N?"*":"-.-")){}
        
        if(H==18&E==4)
            T(K(59),W+2,17,@"    __            __/  \_________ (_______________)");
        
        var res=@" ________________________________________________________________
|\ ____________________________________________________________ /|
| |";

        for(j=0;j<19;j++)
        {
            for(i=0;i<60;i++)
                res+=M[i,j];
            res+="| |\n| |";
        }
            
        return res+@"____________________________________________________________| |
|/______________________________________________________________\|";
    }
    
    static void Main()
    {
        for(;;)
        {
            Console.Clear();
            //Console.Write(G(DateTime.Now));
            Console.Write(G(DateTime.Now.Add(new TimeSpan(28, 0, 0))));
            System.Threading.Thread.Sleep(15000);
        }
    }
}

Example output (should read 3:31, Wednesday, 13th August):

 ________________________________________________________________
|\ ____________________________________________________________ /|
| |                                                            | |
| |         *  *                                               | |
| |                         *                                  | |
| |      *                 *                                   | |
| |                     *                                      | |
| |            ___                        * *                  | |
| |          _(   )                                            | |
| |        *(___)__)      *                   *                | |
| |                                  *                         | |
| |           ___    *                                      *  | |
| |     *   _(   )  *                             ___    *     | |
| |      * (___)__)                   _         _(   )         | |
| |        *             *           /|\       (___)__)  *  *  | |
| |                                 / | \     *           *    | |
| |                                /__|__\                     | |
| |                               ____|____                    | |
| |~~-~~~~~~~~~~~~~-~~~~~~~~~~~~~~\_______/~~~~~~~~~~~~~~~~~~~~| |
| |                                                            | |
| |                                                            | |
| |____________________________________________________________| |
|/______________________________________________________________\|
VisualMelon
  • 3.9k
  • 18
  • 39