-
Notifications
You must be signed in to change notification settings - Fork 0
/
mars.go
94 lines (85 loc) · 2.62 KB
/
mars.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2016 Gavin "Groovy" Grover. All rights reserved.
// Use of this source code is governed by the same BSD-style
// license as Go that can be found in the LICENSE file.
package main
import(
"fmt"
)
type MonthData []struct{ ds int; nm string }
var earthMths = MonthData {
{31, "Jan"}, {62, "Feb"}, {90, "Mar"}, {121, "Apr"}, {151, "May"}, {182, "Jun"},
{212, "Jul"}, {243, "Aug"}, {274, "Sep"}, {304, "Oct"}, {335, "Nov"}, {365, "Dec"},
}
var marsMths = MonthData {
{61, "Ari"}, {127, "Tau"}, {193, "Gem"}, {258, "Can"}, {318, "Leo"}, {372, "Vir"},
{422, "Lib"}, {469, "Sco"}, {515, "Sag"}, {562, "Cap"}, {613, "Aqu"}, {669, "Pis"},
}
const(
day = 24 * 60 * 60
sol = day + 39 * 60 + 35.24409
daysPerSol = sol/day // approx 1.0274912510 Earth days/sol
marsYear = 668.5991
earthYear = 365.2564
numYrs = 25
)
func main(){
var mthToggle bool
var monthsUsed = map[string]int{}
type MthStack struct{ arr []string; top int }
var mthStack MthStack = MthStack{[]string{"", "", "", "", ""}, 5}
var ma, mm, ms int = 1, 1, 0 //Martian annum, month, sol
var esta, edtm, edty float64 = 0.0, 0.0, 0.0 //elapsed sols this annum, earth-days this month, earth-days this year
fmt.Print("月: ")
for i:= 1; i <= 19; i++ { fmt.Printf("%4d ", i) }
fmt.Printf("\n%2d年:", ma)
for ; ma <= numYrs; ms++ {
if edtm > float64(ms) + 1 && ms % 7 == 6 {
var mthNm string
if mthToggle {
mthNm= "Pis"
mlab: for i:= 0; i < 12; i++ {
if esta <= float64(marsMths[i].ds) {
mthNm= marsMths[(i+11)%12].nm
break mlab
}
}
} else {
mthNm= "Dec"
elab: for i:= 0; i < 12; i++ {
if edty <= float64(earthMths[i].ds) {
mthNm= earthMths[(i+11)%12].nm
if mthNm == mthStack.arr[mthStack.top - 5] {
mthNm= earthMths[i%12].nm
}
break elab
}
}
if mthNm == "Dec" && mthNm == mthStack.arr[mthStack.top - 5] {
mthNm= "Jan"
}
mthStack.arr = append(mthStack.arr, mthNm)
mthStack.top++
}
fmt.Printf(" %s", mthNm)
monthsUsed[mthNm]++
mthToggle = !mthToggle
if ms == 34 { fmt.Printf(" ") } else { fmt.Printf("+ ") }
if esta > marsYear {
ma++; mm = 0
esta -= marsYear
fmt.Printf("\n%2d年:", ma)
}
edtm -= float64(ms) + 1
if edty > earthYear {
edty -= earthYear
}
mm++; ms = 0
}
edtm += daysPerSol
edty += daysPerSol
esta++
}
fmt.Println()
for k, v:= range monthsUsed { fmt.Printf("%s:%2d, ", k, v) }
fmt.Println()
}