*nix utility bc program for showing the days in the years and months, with skip years (instead of leap years), for Bobbie, Karel, Dan, and Kristie's world. The novel can be found at http://joel-rees-economics.blogspot.com/2017/01/soc500-00-00-toc.html .

Format
Plain text
Post date
2017-03-24 15:15
Publication Period
Unlimited
  1. # bc script for showing the lengths of the months relative to skip years
  2. # for the world of Bobbie, Karel, Dan, and Kristie,
  3. #
  4. # by Joel Matthew Rees, winter/spring 2017.
  5. # Copyright 2017, Joel Matthew Rees
  6. #
  7. # Permission granted to use for personal entertainment only.
  8. # (If you need it for other purposes, rewriting it yourself is not that hard,
  9. # and the result will satisfy your needs much more effectively.)
  10. #
  11. # http://joel-rees-economics.blogspot.com/2017/03/soc500-03-08-calendar-math.html
  12. # http://joel-rees-economics.blogspot.com/2017/03/soc500-03-09-computer-calendar.html
  13. #
  14. # Novel here:
  15. # http://joel-rees-economics.blogspot.com/2017/01/soc500-00-00-toc.html
  16. #
  17. # Save as "econmonth.bc"
  18. # invoke as "bc -l econmonth.bc
  19. #
  20. # In the running bc session, run it with
  21. # showmonths(7) for seven years, etc.
  22. scale = 10;
  23. months[ 0 ] = 30;
  24. months[ 1 ] = 29;
  25. months[ 2 ] = 30;
  26. months[ 3 ] = 29;
  27. months[ 4 ] = 29;
  28. months[ 5 ] = 30;
  29. months[ 6 ] = 29;
  30. months[ 7 ] = 30;
  31. months[ 8 ] = 29;
  32. months[ 9 ] = 29;
  33. months[ 10 ] = 30;
  34. months[ 11 ] = 29;
  35. define abs( n ) {
  36. if ( n >= 0 ) {
  37. return n;
  38. }
  39. return -n;
  40. }
  41. # If you want to do something similar,
  42. # for looking at how leap years in your world
  43. # match the actual orbits and revolutions
  44. # of your world and its moon,
  45. # replace isskip() with an appropriate isleap().
  46. # Left as an exercise for the reader.
  47. define isskip( y, m ) {
  48. if ( m != 0 ) {
  49. return 0;
  50. }
  51. mem = scale;
  52. scale = 0;
  53. diff7 = y % 7;
  54. diff98 = y % 98;
  55. diff343 = y % 343;
  56. scale = mem;
  57. if ( diff98 == 48 ) {
  58. return 1;
  59. }
  60. if ( ( diff7 != 1 ) && ( diff7 != 4 ) ) {
  61. return 0;
  62. }
  63. if ( diff343 == 186 ) {
  64. return 0;
  65. }
  66. return 1;
  67. }
  68. # Note that we are treating the first year as year 0,
  69. # and the first month as month 0.
  70. # For your earth, you will need to adjust the year and month input and output.
  71. define showmonths( years ) {
  72. sum = 0;
  73. for ( year = 0; year < years; ++year ) {
  74. for ( month = 0; month <= 11; ++month ) {
  75. days = months[ month ];
  76. if ( isskip( year, month ) ) {
  77. days -= 1;
  78. }
  79. sum += days;
  80. product = year * ( 241957 / 686 ) + ( month + 1 ) * ( 241957 / 686 ) / 12;
  81. diff = product - sum;
  82. print year, " ", month, ": ", days, " (", sum , ", ", product, ": ", diff, ")";
  83. if ( abs( diff ) >= 1 ) {
  84. print "*** > 1 day! ";
  85. }
  86. print "\n";
  87. }
  88. }
  89. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text