Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Box-the-compass/Zig/box-the-compass-1.zig
Normal file
1
Task/Box-the-compass/Zig/box-the-compass-1.zig
Normal file
|
|
@ -0,0 +1 @@
|
|||
const std = @import("std");
|
||||
20
Task/Box-the-compass/Zig/box-the-compass-2.zig
Normal file
20
Task/Box-the-compass/Zig/box-the-compass-2.zig
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/// Degrees are not constrained to the range 0 to 360
|
||||
fn degreesToCompassPoint(degrees: f32) []const u8 {
|
||||
var d = degrees + comptime (11.25 / 2.0);
|
||||
while (d < 0) d += 360;
|
||||
while (d >= 360) d -= 360;
|
||||
const index: usize = @floatToInt(usize, @divFloor(d, 11.25));
|
||||
|
||||
// Concatenation to overcome the inability of "zig fmt" to nicely format long arrays.
|
||||
const points: [32][]const u8 = comptime .{} ++
|
||||
.{ "North", "North by east", "North-northeast", "Northeast by north" } ++
|
||||
.{ "Northeast", "Northeast by east", "East-northeast", "East by north" } ++
|
||||
.{ "East", "East by south", "East-southeast", "Southeast by east" } ++
|
||||
.{ "Southeast", "Southeast by south", "South-southeast", "South by east" } ++
|
||||
.{ "South", "South by west", "South-southwest", "Southwest by south" } ++
|
||||
.{ "Southwest", "Southwest by west", "West-southwest", "West by south" } ++
|
||||
.{ "West", "West by north", "West-northwest", "Northwest by west" } ++
|
||||
.{ "Northwest", "Northwest by north", "North-northwest", "North by west" };
|
||||
|
||||
return points[index];
|
||||
}
|
||||
16
Task/Box-the-compass/Zig/box-the-compass-3.zig
Normal file
16
Task/Box-the-compass/Zig/box-the-compass-3.zig
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
pub fn main() anyerror!void {
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
|
||||
_ = try stdout.print("Index Heading Compass point\n", .{});
|
||||
|
||||
for (0..33) |i| {
|
||||
var heading = @intToFloat(f32, i) * 11.25;
|
||||
heading += switch (i % 3) {
|
||||
1 => 5.62,
|
||||
2 => -5.62,
|
||||
else => 0,
|
||||
};
|
||||
const index = i % 32 + 1;
|
||||
_ = try stdout.print(" {d:2} {d:>6.2}° {s}\n", .{ index, heading, degreesToCompassPoint(heading) });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue