18
2
Let's build an advent Calendar for this Christmas!
Many Advent calendars for children take the form of a large rectangular card with numbered windows for each day of December starting from 1 ( although advent time begins on Advent Sunday, which is the fourth Sunday before Christmas day and often happens to be on November) and leading up to and including Christmas Eve (24) or in some cases Christmas day (25).
Windows are distributed across the calendar at a random position.
Every day children open the corresponding calendar window to reveal a small gift(usually a chocolate)
Task
The task is to display an advent calendar up to date following these rules:
- Include Christmas day : 1 to 25
- For days that have passed put an opened empty window
[ ]
( no different characters allowed ), so if i run the same code the next day there must be a new window opened. - At the current day put an opened window with a gift in it
[@]
( instead of@
you can use every printable character excep forspace
,[
,]
anddigits
). - For the remaining days put only the day number.
- At Christmas all the windows will be open, the next day they are all closed ( a new calendar ).
- Windows must open only on December, windows must stay closed on every month except for December.
- It should work the same way the next year, and every year, that is for example on December 2099 Windows start opening.
- Windows are laid down in random order on a 5 rows x 5 columns grid.
- The grid has not to be accurate, just consider that every windows must have at least one character space separating them on every side: left, top, right and bottom hence numbers must have left and right spaces of at least two characters.
Example
Today (15 December) :
23 21 [ ] 18 [ ] [ ] [ ] [ ] [ ] 16 24 22 [ ] 17 [ ] [ ] [ ] [ ] 25 19 [ ] [ ] [@] [ ] 20
Tomorrow (16 December) :
[ ] 17 25 [ ] [ ] [ ] 19 [ ] 18 21 [ ] 23 24 [ ] [ ] 22 [@] [ ] [ ] [ ] [ ] 20 [ ] [ ] [ ]
On every month different than December
18 23 21 12 19 25 24 3 15 14 16 9 17 20 4 8 2 11 5 7 6 13 10 22 1
All code-golf rules apply.
1Is it supposed to work as well for the next coming years or only for this year? (I suppose it's possible to golf a few bytes on some implementations by assuming a 2019 timestamp.) – Arnauld – 2019-12-15T00:41:05.283
1
So this was in the Sandbox for… 8 minutes?
– Adám – 2019-12-15T00:43:48.4131@JonathanAllan Indeed, Danish advent calenders don't include the 25th. – Adám – 2019-12-15T00:46:25.523
@Arnauld yes it's reusable like most of the commercial calendars, so year doesn't matter – AZTECCO – 2019-12-15T00:46:38.757
@Jonathan Allan yes and sorry .. I meant Christmas day.. Fixing – AZTECCO – 2019-12-15T00:49:09.163
1@Jonathan Allan yes you have to use system time, no input – AZTECCO – 2019-12-15T00:51:05.507
2@Adám sorry but Christmas is just around the corner, since there was no Christmas challenge I felt a bit sad, I used the sandbox to check if my script worked but as I expected it didn't. This is an exception, I'll continue to use the sandbox in the future. – AZTECCO – 2019-12-15T00:57:01.517
There's still ten days until Christmas... – Jo King – 2019-12-15T01:03:28.097
3@Jo King I don't want to see only open windows, at this time we have a good open/closed ratio – AZTECCO – 2019-12-15T01:06:01.617
2Earlier this year, I saw an Advent calendar where the gift was a different bottle of wine, so it's not just for kids to enjoy the gifts! – Giuseppe – 2019-12-15T01:59:58.373
@Adám Wow, with this challenge I learnt that there are advent calendars with 25 windows. Also in Austria and Germany (and pretty sure in all countries where Christmas is celebrated at the evening of the 24th of December), advent calenders have 24 windows only. – rexkogitans – 2019-12-16T08:13:04.477
Could you provide more testcase about Jan. 1st, Dec. 1st, Dec. 25th, Dec. 26th? since I don't know what advent calendar is... – tsh – 2019-12-16T08:20:48.450
@rexkogitans actually the regular advent calendar has 24 days but there are many exceptions on the market with 25 days or 24 + a merry Christmas slot – AZTECCO – 2019-12-16T08:31:42.093
@rexkogitans Though, to be fair, in later years, I've seen those that begin with the 25th — of November! One more week of shopping… – Adám – 2019-12-16T08:36:06.863
@tsh for this challenge, on every month except for December, it must print only days (no opened windows) although as pointed out before nothing stop you to open windows on every month. Gonna add test cases for clarity. – AZTECCO – 2019-12-16T08:40:33.337
@Adám in fact the real advent time begins on Advent Sunday, which is the fourth Sunday before Christmas day. It often happens to be on November. – AZTECCO – 2019-12-16T08:48:06.663