Easter program

As a curio for next week, here’s a program that outputs the date of Easter for a given year. It uses the RPN interpreter dc which you may not even be aware is on your system.

I didn’t write it. I don’t even remember how I got it but it’s old and predates the Internet. As for the mathematical algorithm for calculating the date of Easter, that’s pretty well known and a search will find it for you.

#!/bin/sh
if test $# -lt 1
then
        echo usage: $0 year
        exit 1
fi
echo $* '[ddsf[lfp[too early
]Pq]s@1583>@
ddd19%1+sg100/1+d3*4/12-sx8*5+25/5-sz5*4/lx-10-sdlg11*20+lz+lx-30%
d[30+]s@0>@d[1+]s@lg11<@]s@25=@d[1+]s@24=@se44le-d[30+]s@21>@dld+7%-7+
[March ]smd[31-[April ]sm]s@31<@psnlmPpsn1z>p]splpx' | dc | tr '\012' ' '
echo ''

do you have a pointer to one for Ramadan, Hindu festivals, Chinese New
Years, and etc also?


palladium

No, but I’m sure you can search for them yourself. I confess to no interest in having programs to generate those since if I want to know, I can just look it up on the web.

Old joke, updated for the Internet:

Parent: What’s 2 and 2 kid?
Child: Hang on, let me find the Internet addition page.

If you want to, you could even make it spit out your birthday in a give year :wink:

> your birthday

when i reached Perfection i stopped having those.

hmmmm, or maybe it Paris, Panama City (Florida and Panama), Palma,
Philadelphia…


palladium

I tried to write something that is comparable hard to read, but I think it’s hard to do, as long, as you stick to serious languages. Should try C, though, that’s naturally obfuscated. rotfl!

My gforth implementation of Heiner Lichtenbergs (found in german Wikipedia) algorithm:

#! /usr/bin/env gforth

: easterdate next-arg s>number? if drop dup 100 / dup dup 3 * 3 + 4 / swap 8
* 13 + 25 / 15 rot + swap - swap 2 swap 3 * 3 + 4 / - swap rot dup 19 mod rot
over 19 * + 30 mod tuck dup 28 / over 29 / - rot 11 / * swap 29 / + swap 21 +
swap - -rot dup 4 / + + 7 mod 7 swap - over swap - 7 mod 7 swap - + dup 31 <=
if ." This years easterdate is march " . else 31 -
." This years easterdate is april " . then else ." Pass a number as Argument!"
2drop then cr bye ; easterdate

usage:

  • create a new textfile
  • copy-paste the code into the textfile
  • mark the file as executable
  • run it in the terminal with the year as first argument (without “-” or “–”)

you need to install gforth to use that:
su -c ‘zypper in gforth’
it’s in the official oss repositories.

It can be done in bash as well (no dc). I wrote this many years ago. Slightly longer code but readable.

#!/bin/bash
# easter.sh
#     Shell script to calculate the date of easter
#     in the Gregorian Calendar.
#
# usage:
#   easter.sh -dy]  <year>
#   easter.sh  -     (use standard input)
# where
#              d     = output format <day> <month> <year>
#              y     = add year to output
#                      (standard output: <day> <name of month> )
#
# Method by:   Spencer Jones, General Astronomy, 1922, pp 73-74;
#
#              Jean Meeus, Astronomical Formulae for Calculators,
#              3rd Edition, 1985, Willmann-Bell, Inc., Richmond
#              ISBN 0-943396-09-3
#

declare -i VA
declare -i VB
declare -i VC
declare -i VD
declare -i VE
declare -i VF
declare -i VG
declare -i VI
declare -i VK
declare -i VL
declare -i VM
declare -i VN
declare -i VP

if  "$1" = "-" -o $# -eq 0 ] ; then
   STDINP="`cat -`"
else
   STDINP="$*"
fi

OPTLTR="d"
DOPT=`echo "$STDINP" | sed \
 -e "s/^-${OPTLTR}]//g" \
 -e "s/--*/-/g"  \
 -e "s/${OPTLTR}${OPTLTR}*/${OPTLTR}/g"  \
 -e "s/-${OPTLTR}/${OPTLTR}/g"   \
 -e "s/${OPTLTR}${OPTLTR}*/${OPTLTR}/"   \
 -e "s/${OPTLTR}/-${OPTLTR}/"`

OPTLTR="y"
YOPT=`echo "$STDINP" | sed \
 -e "s/^-${OPTLTR}]//g" \
 -e "s/--*/-/g"  \
 -e "s/${OPTLTR}${OPTLTR}*/${OPTLTR}/g"  \
 -e "s/-${OPTLTR}/${OPTLTR}/g"   \
 -e "s/${OPTLTR}${OPTLTR}*/${OPTLTR}/"   \
 -e "s/${OPTLTR}/-${OPTLTR}/"`

NOW=`echo "$STDINP" | sed -e "s/^0-9]//g"`

YEAR=`echo "$NOW" | sed -e "/^0-9]/d"`
if  -z "$YEAR" ] ; then
   echo "Strange Argument $NOW"
   exit 1
fi

if  $YEAR -lt 1583 ] ; then
   echo 'Usage: easter -dy] <yyyy>  where yyyy >= 1583' 1>&2
   echo '       easter  -           (use standard input)' 1>&2
   exit 1
fi

# This is the start of the calculation
VA=$ $YEAR % 19 ]
VB=$ $YEAR / 100 ]
VC=$ $YEAR % 100 ]
VD=$ $VB / 4 ]
VE=$ $VB % 4 ]
VF=$ ( $VB + 8 ) / 25 ]
VG=$ ( $VB - VF + 1 ) / 3 ]
VH=$ ( (19 * $VA) + $VB - VD - $VG + 15 ) % 30 ]
VI=$ $VC / 4 ]
VK=$ $VC % 4 ]
VL=$ (32 + (2*$VE) + (2*$VI) - $VH - $VK) % 7 ]
VM=$ ($VA + (11 * $VH) + (22 * $VL)) / 451 ]
VN=$ ($VH + $VL - (7 * $VM) + 114) / 31 ]
VP=$ ($VH + $VL - (7 * $VM) + 114) % 31 ]

# output date format <day> <month> <year>
if  "$DOPT" = "-d" ] ; then
   echo -n $ $VP + 1 ]
   echo -n " "
   echo -n $ $VN ]
   echo " $YEAR"
   exit 0
fi

# output day of month
echo -n $ $VP + 1 ]

if  $VN -eq 3 ] ; then
   echo -n " March"
elif  $VN -eq 4 ] ; then
   echo -n " April"
else
   echo " unknown ERROR"
fi

if  "$YOPT" = "-y" ] ; then
   echo " $YEAR"
else
   echo
fi

exit 0

Just for the fun of it: I compared the results of all three programs for the range of years 1583 to 3000 and they all report the same results.

Readable? That’s against the programmer’s guild code of conduct! Programmers are supposed to obfuscate their programs as much as possible to ensure job security. My job is so secure because I spend all my days trying to work out what I wrote last week. :wink: lol!

Programmers are supposed to obfuscate their programs as much as possible

That’s why we have ‘sed’. Hmmm, thinking of the easter program written as a sed script … rotfl!

Perl user?

scnr

That’s why the popular languages we know are so incredible popular. They are very well suited for generating obfuscated code.

Just take a look at these two contests, where programmers show their most talent in programming skills to obfuscate their code as much as possible:
The International Obfuscated C Code Contest
The Linux Kernel Archives

The Forth programming language is very good designed for this. Yes, it has a clean syntax (what syntax can be cleaner than practically none?) and it’s very fast and easy to write programs in it, if you stick to some conventions (including the forth-convention to break conventions) and factorize your code in as many word defintions as possible. But to finally obfuscate it (what a programmer should never forget to do before committing the code!) you just need to defactorize them to as few word defintions as possible, throw away all formattings of code and then you are done.

C is also a very good language to confuse others with. It has powerful obfuscate-features like pointer-arithmetic and macroes, while practically every single syntax-decision fullfills the need of obfuscating. Just take a look at variable definitions:

int* a, b, c;

against, for example:

a, b, c : access integer;

you could think, both are doing the same, but here comes the stregth of C into play. You first list the type of the variables, then the variable names, so the types should all be “int*”. But, no, only “a” will be “int*” the others will be “int”. That’s good, while in the Ada example, you can way too easily see what’s going on. You will get three variables of the type “access integer”. That’s not good.

Consider a loop to repeat a task n times?

for(i=0; i<=n; i++)

against, for example:

for i = 1 to n do

one-off-error anyone? Yeah, plenty of them easily done in C, while it will get hard in the pascal-example.

The standard library is designed to be as less verbose as possible, the names are very carefully choosen in a way, the programmer can write and understand there meaning with just years of learning them. strtol, itoa, fprintf, frexp, ldexp, atof, atoi, atol, strtoul are just example of the amazing work C is doing for you to obfuscate your code and safe your job! And don’t forget the masses of buffer overflows and other errors you can easily produce to get money with further supporting the mess you’ve done. That’s how enterprise linux is working: Collecting a bunch of C-Software, give them away for free, knowing, that the users NEED the patches, they just provide for money.

With C++ it was planned to even get better than C. But while succeeding in some areas, C++ misses some of the stregths of C. Of course, they have increased the amount of pointer-confusing with providing not just one, no, dozens of different pointer types, all of them behaving slightly different from each other! That’s perhaps the best work they’ve done in C++: smart, smarter, the smartest! You are best off with using as many as possible different pointers to access one part of the memory to get your code most obfuscated. they’ve also introduced some new operators like “<<” which is not to confuse with “<<”, of course. but on the other side, they’ve weakened the macro-concept of C by providing templates and class-types. So, I would rate it a little bit worse than C.

Java is a good example of a language badly designed for obfuscating your code, but why is it so **** popular then? Java has archived something, not many languages can do: They’re training their newcomers in writing obfuscated code and sell it as clean and good design in a way similar to our governments selling us bureaucracy as something simple and working.

Let’s for example think about writing a command line application which takes two integers as input and the result as output and try to think in a Java way: You first want to get a nice architecture for your new application, but your nice tool to draw diagrams of any kind is getting “too old”, because you have already used it for the last team-project to substract two integers. So, you will need the first week of the project to search and evaluate the correct tools to design your application.

then you will perhaps very fast decide, that you need a multilayer-architecture for your project. Perhaps you would be better off with a MVC design, because it is more complicated, but at least you want to sell your software for as much money as possible. And we will se, we can make even this one complicated.

Then you need some classes. The following classes are designed for the logic-layer: infix_operator, add(infix-operator), infix-operand, summand(infix-operand), main. Because of the complexity of the classes you are perhaps better off with adding some additional inheritance, some generic classes and stuff.

The persistence-layer could be empty, because there is no persistence at all. But we are Java professionals, so for the case we will ever need persistence in that application, we will prepare some abstract classes and interfaces for all kind of databases, and some manual binary and text file managing.

As we speak about interfaces/multi-inheritance: To realize the presentation-layer we could define some interfaces like “printable” to add to result- and operands-classes, or “user-definable” we add to the operands. We will reach two goals with just one little trick: Our presentation layer have “presentation”- classes in it, so it looks like it’s well designed, but under the hood we have to implement them in our logic-layer. So we imply that we have a well designed, typical Java program, while in fact anyone whoever tries to maintain it will have much fun and a guaranteed job for, perhaps, the next few weeks.

That’s why Java is so popular!

Microsoft has now pushed, with C#, a kind of consolidation of all of this obfuscating-Work: A mixture between C, C++ and Java. C# in fact is an evil plan of Microsoft to destroy all competition by making competitors using that language. It’s designed like their Windows products which is planned to build upon the strengths of all of it’s predecessors: The feature-richness and visual appearance of Windows 1.0, the stability and security of Windows 95 and the speed and ressource-need of Windows Vista.

Bad for them, they failed with this for Windows 7 because Microsoft has one big problem: These plans are so confidential that their own employees use their products too, making a good plan going bad.

So, what languages have failed? Seriously? Ada is just gotten popular because the US agencies found out the tricks of programmers, so they pushed and even forced the usage of a well designed language and even managed to get some senseful documentation out there, that makes careless programmers to write good code in the end. At least, the community of programmers succesfully banned it succesfully in some niches. Perhaps one could be a little bit more tolerant to well-designed languages and code if it comes to safety critical applications. What do you think? Disasters in nuclear powerplants, crashing airplanes, weapon systems going wild and other things could even tend to give more programmers something to do.

Pascal was so succesful because nobody recognized it as dangerous. Nobody could have known, that a perhaps harmless programming language designed for teaching by a wrong-minded professor who didn’t understand the real needs of programmers (complicated pointer-arithmetic, cryptic syntax and dozens of gotos) will get so many users. The programmer community have been more careful after the success of Pascal, so none of those “clean and simple” successors of Pascal could get any bigger popularity.

What about D? Not to mention here, no real harm coming from this. Programmer-Communities already started heavy flamewars against it to defend themselves.

Go? At least it’s based on Oberon, so it eventually will become dangerous. Luckily it has C-like syntax. Is it just to leave the programmers in false sense of safety? Only google will know.

P.S.: Oh, forgot to mention PHP of course, but I think I don’t have to say much about it. If you want to make money out of programming, there’s an easy trick to do this with PHP: If a government organization looks for somebody to design a new webapp for them, they will always take the cheapest offer. So, regardless if you dissatify them, they will choose your offer next time again if you just have the cheapest offer again. Don’t worry, during the project stage you can always say something like: “Affordings have changed, so we have to raise the price from 5_000€ to 50_000€.” Nobody will care about. PHP is the best option to produce, fast, with low effort and 12 year old programmers, a very very very bad, unstable and unsecure webapplication which can feed your family for the rest of your live.

Ah, the Java logic layer is very badly designed. I think it’s better we use other classes, with the printables and user_definables added:
operator(printable)
binary_operator(operator)
infix_operator(binary_operator)
add(infix-operator)
infix_operand(printable, user_definable)
summand(infix-operand)
result(printable)
main

I can obfuscate any language you give me. >:)

Hey ken_yap,

Thanks for the Easter date generator.
You’re right: I didn’t realize that I had an RPN calculator in my 11.2 openSUSE system. I’ll check it out.
I chuckled over the “two plus two” joke at the end, too.

And BuddelBob, your commentary on confusion possibilities with languages is priceless. You should consider submitting it to a computer magazine for even wider public appreciation of your good humor.