How to resolve the algorithm Calendar step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

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  411
  5  6  7  8  9 10 112  3  4  5  6  7  82  3  4  5  6  7  8
 12 13 14 15 16 17 189 10 11 12 13 14 159 10 11 12 13 14 15
 19 20 21 22 23 24 2516 17 18 19 20 21 2216 17 18 19 20 21 22
 26 27 28 29 30 3123 24 25 26 27 2823 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  51  2  31  2  3  4  5  6  7
  6  7  8  9 10 11 124  5  6  7  8  9 108  9 10 11 12 13 14
 13 14 15 16 17 18 1911 12 13 14 15 16 1715 16 17 18 19 20 21
 20 21 22 23 24 25 2618 19 20 21 22 23 2422 23 24 25 26 27 28
 27 28 29 3025 26 27 28 29 30 3129 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  51  21  2  3  4  5  6
  6  7  8  9 10 11 123  4  5  6  7  8  97  8  9 10 11 12 13
 13 14 15 16 17 18 1910 11 12 13 14 15 1614 15 16 17 18 19 20
 20 21 22 23 24 25 2617 18 19 20 21 22 2321 22 23 24 25 26 27
 27 28 29 30 3124 25 26 27 28 29 3028 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  411  2  3  4  5  6
  5  6  7  8  9 10 112  3  4  5  6  7  87  8  9 10 11 12 13
 12 13 14 15 16 17 189 10 11 12 13 14 1514 15 16 17 18 19 20
 19 20 21 22 23 24 2516 17 18 19 20 21 2221 22 23 24 25 26 27
 26 27 28 29 30 3123 24 25 26 27 28 2928 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