Buch Cover Buch Cover Buch Cover Buch Cover

Web-Code: - Webcode Help

Diskordianischer Kalender (Kleinprojekte)

Schreiben Sie eine Routine, die ein gregorianisches Datum annimt und sie als

Datum im diskordianischen Kalender zurückgibt.

4 Kommentare

Bitte melde dich an um einen Kommentar abzugeben

Kommentare (4)

gressly 28. April 2023 10:31   reply report
JKooP
@virgil: Danke für die schöne Aufgabe und ja - die Seite hätte Potential. Nach Rücksprache mit IDM-Studios bzw. Herrn P.G.F. habe ich erfahren, dass das Projekt aufgrund fehlender Mittel eingestellt wurde und die Seite nicht weiter gepflegt wird. Die Seite bleibt weiterhin online, unterliegt aber keiner Überarbeitung mehr.

Stimmt, das Projekt ist abgeschlossen. Einzig die Seite bleibt so lange bestehen, wie dies meine finanziellen Mittel ermöglichen.
φ
gressly 28. April 2023 10:30   reply report
Habe versucht, den Link etwas zu verschönern...
Spannender Kalender.
JKooP 4. März 2023 19:15   reply report
@virgil: Danke für die schöne Aufgabe und ja - die Seite hätte Potential. Nach Rücksprache mit IDM-Studios bzw. Herrn P.G.F. habe ich erfahren, dass das Projekt aufgrund fehlender Mittel eingestellt wurde und die Seite nicht weiter gepflegt wird. Die Seite bleibt weiterhin online, unterliegt aber keiner Überarbeitung mehr.
virgil 3. März 2023 22:16   reply report
Diese Seite hat echt Potential, ist aber unfassbar dumm auf- und umgesetzt.
Der Link ist: https://de.wikipedia.org/wiki/Diskordianischer_Kalender

4 Lösung(en)

// NET 7.x | C# 11.x | VS-2022

var WEEK_DAYS = new List<(string lType, string sType)> {
    ("Sweetmorn", "SM"), ("Boomtime", "BT"), ("Pungenday", "PD"),
    ("Prickle-Prickle", "PP"), ("Setting Orange", "SO") };

var SEASONS = new List<(string lType, string sType)> {
    ("Chaos", "I"), ("Discord", "II"), ("Confusion", "III"),
    ("Bureaucracy", "IV"), ("Aftermath", "V") };

var HOLIDAYS = new List<(string dateDis, string Name)> {
    ("5.Chaos", "Mungtday"), ("50.Chaos", "Chaoflux"),
    ("5.Discord", "Mojoday"), ("50.Discord", "Discoflux"),
    ("5.Confusion", "Syaday"), ("50.Confusion", "Confuflux"),
    ("5.Bureaucracy", "Zaraday"), ("50.Bureaucracy", "Bureflux"),
    ("5.Aftermath", "Maladay"), ("50.Aftermath", "Afflux")
};

DiscordianDate GetDiscordianDate(DateTime date_, bool shortType_ = false) {
    // gregorian day of the year
    var dayGreg = date_.DayOfYear;

    // discordian day
    var dayTmp = dayGreg % 73;
    var day = dayTmp == 0 ? 73 : dayTmp;

    // discordian season
    int season;
    var seasonTmp = dayGreg / 73;
    if (seasonTmp == 5) season = 4;
    else if (seasonTmp == 0 && seasonTmp > 0) season = seasonTmp - 1;
    else season = seasonTmp;
    var seasonType = shortType_ ? SEASONS[season].sType: SEASONS[season].lType;

    // discordian weekday
    var weekdayTmp = dayGreg % 5;
    var weekday = weekdayTmp == 0 ? 4 : weekdayTmp - 1;
    var weekdayType = shortType_ ? WEEK_DAYS[weekday].sType : WEEK_DAYS[weekday].lType;

    return new DiscordianDate(day, seasonType, weekdayType, date_.Year + 1166);
}

string GetHoliday(DateTime date_) {
    var (day, season, weekday, _) = GetDiscordianDate(date_);
    var find = $"{day}.{season}";
    var found = HOLIDAYS.Any(x => x.dateDis == find);
    var dateGreg = $"gregorian: {date_.ToShortDateString()}\n";
    var holidayType = (day == 5 ? "apostle" : "season") + " holiday";
    return dateGreg + (found ? $"{weekday}, {day}. {season} -> " +
        $"{HOLIDAYS.Where(x => x.dateDis == find).FirstOrDefault().Name} ({holidayType})" : "no holiday");
}
void print(DiscordianDate date_, DateTime date_greg_) {
    var (day, season, weekday, year) = date_;
    Console.WriteLine($"gregorian: {date_greg_.ToShortDateString()}" +
        $"\ndiscordian: {weekday}, {day}.{season} {year} YOLD\n");
}

// long format
var dateStd = new DateTime(2023, 2, 19);
print(GetDiscordianDate(dateStd, false), dateStd);

// short format and leap year
var dateLY = new DateTime(2024, 2, 29);
print(GetDiscordianDate(dateLY, true), dateLY);

// get holiday
var dateH = GetHoliday(dateStd);
Console.WriteLine(dateH);

record struct DiscordianDate(int Day, string Season, string Weekday, int Year);
                

Lösung von: Jens Kelm (@JKooP)

// C++ 20 | VS-2022
#include <iostream>
#include <vector>
#include <format>
#include <algorithm>
#include <sstream>

constexpr size_t DAYS_SEASON{ 73 };
constexpr size_t DAYS_WEEK{ 5 };
constexpr size_t YEAR_DIFF{ 1166 };

struct discordian_date {
    const size_t day, year;
    const std::string season, weekday;
};

struct gregorian_date {
    const size_t day, month, year;
};

struct constants_type {
    const std::string long_type, short_type;
};

struct holiday_type {
    const std::string date, name;
};

const std::vector<constants_type> WEEKDAYS {
    {"Sweetmorn", "SM"}, {"Boomtime", "BT"},
    {"Pungenday", "PD"}, {"Prickle-Prickle", "PP"},
    {"Setting Orange", "SO"}
};

const std::vector<constants_type> SEASONS {
    {"Chaos", "I"}, {"Discord", "II"},
    {"Confusion", "III"}, {"Bureaucracy", "IV"},
    {"Aftermath", "V"}
};

const std::vector<holiday_type> HOLIDAYS{
    {"5.Chaos", "Mungtday"}, {"50.Chaos", "Chaoflux"},
    {"5.Discord", "Mojoday"}, {"50.Discord", "Discoflux"},
    {"5.Confusion", "Syaday"}, {"50.Confusion", "Confuflux"},
    {"5.Bureaucracy", "Zaraday"}, {"50.Bureaucracy", "Bureflux"},
    {"5.Aftermath", "Maladay"}, {"50.Aftermath", "Afflux"}
};

inline const auto get_nth_day_of_year(const gregorian_date& date_) {
    auto sum{ 0 };
    auto ily{ date_.year % 4 == 0 && date_.year % 100 != 0 || date_.year % 400 == 0 };
    size_t mon[]{ 31, ily ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    for (auto i{ 0 }; i < date_.month - 1; ++i) sum += mon[i];
    return sum + date_.day;
}

inline const discordian_date get_discordian_date(const gregorian_date& date_, bool short_t_ = false) {
    // gregorian day of the year
    const auto day_greg{ get_nth_day_of_year(date_) };

    // discordian day
    const auto day_tmp{ day_greg % DAYS_SEASON };
    const auto day{ day_tmp == 0 ? DAYS_SEASON : day_tmp };

    // discordian season
    size_t season{};
    const auto season_tmp{ day_greg / DAYS_SEASON };
    if (season_tmp == DAYS_WEEK) season = DAYS_WEEK - 1;
    else if (season_tmp == 0 && season_tmp > 0) season = season_tmp - 1;
    else season = season_tmp;
    const auto& season_type{ short_t_ ? SEASONS[season].short_type : SEASONS[season].long_type };

    // discordian weekday
    const auto weekday_tmp{ day_greg % DAYS_WEEK };
    const auto weekday{ weekday_tmp == 0 ? DAYS_WEEK - 1 : weekday_tmp };
    const auto& weekday_type{ short_t_ ? WEEKDAYS[weekday].short_type : WEEKDAYS[weekday].long_type };

    return { day, date_.year + YEAR_DIFF, season_type, weekday_type };
}

inline const auto get_holiday(const gregorian_date& date_) {
    const auto& [day, year, season, weekday] = get_discordian_date(date_);

    std::stringstream find, out_greg, out_disc, type;

    out_greg << "gregorian: " << date_.day << "." << date_.month << "." << date_.year << "\n";

    find << day << "." << season;
    auto found{ std::find_if(HOLIDAYS.begin(), HOLIDAYS.end(), [&find](const auto& x) { return x.date == find.str(); }) };
    if (found != HOLIDAYS.end()) {
        type << (day == 5 ? "apostle" : "season") << " holiday";
        out_disc << weekday << ", " << day << ". " << season << " -> " << found->name << " (" << type.str() << ")\n";
    }
    else out_disc << "no holiday";

    return out_greg.str() + out_disc.str();
}

inline const std::ostream& print(std::ostream& os_, const gregorian_date& date_) {
    const auto& dis{ get_discordian_date(date_) };
    std::cout << std::format("gregorian: {}.{}.{}\ndiscordian: {}, {}.{} {} YOLD\n\n",
        date_.day, date_.month, date_.year, dis.weekday, dis.day, dis.season, dis.year);
    return os_;
}

int main() {
    // long format
    print(std::cout, { 19, 2, 2023 });

    // short format and leap year
    print(std::cout, { 29, 2, 2024 });

    // holiday
    std::cout << get_holiday({ 19, 2, 2023 }) << "\n";
}
                

Lösung von: Jens Kelm (@JKooP)

// C++ 20 | VS-2022
// Hier vom diskordianischen zum gregorianischen Kalender:

#include <iostream>
#include <vector>
#include <algorithm>
#include <format>

constexpr int DAYS_SEASON{ 73 };
constexpr int YEAR_DIFF{ 1166 };

enum class season_type {
    chaos, discord, confusion, bureaucracy, aftermath
};

struct discordian_date {
    int day;
    season_type season;
    int year;
};

struct gregorian_date {
    int day, month, year;
};

inline const gregorian_date get_gregorian_date(const discordian_date& date_) {
    const auto year{ date_.year - YEAR_DIFF };
    const auto day_of_year{ (int)date_.season * DAYS_SEASON + date_.day };
    const auto is_leap_year{ year % 4 == 0 && year % 100 != 0 || year % 400 == 0 };

    int mon[]{ 31, is_leap_year ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    int month{ 1 };
    int day{ (int)day_of_year };

    for (int i{ 0 }; i < 12; ++i) {
        if (day - mon[i] > 0) {
            day -= mon[i];
            month++;
        }
        else break;
    }
    return{ day, month, year };
}

inline const std::ostream& print(std::ostream& os_, const discordian_date& date_) {
    const auto greg{ get_gregorian_date(date_) };
    std::cout << std::format("gregorian: {:02}.{:02}.{:04}\n", greg.day, greg.month, greg.year);
    return os_;
}

int main() {
    print(std::cout, { 50, season_type::chaos, 3189 });
}
                

Lösung von: Jens Kelm (@JKooP)

function isLeapYear(num) {
  if (num & 3 != 0) return false;
  return (num % 100 != 0 || num % 400 == 0);
}

let DateToDiscordian = function(date = new Date()) {
  const
    SEASONS  =
      'Chaos_Discord_Confusion_Bureaucracy_The Aftermath'.split('_'),
    WEEKDAYS =
      'Sweetmorn_Boomtime_Pungenday_Prickle-Prickle_Setting Orange'.split('_'),
    APOSTLES =
      'Mungday Mojoday Syaday Zaraday Maladay'.split(' '),
    HOLIDAYS =
      'Chaoflux Discoflux Confuflux Bureflux Afflux'.split(' ');

  function getDayOfYear(d) {
    let dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
        mon      = d.getMonth(),
        day      = d.getDate(),
        out      = dayCount[mon] + day;
    return (mon > 2 && !isLeapYear(d.getFullYear())) ? out-- : out;
  }

  let y   = date.getFullYear(),
      doy = getDayOfYear(date),
      cel = null,                  // feiertag
      div = Math.floor(doy / 73),  // monat
      sea = doy % 73;              // tag im monat

  if (isLeapYear(y))
    if (doy == 60) cel = "St. Tib's Day";
  else if (doy > 60) doy--;
  doy--;

  if (sea == 0) { sea = 73; div--; }
  if (sea == 5) cel = APOSTELS[div];
  if (sea == 50) cel = HOLIDAYS[div];

  this.dayOfWeek = (cel == "St. Tib's Day") ? cel : WEEKDAYS[doy % 5];
  this.dayOfSeason = sea;
  this.season = SEASONS[div];
  this.yold = y + 1166;
  this.holiday = cel;

  /****************************************\
  |* FORMAT-PLATZHALTER                   *|
  |*--------------------------------------*|
  |* §Y§   jahreszahl                     *|
  |* §YN§  "Year of Our Lady of Discord"  *|
  |* §Yn§  "YOLD"                         *|
  |* §SN§  monatsname lang                *|
  |* §Sn§  monatsname kurz                *|
  |* §s§   monatszahl                     *|
  |* §sr§  monatszahl römisch             *|
  |* §DN§  tagesname lang                 *|
  |* §Dn§  tagesname kurz                 *|
  |* §d§   tag im monat                   *|
  |* §h§   feiertag (wenn's einer ist)    *|
  |****************************************/
  this.print = function(format = '§Y§-§s§-§d§', language = 'en') {
    const DICT = [
      // key (en)
      [
        'Year of Our Lady of Discord',
        'YOLD',
        SEASONS,
        'Chs Dsc Cfn Bcy Afm'.split(' '),
        WEEKDAYS,
        'SM BT PD PP SO'.split(' '),
        APOSTLES,
        HOLIDAYS,
        "St. Tib's Day"
      ],
      // de
      [
        'Jahr unserer Herrin der Zwietracht',
        'JuHdZ',
        'Chaos Zwietracht Verwirrung Bürokratie Nachhall'.split(' '),
        'Chs Zwi Ver Bür Nac'.split(' '),
        'Süßmorg Bumzeit Stichtag Prickelprickel Orangensatz'.split(' '),
        'Sü Bu St Pr Or'.split(' '),
        'Mungtag Mojotag Syatag Zaratag Malatag'.split(' '),
        'Chaoflux Zwieflux Wirrflux Büroflux Nachflux'.split(' '),
        'St. Tibtag'
      ],
      // eo
      [
        'Jaro de Nia Sinjorino de Diskordo',
        'JNSD',
        '?aoso Diskordo Konfuzo Burokratio Posteco'.split(' '),
        '?ao Dis Kon Bur Pos'.split(' '),
        'Dol?fruo ?a?stempo Piko Tiklotiklo Oran?subiro'.split(' '),
        'Do ?a Pi Ti Or'.split(' '),
        'Mungodo Mo?odo Sjado Zarado Malaklido'.split(' '),
        '?aofluxo Diskfluxo Konfukluxo Burofluxo Postfluxo'.split(' '),
        'Stª Tibo'
      ],
      // fr
      [
        'Année de Notre Dame Discorde',
        'ANDD',
        'Chaos Discorde Confusion Bureaucratie Contrecoup'.split(' '),
        'Chs Dis Con Bur Con'.split(' '),
        'Douxmat_Tempsboom_Jourâcre_Piquant-Piquant_Orange Couchant'.split('_'),
        'Do Te Jo Pi Oc'.split(' '),
        'Mungdi Mojodi Syadi Zaradi Maladi'.split(' '),
        'Chaoflux Discflux Confuflux Bureauflux Contreflux'.split(' '),
        'St. Tib'
      ]
    ];

    let l;
    switch(language) {
      case 'de': l = 1; break;
      case 'eo': l = 2; break;
      case 'fr': l = 3; break;
      default: l = 0;
    }

    let rom = 'I II III IV V'.split(' '),
        tmp;

    format = format.replace(/§Y§/g,  this.yold)
                   .replace(/§YN§/g, DICT[l][0])
                   .replace(/§Yn§/g, DICT[l][1])
                   .replace(/§s§/g,  SEASONS.indexOf(this.season)+1)
                   .replace(/§sr§/g, rom[SEASONS.indexOf(this.season)])
                   .replace(/§d§/g,  this.dayOfSeason);
    tmp = SEASONS.indexOf(this.season);
    format = format.replace(/§SN§/g, DICT[l][2][tmp])
                   .replace(/§Sn§/g, DICT[l][3][tmp]);

    if (this.dayOfWeek == "St. Tib's Day") {
      format = format.replace(/§DN§/g, DICT[l][8])
                     .replace(/§Dn§/g, '');
    } else {
      tmp = WEEKDAYS.indexOf(this.dayOfWeek);
      format = format.replace(/§DN§/g, DICT[l][4][tmp])
                     .replace(/§Dn§/g, DICT[l][5][tmp]);
    }
    if (this.holiday != null)
      switch (true) {
        case (this.holiday == "St. Tib's Day"):
          format = format.replace(/§h§/g, DICT[l][8]);
        break;
        case (this.holiday.endsWith('day')):
          tmp = APOSTLES.indexOf(this.holiday);
          format = format.replace(/§h/g, DICT[l][6][tmp]);
        break;
        case (this.holiday.endsWith('lux')):
          tmp = HOLIDAYS.indexOf(this.holiday);
          format = format.replace(/§h§/g, DICT[l][7][tmp]);
        break;
      }
    else format = format.replace(/§h§/g, '');
    return format;
  }
}

/* Und wo wir schonmal dabei sind... */
function discordToGregor(disc) {
  let year = disc.yold - 1166;
  if (disc.holiday == "St. Tib's Day") return new Date(year, 2-1, 29);
  let days =
    'Chaos_Discord_Confusion_Bureaucracy_The Aftermath'
      .split('_')
      .indexOf(disc.season) * 73 + disc.dayOfSeason;
  if (isLeapYear(year) && days > 59) days++;
  return new Date(year, 0, days);
}

/*********\
|* TESTS *|
\*********/

// ohne parameter: heutiges datum
let today = new DateToDiscordian();
console.table(today);
console.log(today.print());

let d = new Date(2007, 1-1, 1),
    dDate = new DateToDiscordian(d);

// Sweetmorn, 1. Chaos 3173 Year of Our Lady of Discord
console.log( dDate.print('§DN§, §d§. §SN§ §Y§ §YN§') );

// Sü, 1 I 3173 JuHdZ
console.log( dDate.print('§Dn§, §d§ §sr§ §Y§ §Yn§', 'de') );

// 23ª de Diskordo
d = new Date(2023, 4-1, 15);
console.log( new DateToDiscordian(d).print('§d§ª de §SN§', 'eo') );

// 69 Con
d = new Date(2023, 8-1, 3);
console.log( new DateToDiscordian(d).print('§d§ §Sn§', 'fr') );

// St. Tib’s Day 3170
d = new Date(2004, 2-1, 29);
console.log ( new DateToDiscordian(d).print('§DN§ §Y§') );

// Büroflux 3172
d = new Date(2006, 9-1, 26)
console.log( new DateToDiscordian(d).print('§h§ §Y§', 'de') );

dDate = {
  yold: 1234,
  season: 'The Aftermath', // 5
  dayOfSeason: 67
}
console.log( discordToGregor(dDate).toLocaleDateString() );

                

Lösung von: Lisa Salander (Heidi-Klum-Gymnasium Bottrop)

Aktionen

Bewertung

Durchschnittliche Bewertung:

Eigene Bewertung:
Bitte zuerst anmelden

Meta

Zeit: 1
Schwierigkeit: Mittel
Webcode: 7tkr-3a6w
Autor: ()

Download PDF

Download ZIP

Zu Aufgabenblatt hinzufügen