mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-11-09 19:40:48 -05:00
added 059
This commit is contained in:
parent
34eef5bd24
commit
1427d3b6f1
3 changed files with 40 additions and 0 deletions
|
@ -302,6 +302,10 @@ const exercises = [_]Exercise{
|
||||||
.output = "Archer's Point--2->Bridge--1->Dogwood Grove--3->Cottage--2->East Pond--1->Fox Pond",
|
.output = "Archer's Point--2->Bridge--1->Dogwood Grove--3->Cottage--2->East Pond--1->Fox Pond",
|
||||||
.hint = "This is the biggest program we've seen yet. But you can do it!"
|
.hint = "This is the biggest program we've seen yet. But you can do it!"
|
||||||
},
|
},
|
||||||
|
.{
|
||||||
|
.main_file = "059_integers.zig",
|
||||||
|
.output = "Zig is cool.",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Check the zig version to make sure it can compile the examples properly.
|
/// Check the zig version to make sure it can compile the examples properly.
|
||||||
|
|
28
exercises/059_integers.zig
Normal file
28
exercises/059_integers.zig
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// Zig lets you express integer literals in several convenient
|
||||||
|
// formats. These are all the same value:
|
||||||
|
//
|
||||||
|
// const a1: u8 = 65; // decimal
|
||||||
|
// const a2: u8 = 0x41; // hexadecimal
|
||||||
|
// const a3: u8 = 0o101; // octal
|
||||||
|
// const a4: u8 = 0b1000001; // binary
|
||||||
|
// const a5: u8 = 'A'; // UTF-8 code point literal
|
||||||
|
//
|
||||||
|
// You can also place underscores in numbers to aid readability:
|
||||||
|
//
|
||||||
|
// const t1: u32 = 14_689_520 // Ford Model T sales 1909-1927
|
||||||
|
// const t2: u32 = 0xE0_24_F0 // same, in hex pairs
|
||||||
|
//
|
||||||
|
// Please fix the message:
|
||||||
|
|
||||||
|
const print = @import("std").debug.print;
|
||||||
|
|
||||||
|
pub fn main() void {
|
||||||
|
var zig = [_]u8 {
|
||||||
|
0o131, // octal
|
||||||
|
0b1101000, // binary
|
||||||
|
0x66, // hex
|
||||||
|
};
|
||||||
|
|
||||||
|
print("{s} is cool.\n", .{zig});
|
||||||
|
}
|
8
patches/patches/059_integers.patch
Normal file
8
patches/patches/059_integers.patch
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
22,24c22,24
|
||||||
|
< 0o131, // octal
|
||||||
|
< 0b1101000, // binary
|
||||||
|
< 0x66, // hex
|
||||||
|
---
|
||||||
|
> 0o132, // octal
|
||||||
|
> 0b1101001, // binary
|
||||||
|
> 0x67, // hex
|
Loading…
Reference in a new issue