How to resolve the algorithm Calendar step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Calendar step by step in the J programming language
Table of Contents
Problem Statement
Create a routine that will generate a text calendar for any year.
Test the calendar by generating a calendar for the year 1969, on a device of the time.
Choose one of the following devices:
(Ideally, the program will generate well-formatted calendars for any page width from 20 characters up.) Kudos (κῦδος) for routines that also transition from Julian to Gregorian calendar. This task is inspired by Real Programmers Don't Use PASCAL by Ed Post, Datamation, volume 29 number 7, July 1983. For further Kudos see task CALENDAR, where all code is to be in UPPERCASE. For economy of size, do not actually include Snoopy generation in either the code or the output, instead just output a place-holder.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Calendar step by step in the J programming language
Source code in the j programming language
require 'dates format' NB. J6.x
require 'dates general/misc/format' NB. J7.x
calBody=: (1 1 }. _1 _1 }. ":)@(-@(<.@%&22)@[ ]\ calendar@])
calTitle=: (<: - 22&|)@[ center '[Insert Snoopy here]' , '' ,:~ ":@]
formatCalendar=: calTitle , calBody
80 formatCalendar 1969
[Insert Snoopy here]
1969
Jan │ Feb │ Mar
Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa
1 2 3 4│ 1│ 1
5 6 7 8 9 10 11│ 2 3 4 5 6 7 8│ 2 3 4 5 6 7 8
12 13 14 15 16 17 18│ 9 10 11 12 13 14 15│ 9 10 11 12 13 14 15
19 20 21 22 23 24 25│ 16 17 18 19 20 21 22│ 16 17 18 19 20 21 22
26 27 28 29 30 31 │ 23 24 25 26 27 28 │ 23 24 25 26 27 28 29
│ │ 30 31
─────────────────────┼─────────────────────┼─────────────────────
Apr │ May │ Jun
Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa
1 2 3 4 5│ 1 2 3│ 1 2 3 4 5 6 7
6 7 8 9 10 11 12│ 4 5 6 7 8 9 10│ 8 9 10 11 12 13 14
13 14 15 16 17 18 19│ 11 12 13 14 15 16 17│ 15 16 17 18 19 20 21
20 21 22 23 24 25 26│ 18 19 20 21 22 23 24│ 22 23 24 25 26 27 28
27 28 29 30 │ 25 26 27 28 29 30 31│ 29 30
│ │
─────────────────────┼─────────────────────┼─────────────────────
Jul │ Aug │ Sep
Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa
1 2 3 4 5│ 1 2│ 1 2 3 4 5 6
6 7 8 9 10 11 12│ 3 4 5 6 7 8 9│ 7 8 9 10 11 12 13
13 14 15 16 17 18 19│ 10 11 12 13 14 15 16│ 14 15 16 17 18 19 20
20 21 22 23 24 25 26│ 17 18 19 20 21 22 23│ 21 22 23 24 25 26 27
27 28 29 30 31 │ 24 25 26 27 28 29 30│ 28 29 30
│ 31 │
─────────────────────┼─────────────────────┼─────────────────────
Oct │ Nov │ Dec
Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa
1 2 3 4│ 1│ 1 2 3 4 5 6
5 6 7 8 9 10 11│ 2 3 4 5 6 7 8│ 7 8 9 10 11 12 13
12 13 14 15 16 17 18│ 9 10 11 12 13 14 15│ 14 15 16 17 18 19 20
19 20 21 22 23 24 25│ 16 17 18 19 20 21 22│ 21 22 23 24 25 26 27
26 27 28 29 30 31 │ 23 24 25 26 27 28 29│ 28 29 30 31
│ 30 │
You may also check:How to resolve the algorithm N'th step by step in the Sidef programming language
You may also check:How to resolve the algorithm Nim game step by step in the Factor programming language
You may also check:How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the R programming language
You may also check:How to resolve the algorithm Feigenbaum constant calculation step by step in the Go programming language
You may also check:How to resolve the algorithm Generic swap step by step in the SNOBOL4 programming language