Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,32 @@
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
// array literal
const array1 = [9]i32{ 0, 1, 1, 2, 3, 5, 7, 12, 21 };
// infer the size of the array
const array2 = [_]i32{ 0, 1, 1, 2, 3, 5, 7, 12, 21 };
// alternative initialization using result location
const array3: [9]i32 = .{ 0, 1, 1, 2, 3, 5, 7, 12, 21 };
// initialize an array with zeros using array multiplication
var array4 = [_]i32{0} ** 5; // array length: 5
// assign elements to an array (must be declared as a variable)
array4[0] = -12;
array4[2] = 345;
array4[4] = -6;
// retieve elements from an array
try stdout.print("{d}, ", .{array4[0]});
try stdout.print("{d}, ", .{array4[1]});
try stdout.print("{d}, ", .{array4[2]});
try stdout.print("{d}, ", .{array4[3]});
try stdout.print("{d}\n", .{array4[4]});
// unused constants must be discarded
_ = array1; _ = array2; _ = array3;
}

View file

@ -0,0 +1,21 @@
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
// ArrayLists are initialized in the heap
var array = std.ArrayList(i32).init(allocator);
defer array.deinit();
// pushing elements to an ArrayList
try array.append(-12);
try array.append(345);
try array.append(-7);
// retrieving elements from an ArrayList
try stdout.print("{d}, ", .{array.items[0]});
try stdout.print("{d}, ", .{array.items[1]});
try stdout.print("{d}\n", .{array.items[2]});
}