Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string getLunarPhase(string season, int dayCount, string initialPhase) {
- vector<string> phases = {
- "NewMoon", "Crescent", "Quarter", "Gibbous",
- "Full", "Waning", "Eclipse", "Twilight"
- };
- unordered_map<string, int> monthDays = {
- {"January", 31}, {"February", 28}, {"March", 31}, {"April", 30},
- {"May", 31}, {"June", 30}, {"July", 31}, {"August", 31},
- {"September", 30}, {"October", 31}, {"November", 30}, {"December", 31}
- };
- unordered_map<string, int> phaseIndex;
- for (int i = 0; i < phases.size(); ++i)
- phaseIndex[phases[i]] = i;
- // Step 1: Calculate total days from Jan 1 to (season, dayCount)
- int daysPassed = 0;
- for (auto& [month, days] : monthDays) {
- if (month == season) break;
- daysPassed += days;
- }
- daysPassed += (dayCount - 1); // 0-based offset
- // Step 2: Compute the resulting phase
- int startPhaseIdx = phaseIndex[initialPhase];
- int resultIdx = (startPhaseIdx + daysPassed) % 8;
- return phases[resultIdx];
- }
Advertisement
Add Comment
Please, Sign In to add comment