The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
Write a function in your favorite language to create a "day view" in an array for a month, like 11/2019. So for that month/year, the array should look like this, where the day numbers not in the month are null or undefined:
- convince a culture with a different week size to adopt the 7 days week.
- convince a culture without the concept of calendar to adopt a 10 days week calendar (or 5 day, for the impatient), and then apply previous step.
printMonth :: Integer -> Int -> IO ()
printMonth year month = printWeeks entriesInMonth
-- printWeeks chunks the month's entries into weeks & prints each week on a new line
printWeeks days = mapM_ (putStrLn.unwords) (chunksOf 7 days)
-- entriesInMonth concatenates the empty entries at the start of the month with the days
entriesInMonth = startPadding ++ daysOfMonth
-- daysOfMonth generates a list of days of the month as strings
daysOfMonth = map (printf "%2d") [1..(julianMonthLength year month)]
-- startPadding generates blank strings for each empty entry before day '1'
startPadding = replicate blanksBeforeDay1 " "
-- blanksBeforeDay1 is the number of empty entries before day '1'
blanksBeforeDay1 = (fromEnum $ dayOfWeek (fromJulian year month 1)) `mod` 7
[ETA] That's using the Julian calendar - the standard Gregorian calendar can be used by replacing the word 'julian' or 'Julian' with 'gregorian'/'Gregorian'. And yes, I should be able to remember which calendar we use [/ETA]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
modified 6-Nov-19 8:41am.
Last Visit: 17-Jan-20 2:52 Last Update: 17-Jan-20 2:52