Post by MadhuI never did use REXX on an IBM system. My introduction to it was
ARexx, on the Amiga. What made is especially useful was that some
programs had a built-in Arexx interface, allowing an ARexx program to
do pretty much whatever the programmer wanted to expose to ARexx.
You can reduce the brute force problem space by half because the 4 year
;; YYYY-MM-DD: ABCD-DC-BA
;; YYYY-DD-MM: ABCD-DC-BA
And you can check if a year is a palindrome or not and you are done
without generating all the strings for every day and month.
[snip]
And quickly my eyes glazed over. I knew there was a reason I never
learned LISP. I cannot, for the life of me, figure out how you are
making the determination that the year is a palindrome.
Sorry, I did spring it on you to see if it was readable and the
algorithm was understandable and I guess that answers it. The posted
code has at least one off-by-one bug and is missing 2 lines in one
function lost in cut & paste
Nice. I can only assume that it's fasfter than mine, which takes about
0.033 seconds for 2021 to 2099.
The range is too small for any comparison and i dont think you can
compare script executions with the `time' command meaningfully
I downloaded and installed regina-rexx and read the wikipedia page for
the syntax for 2-3 hours I came up with this: the algorithm should be
faster. maybe you can check or comment
First, let me say that I didn't mean to nerdsnipe you. I should have
realized that you were susceptible when I saw your LISP program.
In case you aren't familiar with the term, see https://xkcd.com/356/
Of course, the entire Palindromic Dates thread nerdsniped me.
Anyway, thanks for the Rexx program. I now know how your algorithm
works, and it is VERY much faster than mine. Just for grins, I timed
both of them. Mine stutters when writing to the terminal, and yours
just slaps them all up faster than I can see it happening.
Mine:
real 0m2.884s
user 0m2.845s
sys 0m0.004s
Yours:
real 0m0.010s
user 0m0.010s
sys 0m0.000s
This time is for starting year = 1753, ending year = 9999.
This also showed me that the first palindromic year of the Gregorian
calendar is 2001/10/02, and that there are 288 palindromic years in
that range.
Your program looks good to me. There are a few things I need to
study. I have never used a parse like
parse var year 1 ab 3 3 cd 5
but it looks real handy.
I just checked, and it was also documented in ARexx. Can't believe I
missed it.
Post by Madhu#!/usr/bin/rexx
startyear = 2021
endyear = 2099
do y = startyear to endyear
if value(palindrome_year_p(y)) then
say y||reverse(y)
end
return 0
parse arg year
p = year // 4
q = year // 400
return (p = 0) & ^ (q = 100 | q = 200 | q = 300)
parse arg year month
select
when month = 1 | month = 3 | month = 5 | month = 8 | month = 10 | month = 12 then return 31
when month = 4 | month = 6 | month = 9 | month = 11 then return 30
when month = 2 then do
if gregorian_leap_year_p(year) then return 29
else return 28
end
otherwise
say "invalid month" month
exit 1
end
/* ABCD-DC-BA = YYYY-MM-DD*/
parse arg year
parse var year 1 ab 3 3 cd 5
mm = reverse(ab)
dd = reverse(cd)
return 0 < mm & mm < 13 & 0 < dd & dd < 1 + days_in_month(year mm)