Functions for working with the idealized calendar of Planet Xhilr
リビジョン | c15ac07f1ef24eb22dd62c0b10206b8d9a5df1d9 (tree) |
---|---|
日時 | 2017-06-13 16:37:12 |
作者 | Joel Matthew Rees <joel.rees@gmai...> |
コミッター | Joel Matthew Rees |
pastebin changes
@@ -1,20 +1,43 @@ | ||
1 | - | |
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 | +# Pastebin: https://osdn.net/users/reiisi/pastebin/4955 | |
18 | +# | |
19 | +# Save as "econmonth.bc" | |
20 | +# invoke as "bc -l econmonth.bc | |
21 | +# | |
22 | +# In the running bc session, run it with | |
23 | +# showmonths(7) for seven years, etc. | |
24 | + | |
2 | 25 | |
3 | 26 | scale = 10; |
4 | 27 | |
5 | 28 | |
6 | -months[ 1 ] = 30; | |
7 | -months[ 2 ] = 29; | |
8 | -months[ 3 ] = 30; | |
29 | +months[ 0 ] = 30; | |
30 | +months[ 1 ] = 29; | |
31 | +months[ 2 ] = 30; | |
32 | +months[ 3 ] = 29; | |
9 | 33 | months[ 4 ] = 29; |
10 | -months[ 5 ] = 29; | |
11 | -months[ 6 ] = 30; | |
12 | -months[ 7 ] = 29; | |
13 | -months[ 8 ] = 30; | |
34 | +months[ 5 ] = 30; | |
35 | +months[ 6 ] = 29; | |
36 | +months[ 7 ] = 30; | |
37 | +months[ 8 ] = 29; | |
14 | 38 | months[ 9 ] = 29; |
15 | -months[ 10 ] = 29; | |
16 | -months[ 11 ] = 30; | |
17 | -months[ 12 ] = 29; | |
39 | +months[ 10 ] = 30; | |
40 | +months[ 11 ] = 29; | |
18 | 41 | |
19 | 42 | define abs( n ) { |
20 | 43 | if ( n >= 0 ) { |
@@ -24,8 +47,15 @@ define abs( n ) { | ||
24 | 47 | } |
25 | 48 | |
26 | 49 | |
50 | +# If you want to do something similar, | |
51 | +# for looking at how leap years in your world | |
52 | +# match the actual orbits and revolutions | |
53 | +# of your world and its moon, | |
54 | +# replace isskip() with an appropriate isleap(). | |
55 | +# Left as an exercise for the reader. | |
56 | + | |
27 | 57 | define isskip( y, m ) { |
28 | - if ( m != 1 ) { | |
58 | + if ( m != 0 ) { | |
29 | 59 | return 0; |
30 | 60 | } |
31 | 61 | mem = scale; |
@@ -41,28 +71,31 @@ define isskip( y, m ) { | ||
41 | 71 | return 0; |
42 | 72 | } |
43 | 73 | if ( diff343 == 186 ) { |
44 | -# if ( ( diff343 == 53 ) || ( diff343 == 246 ) ) { | |
45 | 74 | return 0; |
46 | 75 | } |
47 | 76 | return 1; |
48 | 77 | } |
49 | 78 | |
50 | 79 | |
80 | +# Note that we are treating the first year as year 0, | |
81 | +# and the first month as month 0. | |
82 | +# For your earth, you will need to adjust the year and month input and output. | |
83 | + | |
84 | + | |
51 | 85 | define showmonths( years ) { |
52 | 86 | sum = 0; |
53 | 87 | for ( year = 0; year < years; ++year ) { |
54 | - for ( month = 1; month <= 12; ++month ) { | |
88 | + for ( month = 0; month <= 11; ++month ) { | |
55 | 89 | days = months[ month ]; |
56 | 90 | if ( isskip( year, month ) ) { |
57 | 91 | days -= 1; |
58 | 92 | } |
59 | 93 | sum += days; |
60 | -# product = year * ( 241959 / 686 ) + month * ( 241957 / 686 ) / 12; | |
61 | - product = year * ( 241957 / 686 ) + month * ( 241957 / 686 ) / 12; | |
94 | + product = year * ( 241957 / 686 ) + ( month + 1 ) * ( 241957 / 686 ) / 12; | |
62 | 95 | diff = product - sum; |
63 | 96 | print year, " ", month, ": ", days, " (", sum , ", ", product, ": ", diff, ")"; |
64 | 97 | if ( abs( diff ) >= 1 ) { |
65 | - print "*** "; | |
98 | + print "*** > 1 day! "; | |
66 | 99 | } |
67 | 100 | print "\n"; |
68 | 101 | } |