Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/FizzBuzz/Rust/fizzbuzz-1.rust
Normal file
10
Task/FizzBuzz/Rust/fizzbuzz-1.rust
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fn main() {
|
||||
for i in 1..=100 {
|
||||
match (i % 3, i % 5) {
|
||||
(0, 0) => println!("fizzbuzz"),
|
||||
(0, _) => println!("fizz"),
|
||||
(_, 0) => println!("buzz"),
|
||||
(_, _) => println!("{}", i),
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Task/FizzBuzz/Rust/fizzbuzz-2.rust
Normal file
12
Task/FizzBuzz/Rust/fizzbuzz-2.rust
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
fn main() {
|
||||
(1..=100)
|
||||
.map(|n| match (n % 3, n % 5) {
|
||||
(0, 0) => "FizzBuzz".into(),
|
||||
(0, _) => "Fizz".into(),
|
||||
(_, 0) => "Buzz".into(),
|
||||
_ => Cow::from(n.to_string()),
|
||||
})
|
||||
.for_each(|n| println!("{:?}", n));
|
||||
}
|
||||
18
Task/FizzBuzz/Rust/fizzbuzz-3.rust
Normal file
18
Task/FizzBuzz/Rust/fizzbuzz-3.rust
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
fn fizzbuzz() -> String {
|
||||
(1..=100).fold(String::new(), |mut output, x| {
|
||||
let fizz = if x % 3 == 0 { "fizz" } else { "" };
|
||||
let buzz = if x % 5 == 0 { "buzz" } else { "" };
|
||||
if fizz.len() + buzz.len() != 0 {
|
||||
output + fizz + buzz + "\n"
|
||||
} else {
|
||||
write!(&mut output, "{}", x).unwrap();
|
||||
output + "\n"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", fizzbuzz());
|
||||
}
|
||||
37
Task/FizzBuzz/Rust/fizzbuzz-4.rust
Normal file
37
Task/FizzBuzz/Rust/fizzbuzz-4.rust
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#![no_std]
|
||||
#![feature(asm, lang_items, libc, no_std, start)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
const LEN: usize = 413;
|
||||
static OUT: [u8; LEN] = *b"\
|
||||
1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n\
|
||||
16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n\
|
||||
31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n\
|
||||
46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n\
|
||||
61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n\
|
||||
76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n\
|
||||
91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz\n";
|
||||
|
||||
#[start]
|
||||
fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
unsafe {
|
||||
asm!(
|
||||
"
|
||||
mov $$1, %rax
|
||||
mov $$1, %rdi
|
||||
mov $0, %rsi
|
||||
mov $1, %rdx
|
||||
syscall
|
||||
"
|
||||
:
|
||||
: "r" (&OUT[0]) "r" (LEN)
|
||||
: "rax", "rdi", "rsi", "rdx"
|
||||
:
|
||||
);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"] extern fn eh_personality() {}
|
||||
#[lang = "panic_fmt"] extern fn panic_fmt() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue