mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-11-08 19:20:47 -05:00
Merge branch 'ratfactor:main' into testing
This commit is contained in:
commit
2cb6975b13
7 changed files with 9 additions and 9 deletions
|
@ -11,7 +11,7 @@
|
|||
// ...
|
||||
// }
|
||||
//
|
||||
// Perhaps knowing this well help solve the errors we're getting
|
||||
// Perhaps knowing this will help solve the errors we're getting
|
||||
// with this little program?
|
||||
//
|
||||
const std = @import("std");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// There is also an 'inline while'. Just like 'inline for', it
|
||||
// loops at compile time, allowing you do all sorts of
|
||||
// loops at compile time, allowing you to do all sorts of
|
||||
// interesting things not possible at runtime. See if you can
|
||||
// figure out what this rather bonkers example prints:
|
||||
//
|
||||
|
|
|
@ -69,7 +69,7 @@ pub fn main() void {
|
|||
}
|
||||
|
||||
// Here's our generic sequence printing function. It's nearly
|
||||
// complete, but there are a couple missing bits. Please fix
|
||||
// complete, but there are a couple of missing bits. Please fix
|
||||
// them!
|
||||
fn printSequence(my_seq: anytype) void {
|
||||
const my_typeinfo = @typeInfo(@TypeOf(my_seq));
|
||||
|
|
|
@ -86,7 +86,7 @@ const Insect = union(enum) {
|
|||
|
||||
// Thanks to 'inline else', we can think of this print() as
|
||||
// being an interface method. Any member of this union with
|
||||
// with a print() method can be treated uniformly by outside
|
||||
// a print() method can be treated uniformly by outside
|
||||
// code without needing to know any other details. Cool!
|
||||
pub fn print(self: Insect) void {
|
||||
switch (self) {
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
// std.debug.print("ptr={*}\n", .{ptr});
|
||||
//
|
||||
// const slice_ptr = try allocator.alloc(f64, 5);
|
||||
// std.debug.print("ptr={*}\n", .{ptr});
|
||||
// std.debug.print("slice_ptr={*}\n", .{slice_ptr});
|
||||
// }
|
||||
|
||||
// Instead of an simple integer or a constant sized slice, this
|
||||
|
|
|
@ -39,7 +39,7 @@ fn isPangram(str: []const u8) bool {
|
|||
// first we check if the string has at least 26 characters
|
||||
if (str.len < 26) return false;
|
||||
|
||||
// we uses a 32 bit variable of which we need 26 bit
|
||||
// we uses a 32 bit variable of which we need 26 bits
|
||||
var bits: u32 = 0;
|
||||
|
||||
// loop about all characters in the string
|
||||
|
@ -50,8 +50,8 @@ fn isPangram(str: []const u8) bool {
|
|||
//
|
||||
// to do this, we use a little trick:
|
||||
// since the letters in the ASCI table start at 65
|
||||
// and are numbered by, we simply subtract the first
|
||||
// letter (in this case the 'a') from the character
|
||||
// and are numbered sequentially, we simply subtract the
|
||||
// first letter (in this case the 'a') from the character
|
||||
// found, and thus get the position of the desired bit
|
||||
bits |= @as(u32, 1) << @truncate(u5, ascii.toLower(c) - 'a');
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
// These can be used in different ways, but typically to convert
|
||||
// numerical values into various text representations. The
|
||||
// results can be used for direct output to a terminal or stored
|
||||
// for later use or written to file. The latter is useful when
|
||||
// for later use or written to a file. The latter is useful when
|
||||
// large amounts of data are to be processed by other programs.
|
||||
//
|
||||
// In Ziglings, we are concerned with the output to the console.
|
||||
|
|
Loading…
Reference in a new issue