Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
35
Task/Box-the-compass/EasyLang/box-the-compass.easy
Normal file
35
Task/Box-the-compass/EasyLang/box-the-compass.easy
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
func$ expand cp$ .
|
||||
for c$ in strchars cp$
|
||||
if c$ = "N"
|
||||
r$ &= "north"
|
||||
elif c$ = "E"
|
||||
r$ &= "east"
|
||||
elif c$ = "S"
|
||||
r$ &= "south"
|
||||
elif c$ = "W"
|
||||
r$ &= "west"
|
||||
elif c$ = "b"
|
||||
r$ &= "by"
|
||||
else
|
||||
r$ &= "-"
|
||||
.
|
||||
.
|
||||
h$ = strchar (strcode substr r$ 1 1 - 32)
|
||||
return h$ & substr r$ 2 999
|
||||
.
|
||||
proc main . .
|
||||
cp$[] = [ "N" "NbE" "N-NE" "NEbN" "NE" "NEbE" "E-NE" "EbN" "E" "EbS" "E-SE" "SEbE" "SE" "SEbS" "S-SE" "SbE" "S" "SbW" "S-SW" "SWbS" "SW" "SWbW" "W-SW" "WbS" "W" "WbN" "W-NW" "NWbW" "NW" "NWbN" "N-NW" "NbW" ]
|
||||
print "Index Degrees Compass point"
|
||||
print "----- ------- -------------"
|
||||
for i = 0 to 32
|
||||
ind = (i + 1) mod1 32
|
||||
heading = i * 11.25
|
||||
if i mod 3 = 1
|
||||
heading += 5.62
|
||||
elif i mod 3 = 2
|
||||
heading -= 5.62
|
||||
.
|
||||
print ind & "\t" & heading & "\t" & expand cp$[ind]
|
||||
.
|
||||
.
|
||||
main
|
||||
|
|
@ -17,6 +17,6 @@ writeln "index degrees compass point"
|
|||
writeln "----- ------- -------------"
|
||||
|
||||
for .phi in .angles {
|
||||
val .i = truncate(.phi x 32 / 360 + 0.5) rem 32 + 1
|
||||
writeln $"\.i:5; \.phi:r2:6; \.box[.i];"
|
||||
val .i = trunc(.phi x 32 / 360 + 0.5) rem 32 + 1
|
||||
writeln $"\{.i:5} \{.phi:r2:6} \{.box[.i]}"
|
||||
}
|
||||
|
|
|
|||
59
Task/Box-the-compass/Swift/box-the-compass-1.swift
Normal file
59
Task/Box-the-compass/Swift/box-the-compass-1.swift
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import Foundation
|
||||
|
||||
extension Double {
|
||||
var nearestQr: Double {(self * 4.0).rounded(.toNearestOrAwayFromZero) / 4.0}
|
||||
}
|
||||
|
||||
extension Measurement<UnitAngle>/*: ExpressibleByFloatLiteral*/ {
|
||||
var cos: Double { Darwin.cos(self.converted(to: .radians).value) }
|
||||
var sin: Double { Darwin.sin(self.converted(to: .radians).value) }
|
||||
}
|
||||
|
||||
struct Compass {
|
||||
var bearing: Measurement<UnitAngle>
|
||||
var style: Style = .RN
|
||||
init(_ deg: Double, _ min: Double = 0, _ sec: Double = 0, style: Style = .RN
|
||||
) {
|
||||
self.bearing = .init(value: deg + min/60.0 + sec/360.0, unit: .degrees)
|
||||
self.style = style
|
||||
}
|
||||
static func degreesToPoints(_ deg: Double) -> Double {
|
||||
(deg/360 * 32).nearestQr
|
||||
}
|
||||
var point: Double {
|
||||
Self.degreesToPoints(self.bearing.value)
|
||||
}
|
||||
var quad: (String,String) {
|
||||
(bearing.cos < 0 ? "S" : "N", bearing.sin < 0 ? "W" : "E")
|
||||
}
|
||||
var step: (Int,Double) {
|
||||
let temp = 8 - abs(abs(self.point - 16) - 8)
|
||||
return (Int(temp),temp.truncatingRemainder(dividingBy: 1))
|
||||
}
|
||||
enum Style {case RN, USN, noBy}
|
||||
var formats = ["N", "NxE", "NNE", "NExN", "NE", "NExE", "ENE", "ExN", "E"]
|
||||
let fractions = ["¼","½","¾"]
|
||||
var invertedPoints: [Int] {
|
||||
switch self.style {
|
||||
case .RN: [3,6,7]
|
||||
case .USN: [3,7]
|
||||
case .noBy: [1,5,7]
|
||||
}
|
||||
}
|
||||
|
||||
func named() -> String {
|
||||
var (pt,frac) = self.step
|
||||
var fracStr: String = ""
|
||||
if frac != 0.0 {
|
||||
if invertedPoints.contains(pt) {
|
||||
pt += 1
|
||||
fracStr = fractions.reversed()[Int(frac * 4) - 1] + "N"
|
||||
} else {
|
||||
fracStr = fractions[Int(frac * 4) - 1] + "E"
|
||||
}
|
||||
}
|
||||
return (self.formats[pt] + fracStr)
|
||||
.replacing(/(N|E)/) { $0.output.0 == "N" ? self.quad.0 : self.quad.1 }
|
||||
.replacing(/x/) {_ in "by"}
|
||||
}
|
||||
}
|
||||
17
Task/Box-the-compass/Swift/box-the-compass-2.swift
Normal file
17
Task/Box-the-compass/Swift/box-the-compass-2.swift
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
let arr = [
|
||||
000.00, 016.87, 016.88, 033.75, 050.62, 050.63, 067.50, 084.37, 084.38,
|
||||
090.00, 101.25, 118.12, 118.13, 135.00, 151.87, 151.88, 168.75, 185.62,
|
||||
185.63, 202.50, 219.37, 219.38, 236.25, 253.12, 253.13, 270.00, 286.87,
|
||||
286.88, 303.75, 320.62, 320.63, 337.50, 354.37, 354.38
|
||||
]
|
||||
|
||||
let arr2 = stride(from: 0, through: 360, by: 22.5/8.0)
|
||||
|
||||
let pointFormatter = NumberFormatter()
|
||||
pointFormatter.minimumIntegerDigits = 2
|
||||
pointFormatter.minimumFractionDigits = 2
|
||||
|
||||
for d in arr {
|
||||
let c = Compass(d, style: .RN)
|
||||
print(pointFormatter.string(from: c.point as NSNumber)!, c.dms , c.named())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue