*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-04-11 01:17
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. # See these chapters of Sociology 500, a Novel, on line:
  12. # <http://joel-rees-economics.blogspot.com/2017/03/soc500-03-08-calendar-math.html>
  13. # <http://joel-rees-economics.blogspot.jp/2017/04/soc500-03-09-calculating-months-skip-years.html>
  14. # <http://joel-rees-economics.blogspot.com/2017/04/soc500-03-10-computers.html>
  15. # Novel table of contents and preface here:
  16. # <http://joel-rees-economics.blogspot.com/2017/01/soc500-00-00-toc.html>.
  17. #
  18. # Save as "econmonth.bc"
  19. # invoke as "bc -l econmonth.bc
  20. #
  21. # In the running bc session, run it with
  22. # showmonths(7) for seven years, etc.
  23. scale = 10;
  24. months[ 0 ] = 30;
  25. months[ 1 ] = 29;
  26. months[ 2 ] = 30;
  27. months[ 3 ] = 29;
  28. months[ 4 ] = 29;
  29. months[ 5 ] = 30;
  30. months[ 6 ] = 29;
  31. months[ 7 ] = 30;
  32. months[ 8 ] = 29;
  33. months[ 9 ] = 29;
  34. months[ 10 ] = 30;
  35. months[ 11 ] = 29;
  36. define abs( n ) {
  37. if ( n >= 0 ) {
  38. return n;
  39. }
  40. return -n;
  41. }
  42. # If you want to do something similar,
  43. # for looking at how leap years in your world
  44. # match the actual orbits and revolutions
  45. # of your world and its moon,
  46. # replace isskip() with an appropriate isleap().
  47. # Left as an exercise for the reader.
  48. define isskip( y, m ) {
  49. if ( m != 0 ) {
  50. return 0;
  51. }
  52. mem = scale;
  53. scale = 0;
  54. diff7 = y % 7;
  55. diff98 = y % 98;
  56. diff343 = y % 343;
  57. scale = mem;
  58. if ( diff98 == 48 ) {
  59. return 1;
  60. }
  61. if ( ( diff7 != 1 ) && ( diff7 != 4 ) ) {
  62. return 0;
  63. }
  64. if ( diff343 == 186 ) {
  65. return 0;
  66. }
  67. return 1;
  68. }
  69. # Note that we are treating the first year as year 0,
  70. # and the first month as month 0.
  71. # For your earth, you will need to adjust the year and month input and output.
  72. define showmonths( years ) {
  73. sum = 0;
  74. for ( year = 0; year < years; ++year ) {
  75. for ( month = 0; month <= 11; ++month ) {
  76. days = months[ month ];
  77. if ( isskip( year, month ) ) {
  78. days -= 1;
  79. }
  80. sum += days;
  81. product = year * ( 241957 / 686 ) + ( month + 1 ) * ( 241957 / 686 ) / 12;
  82. diff = product - sum;
  83. print year, " ", month, ": ", days, " (", sum , ", ", product, ": ", diff, ")";
  84. if ( abs( diff ) >= 1 ) {
  85. print "*** > 1 day! ";
  86. }
  87. print "\n";
  88. }
  89. }
  90. }
  91. # To show just the ideal months, run this:
  92. # showidealmonths(7) for seven years, etc.
  93. define showidealmonths( years ) {
  94. sum = 0;
  95. for ( year = 0; year < years; ++year ) {
  96. for ( month = 0; month < 12; ++month ) {
  97. days = 29;
  98. sum += days;
  99. product = year * ( 241957 / 686 ) + ( month + 1 ) * ( 241957 / 686 ) / 12;
  100. if ( ( product - sum ) >= 0 ) {
  101. days += 1; sum += 1;
  102. }
  103. print year, " ", month, ": ", days, " (", sum , ", ", product, ")\n";
  104. }
  105. }
  106. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text