Task: Discordian date


C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iterator>
using namespace std;
class myTuple
{
public:
    void set( int a, int b, string c ) { t.first.first = a; t.first.second = b; t.second = c; }
    bool operator == ( pair<int, int> p ) { return p.first == t.first.first && p.second == t.first.second; }
    string second() { return t.second; }
private:
    pair<pair<int, int>, string> t;
};
class discordian
{
public:
    discordian() {
        myTuple t;
        t.set( 5, 1, "Mungday" ); holyday.push_back( t ); t.set( 19, 2, "Chaoflux" ); holyday.push_back( t );
        t.set( 29, 2, "St. Tib's Day" ); holyday.push_back( t ); t.set( 19, 3, "Mojoday" ); holyday.push_back( t );
        t.set( 3, 5, "Discoflux" ); holyday.push_back( t ); t.set( 31, 5, "Syaday" ); holyday.push_back( t );
        t.set( 15, 7, "Confuflux" ); holyday.push_back( t ); t.set( 12, 8, "Zaraday" ); holyday.push_back( t ); 
        t.set( 26, 9, "Bureflux" ); holyday.push_back( t ); t.set( 24, 10, "Maladay" ); holyday.push_back( t ); 
        t.set( 8, 12, "Afflux" ); holyday.push_back( t ); 
        seasons.push_back( "Chaos" ); seasons.push_back( "Discord" ); seasons.push_back( "Confusion" ); 
        seasons.push_back( "Bureaucracy" ); seasons.push_back( "The Aftermath" );
        wdays.push_back( "Setting Orange" ); wdays.push_back( "Sweetmorn" ); wdays.push_back( "Boomtime" );
        wdays.push_back( "Pungenday" ); wdays.push_back( "Prickle-Prickle" ); 
    }
    void convert( int d, int m, int y ) {
        if( d == 0 || m == 0 || m > 12 || d > getMaxDay( m, y ) ) { 
            cout << "\nThis is not a date!"; 
            return; 
        }
        vector<myTuple>::iterator f = find( holyday.begin(), holyday.end(), make_pair( d, m ) ); 
        int dd = d, day, wday, sea,  yr = y + 1166;
        for( int x = 1; x < m; x++ )
            dd += getMaxDay( x, 1 );
        day = dd % 73; if( !day ) day = 73; 
        wday = dd % 5; 
        sea  = ( dd - 1 ) / 73;
        if( d == 29 && m == 2 && isLeap( y ) ) { 
            cout << ( *f ).second() << " " << seasons[sea] << ", Year of Our Lady of Discord " << yr; 
            return; 
        }
        cout << wdays[wday] << " " << seasons[sea] << " " << day;
        if( day > 10 && day < 14 ) cout << "th"; 
        else switch( day % 10) { 
            case 1: cout << "st"; break; 
            case 2: cout << "nd"; break; 
            case 3: cout << "rd"; break; 
            default: cout << "th"; 
        }
        cout << ", Year of Our Lady of Discord " << yr;
        if( f != holyday.end() ) cout << " - " << ( *f ).second();
    }
private:
    int getMaxDay( int m, int y ) { 
        int dd[] = { 0, 31, isLeap( y ) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; return dd[m]; 
    }
    bool isLeap( int y ) { 
        bool l = false; 
        if( !( y % 4 ) ) { 
            if( y % 100 ) l = true; 
            else if( !( y % 400 ) ) l = true; 
        }
        return l; 
    }
    vector<myTuple> holyday; vector<string> seasons, wdays;
};
int main( int argc, char* argv[] ) {
    string date; discordian disc;
    while( true ) {
        cout << "Enter a date (dd mm yyyy) or 0 to quit: "; getline( cin, date ); if( date == "0" ) break;
        if( date.length() == 10 ) {
            istringstream iss( date ); 
            vector<string> vc;
            copy( istream_iterator<string>( iss ), istream_iterator<string>(), back_inserter<vector<string> >( vc ) );
            disc.convert( atoi( vc[0].c_str() ), atoi( vc[1].c_str() ), atoi( vc[2].c_str() ) ); 
            cout << "\n\n\n";
        } else cout << "\nIs this a date?!\n\n";
    }
    return 0;
}









Fortran: program discordianDate
    implicit none
    
    character(32) :: arg
    character(15) :: season,day,holyday
    character(80) :: Output,fmt1,fmt2,fmt3
    character(2) :: dayfix,f1,f2,f3,f4
    integer :: i,j,k,daysofyear,dayofweek,seasonnum,yold,dayofseason,t1,t2,t3
    integer,dimension(8) :: values
    integer, dimension(12) :: daysinmonth
    logical  :: isleapyear, isholyday, Pleapyear
     
    
    call date_and_time(VALUES=values)
    
    daysinmonth = (/ 31,28,31,30,31,30,31,31,30,31,30,31 /)
    isleapyear = .false.
    isholyday = .false.
    
    
    j = iargc()
    do i = 1, iargc()
      call getarg(i, arg)  
      if (j==3) then
        if (i==1) then
          read(arg,'(i2)') values(3)  
        endif
        if (i==2) then
          read(arg,'(i2)') values(2)  
        endif
        if (i==3) then
          read(arg,'(i4)') values(1)  
 
        endif
      endif
      if (j==2) then  
        if (i==1) then
          read(arg,'(i2)') values(3)  
        endif
        if (i==2) then
          read(arg,'(i2)') values(2)  
        endif
      endif
      if (j==1) then 
        read(arg,'(i2)') values(3)  
      endif
    end do
 
    

    yold = values(1) + 1166
    daysofyear = 0
    if (values(2)>1) then 
    do i=1 , values(2)-1 , 1
        daysofyear = daysofyear + daysinmonth(i)
     end do
   end if
    daysofyear = daysofyear + values(3)
    isholyday = .false.
    isleapyear = Pleapyear(yold)
    dayofweek = mod (daysofyear, 5)
    seasonnum = ((daysofyear - 1) / 73) + 1 
    dayofseason = daysofyear - ((seasonnum - 1)  * 73)
    k = mod(dayofseason,10)  
    select case (k)
      case (1)
         dayfix='st'
      case (2)
         dayfix='nd'
      case (3)
         dayfix='rd'
      case default
         dayfix='th'
    end select
    
    if (((dayofseason > 10) .and. (dayofseason < 20)) .eqv. .true.) then
      dayfix = 'th'
    end if
    select case (Seasonnum)
      case (1) 
        season ='Choas'
        f4 = '5'
      case (2) 
        season ='Discord'
        f4 = '7'
      case (3) 
        season ='Confusion'
        f4 = '9'
      case (4) 
        season ='Bureaucracy'
        f4 = '10'
      case (5) 
        season ='The Aftermath'
        f4 = '13'
    end select
    select case (dayofweek)
       case (0) 
         day='Setting Orange'
         f2 = '14'
       case (1) 
         day ='Sweetmorn'
         f2 = '9'
       case (2) 
         day = 'Boomtime'
         f2 = '8'
       case (3) 
         day = 'Pungenday'
         f2 = '9'
       case (4) 
         day = 'Prickle-Prickle'
         f2 = '15'
    end select
    
    select case (dayofseason)
      case (5)
        isholyday = .true.
        select case (seasonnum)
          case (1)
             holyday ='Mungday'
             f1 = '7'
          case (2)
             holyday = 'Mojoday'
             f1 = '7'
          case (3)
            holyday = 'Syaday'
            f1 = '6'
          case (4)
             holyday = 'Zaraday'
             f1 = '7'
          case (5)
            holyday = 'Maladay'
            f1 = '7'
         end select
      Case (50)
        isholyday = .true.
        select case (seasonnum)
          case (1)
            holyday = 'Chaoflux'
            f1 = '8'
          case (2)
            holyday = 'Discoflux'
            f1 = '9'
          case (3)
            holyday = 'Confuflux'
            f1 = '9'
          case (4)
            holyday = 'Bureflux'
            f1 = '8'
          case (5)
            holyday = 'Afflux'
            f1 = '6'
         end select
    end select
    

    
    if (isleapyear .eqv. .true.) then 
      if ((values(2) == 2) .and. (values(3) == 29)) then
         isholyday = .true.
      end if
    end if
    
    f3 = "2"
    if (dayofseason < 10) then
      f3 = "1"
    end if
    fmt1 = "(a,i4)"
    fmt2 = "(A,a" // f1 // ",A,A" // f2 // ",A,I" // f3 // ",A2,A,A" // f4 // ",A,I4)"
    fmt3 = "(A,A" // f2 // ",A,I" // f3 //",A2,A,A" // f4 // ",A,I4)"
    
    if (isholyday .eqv. .true.) then
      if (values(3) == 29) then
         print fmt1,'Celebrate for today is St. Tibbs Day in the YOLD ',yold
       else
         print fmt2, 'Today is ',holyday, ' on ',day,' the ',dayofseason,dayfix,' day of ',season,' in the YOLD ',yold 
       end if
     else   
         print fmt3, 'Today is ',day,' the ',dayofseason,dayfix, ' day of ',season,' in the YOLD ',yold
     end if
    end program discordianDate

    

    function Pleapyear(dloy) result(leaper)
    implicit none
    integer, intent(in) :: dloy
    logical :: leaper
    leaper = .false.
    if (mod((dloy-1166),4) == 0)  then
      leaper = .true.
    end if
    if (mod((dloy-1166),100) == 0) then
        leaper = .false.
        if (mod((dloy-1166),400)==0) then
           leaper = .true.
        end if
    end if 
    end function Pleapyear