I’ve deleted my code so as not to show my solution, but modulo arithmetic is going to be part of most solutions, so we’ll have days of 0-27, not 1-28. Should the description reflect that, or am I way off in how I think about it? My first attempt recast day 28 as day 0, but that failed one of the tests; “day 1” is 0 days since the last new moon. Before I post an issue to Github, I want to make sure that I’m not the crazy one who expects a zero index here.
I mean, you’re not wrong, but that’s kind of the point of my question: We’re both right. I’d prefer that the instructions weren’t vague. It’s sort of like those “math arguments” that go around Facebook every couple of months, like 30/3(1+4), that only cause arguments because the problem is written in a way that allows multiple interpretations.
I used the modulus operator to go from 1-based indexing to 0-based and added 1 to return to 1-based indexing, so the lunar days can start over. However, I’m still running into errors.
The code I used for the implementation is:
(day - 1) % 28 + 1.
I believe I implemented the logic correctly.
if (lunarDay >= 1 && lunarDay <= 7) {
return "New";
}
if (lunarDay >= 8 && lunarDay <= 14) {
return “Waxing”;
}
if (lunarDay>= 15 && lunarDay <= 21) {
return “Full”;
}
if (lunarDay >= 22 && lunarDay <= 28) {
return “Waning”;
} else {
return moonPhase(`2000-1-${lunarDay - 28}`)
}
However, I am failing all the tests except two of them. Please help.
I assume that your ‘lunarday = (day-1)%28 + 1’, and ‘day’ is the total days difference between the current date and reference date? If you calculate ‘day’ correctly, lunarday should equal to ‘day%28 + 1’
because after every 28 days since reference date, the cycle repeats with day 1
Thank you for your response. I finally figured out what was wrong. I subtracted the input date from the reference date of “2000-01-06.” Then, I applied the 0 to 1 based index algorithm.
Yup, this is the problem that caused my initial post: When I wrote my original solution, I considered day 28 to be day 0, as seemed to be indicated by the problem description. That very test failed, which led me to the conclusion that when they say “day 1-7” they really mean “day 0-6.” It sounds like I wasn’t the only one confused.
I’m looking for the coding challenges on Github to create an issue for this, to tweak the problem’s description to avoid the confusion evident here, but I can’t find the coding challenges on Github. Are they in a separate repo? @ILM ?
2000-01-06 day 1 new
2000-01-07 day 2 new
2000-01-08 day 3 new
2000-01-09 day 4 new
2000-01-10 day 5 new
2000-01-11 day 6 new
2000-01-12 day 7 new
2000-01-13 day 8 waxing
you need to adjust the calculations
no, there is a block specifically called daily-challenges, well two: curriculum/challenges/english/blocks/daily-coding-challenges-javascript curriculum/challenges/english/blocks/daily-coding-challenges-python
they are not hidden. If you searched a piece of the instructions you would find them
OK; I didn’t see the daily-challenges directory. And In the future I’ll have to do that “search the description” thing; it’s easier than clicking through lots of incorrect challenges. I got to visit the Ghost of Coding Challenges Yet To Come, though.
I created the issue here, to open up comments to a broader audience. Maybe the consensus runs your way, that it’s correct, but I think the description could stand to be tightened up. Also, when there are required fields for which the content is irrelevant, I have too much fun with them. Under “System” I answered, “Not relevant, so I’ll claim to be running a Windows 12 beta on an IBM System/360, connected to the internet via a 110-baud handset-cradle modem.”
You need to subtract the input date from the reference date of “2000-01-06.”
For instance, if you input “2000-01-08,” calculate the difference in days between this date and the reference date.
Next, you will want to transition from a 1-based indexing system to a 0-based indexing system. This is important for your calculations.
Consider how you might normalize the resulting day count to fit within a lunar cycle. What mathematical operations could you use to ensure the day falls within an acceptable range?
message me back if you need more help with the problem.