オエル世界の暦の計算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main(){ | |
int year4m1q3 = ffezCalendar.sys["year4m1q3"]!; | |
int year4d1m1q3 = ffezCalendar.sys["year4d1m1q3"]!; | |
int year4d1m1q4= ffezCalendar.sys["year4d1m1q4"]!; | |
print(365 - year4m1q3); | |
print((365 * 10 + 2) - (year4d1m1q3 * 4) - (year4d1m1q4 * 6)); | |
print((365 * 9 + 2) - (year4d1m1q3 * 4) - (year4d1m1q4 * 5)); | |
print((365 * 19 + 3) - (year4d1m1q3 * 8) - (year4d1m1q4 * 11)); | |
int startYear = 1482; | |
List<bool> lps = [true, true, false, | |
true, true, false, | |
true, true, false, | |
true, true, false, | |
true, true, false, | |
true, true, false, | |
true, true, false, | |
true, true, false, | |
true, true, false, | |
false, false, false, false]; | |
FfezCalendar al = FfezCalendar(startYear,year4d1m1q3,year4d1m1q4); | |
al.nYears(lps,al.to(5260)); | |
ffezCalendar.sys.putC("item","days"); | |
print(hr); | |
} | |
String hr = "---------------------------------------------------------------------------------------------------\n"; | |
FfezCalendarSys ffezCalendar = FfezCalendarSys(); | |
class FfezCalendarSys{ | |
Map<String,int> sys = {}; | |
FfezCalendarSys(){ | |
int day = 1; | |
int week = 3 * day; | |
int decade = 3 * week; | |
int month3 = 3 * decade; | |
int month4 = month3 + decade; | |
int season3 = 3 * month3; | |
int season4 = 3 * month4; | |
int year3 = 3 * season3; | |
int year4 = 3 * season4; | |
int year4d1 = year4 + decade; | |
int year4d2 = year4d1 + decade; | |
int year4m1q3 = year4 + month3; | |
int year4m1q4 = year4 + month4; | |
int year4d1m1q3 = year4d1 + month3; | |
int year4d1m1q4 = year4d1 + month4; | |
int year4d2m1q3 = year4d2 + month3; | |
int year4d2m1q4 = year4d2 + month4; | |
this.put("day",day); | |
this.put("week",week); | |
this.put("decade",decade); | |
this.put("month3",month3); | |
this.put("month4",month4); | |
this.put("season3",season3); | |
this.put("season4",season4); | |
this.put("year3",year3); | |
this.put("year4",year4); | |
this.put("year4d1",year4d1); | |
this.put("year4d2",year4d2); | |
this.put("year4m1q3",year4m1q3); | |
this.put("year4m1q4",year4m1q4); | |
this.put("year4d1m1q3",year4d1m1q3); | |
this.put("year4d1m1q4",year4d1m1q4); | |
this.put("year4d2m1q3",year4d2m1q3); | |
this.put("year4d2m1q4",year4d2m1q4); | |
} | |
void put(String key, int value){ | |
this.sys.putIfAbsent(key,()=>value); | |
} | |
} | |
class FfezCalendar{ | |
late int stYear; | |
late int year; | |
late bool isInCyc = false; | |
late int yearInCyc = 0; | |
late int cycYear = 0; | |
late int nDays; | |
late int lDays; | |
late double itgMeanDaysSubMax = 0; | |
late double itgMeanDaysSubMin = 0; | |
late double itgMeanDaysSubAbs = 0; | |
late int itgDaysInCyc = 0; | |
late double tgDaysInCycSubMax = 0; | |
late double tgDaysInCycSubMin = 0; | |
late double tgDaysInCycSubAbs = 0; | |
late int itgDaysF = 0; | |
late int itgDaysN = 0; | |
late int maxMeanYear = 0; | |
late int maxInCycYear = 0; | |
late int minMeanYear = 0; | |
late int minInCycYear = 0; | |
late int absMeanYear = 0; | |
late int absInCycYear = 0; | |
late double maxDaysOnMeanYear = 0; | |
late double maxDaysOnInCycYear = 0; | |
late double minDaysOnMeanYear = 0; | |
late double minDaysOnInCycYear = 0; | |
late double subMean = 0; | |
late double subInCyc = 0; | |
static bool Function(int) daysNB = (int yearT){ | |
if(yearT % 4 == 0){ | |
if(yearT % 100 == 0){ | |
return (yearT % 400 == 0); | |
}else{ | |
return true; | |
} | |
}else{ | |
return false; | |
} | |
}; | |
int Function(int) daysN = (int yearT)=> FfezCalendar.daysNB(yearT) ? 366 : 365; | |
FfezCalendar(int startYear, int nDays, int lDays){ | |
this.stYear = startYear; | |
this.year = startYear; | |
this.nDays = nDays; | |
this.lDays = lDays; | |
this.maxMeanYear = startYear; | |
this.maxInCycYear = startYear; | |
this.minMeanYear = startYear; | |
this.minInCycYear = startYear; | |
this.absMeanYear = startYear; | |
this.absInCycYear = startYear; | |
} | |
FfezCalendar next(bool isLeap){ | |
double maxTolerMean = 25; | |
double maxTolerInCyc = 25; | |
this.year++; | |
int tFDays = isLeap ? this.lDays: this.nDays; | |
int tNDays = this.daysN(this.year); | |
this.itgDaysF += tFDays; | |
this.itgDaysN += tNDays; | |
int sub = tNDays - tFDays; | |
int itgSub = this.itgDaysN - this.itgDaysF; | |
int yearSub = this.year - this.stYear; | |
double tFDaysMean = this.itgDaysF / yearSub; | |
double solar = 365.24218944; | |
if(this.isInCyc){ | |
this.yearInCyc++; | |
if(this.yearInCyc > this.cycYear){ | |
this.itgDaysInCyc = 0; | |
this.yearInCyc = 1; | |
} | |
print("第${this.year}年($yearSub年経過, ${this.cycYear}年周期中${this.yearInCyc}年目)::"); | |
}else{ | |
print("第${this.year}年($yearSub年経過)::"); | |
} | |
this.itgDaysInCyc += tFDays; | |
print("当該年日数差:$tNDays days - $tFDays days = $sub days"); | |
print("積算日数差 :${this.itgDaysN} days - ${this.itgDaysF} days = $itgSub days"); | |
print("平均日数 ;${this.itgDaysF} days / $yearSub years = $tFDaysMean days"); | |
print("平均回帰年との該当年日数差:$solar days - $tFDays days = ${solar - tFDays} days"); | |
print("平均回帰年との積算年日数差:${solar * yearSub} days - ${this.itgDaysF} days = ${(solar * yearSub) - this.itgDaysF} days"); | |
print("平均回帰年との平均日数差:$solar days - $tFDaysMean days = ${solar - tFDaysMean} days"); | |
double itgMDS = (solar * yearSub) - this.itgDaysF; | |
if(this.itgMeanDaysSubMax < itgMDS){ | |
this.itgMeanDaysSubMin = itgMDS; | |
print("(更新)"); | |
} | |
if(this.itgMeanDaysSubMin > itgMDS){ | |
this.itgMeanDaysSubMin = itgMDS; | |
print("(更新)"); | |
} | |
if(this.itgMeanDaysSubAbs.abs() < itgMDS.abs()){ | |
this.itgMeanDaysSubAbs = itgMDS; | |
print("(更新)"); | |
} | |
print("平均回帰年との積算年日数差絶対最大値:${this.itgMeanDaysSubMax} days"); | |
print("平均回帰年との積算年日数差絶対最大値:${this.itgMeanDaysSubMin} days"); | |
print("平均回帰年との積算年日数差絶対最大値:${this.itgMeanDaysSubAbs} days"); | |
if(this.isInCyc){ | |
print("周期中の日数平均:${this.itgDaysInCyc} days / ${this.cycYear} years = ${this.itgDaysInCyc / this.cycYear} days"); | |
print("周期中の平均回帰年との積算年日数差:${solar * this.yearInCyc} days - ${this.itgDaysInCyc} days = ${(solar * this.yearInCyc) - this.itgDaysInCyc} days"); | |
double yiccs = (solar * this.yearInCyc) - this.itgDaysInCyc; | |
if(this.tgDaysInCycSubMax < yiccs.abs()){ | |
this.tgDaysInCycSubMax = yiccs; | |
print("(更新)"); | |
} | |
if(this.tgDaysInCycSubMin > yiccs.abs()){ | |
this.tgDaysInCycSubMin = yiccs; | |
print("(更新)"); | |
} | |
if(this.tgDaysInCycSubAbs.abs() < yiccs.abs()){ | |
this.tgDaysInCycSubAbs = yiccs; | |
print("(更新)"); | |
} | |
print("周期中の平均回帰年との積算年日数差絶対最大値:${this.tgDaysInCycSubMax} days"); | |
print("周期中の平均回帰年との積算年日数差絶対最大値:${this.tgDaysInCycSubMin} days"); | |
print("周期中の平均回帰年との積算年日数差絶対最大値:${this.tgDaysInCycSubAbs} days"); | |
} | |
if(this.itgMeanDaysSubMax < maxTolerMean){ | |
this.maxMeanYear = this.year; | |
this.maxDaysOnMeanYear = this.itgMeanDaysSubMax; | |
} | |
if(this.tgDaysInCycSubMax < maxTolerInCyc){ | |
this.maxInCycYear = this.year; | |
this.maxDaysOnInCycYear = this.tgDaysInCycSubMax; | |
} | |
if(this.itgMeanDaysSubMin > maxTolerMean){ | |
this.minMeanYear = this.year; | |
this.minDaysOnMeanYear = this.itgMeanDaysSubMin; | |
} | |
if(this.tgDaysInCycSubMin > maxTolerInCyc){ | |
this.minInCycYear = this.year; | |
this.minDaysOnInCycYear = this.tgDaysInCycSubMin; | |
} | |
if(this.itgMeanDaysSubAbs.abs() < maxTolerMean){ | |
this.absMeanYear = this.year; | |
} | |
if(this.tgDaysInCycSubAbs.abs() < maxTolerInCyc){ | |
this.absInCycYear = this.year; | |
} | |
this.subMean = this.maxDaysOnMeanYear - this.minDaysOnMeanYear; | |
this.subInCyc = this.maxDaysOnInCycYear - this.minDaysOnInCycYear; | |
print(hr); | |
return this; | |
} | |
FfezCalendar nYears(List<bool> isLeaps, int years){ | |
this.isInCyc = true; | |
this.cycYear = isLeaps.length; | |
if(years <= 0){ | |
this.isInCyc = false; | |
print("積算平均最大値許容年:${this.maxMeanYear}年(経過${this.maxMeanYear - this.stYear}年)\t周期最大値許容年:${this.maxInCycYear}年(経過${this.maxInCycYear - this.stYear}年)"); | |
print("積算平均最小値許容年:${this.minMeanYear}年(経過${this.minMeanYear - this.stYear}年)\t周期最小値許容年:${this.minInCycYear}年(経過${this.minInCycYear - this.stYear}年)"); | |
print("積算平均絶対値許容年:${this.absMeanYear}年(経過${this.absMeanYear - this.stYear}年)\t周期絶対値許容年:${this.absInCycYear}年(経過${this.absInCycYear - this.stYear}年)"); | |
print("積算平均振れ幅値許容:${this.subMean}日\t周期振れ幅値許容:${this.subInCyc}日"); | |
print(hr); | |
return this; | |
}else{ | |
int ytemp = isLeaps.length - years; | |
bool isLeap = isLeaps[ytemp % isLeaps.length]; | |
this.next(isLeap); | |
return this.nYears(isLeaps, years - 1); | |
} | |
} | |
int to(int toYear){ | |
int temp = toYear - this.year; | |
return temp <= 0 ? 0 : temp; | |
} | |
} | |
extension MapChi<K,V> on Map<K,V>{ | |
void putC([String keyHead = "key", String valHead = "value"]) { | |
Iterable<MapEntry<K,V>> ent = this.entries; | |
int maxLen = ent.map<int>((MapEntry<K,V> e)=>e.key.toString().length).fold<int>(0,(int curr, int prev)=>curr > prev ? curr : prev); | |
Iterable<List<String>> st = ent.map((MapEntry<K,V> entry){ | |
String keym = (entry.key.toString()+" "); | |
String valm = entry.value.toString(); | |
return [keym,valm]; | |
}); | |
List<List<String>> st2 = [[keyHead,valHead]]; | |
st2.addAll(st); | |
String st3 = st2.map((List<String> e){ | |
String keym = e[0].padRight(maxLen+1,"."); | |
String valm = e[1]; | |
return [keym,valm].join(".. "); | |
}).join("\n"); | |
print(st3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment