Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: 115 Characters #6

Closed
DarkRTA opened this issue Oct 14, 2020 · 0 comments
Closed

Rust: 115 Characters #6

DarkRTA opened this issue Oct 14, 2020 · 0 comments

Comments

@DarkRTA
Copy link

DarkRTA commented Oct 14, 2020

extern { fn putchar(x: usize); } // links to putchar() in libc.

fn main() {
    let x = true as usize;       // x = 1
    let y = x + x + x;           // y = 3
    let z = (y << x + y) + x;    // z = 49
    for c in z..=z + y {         // loop c from 49 (z) to 52 (z + y)
        unsafe { putchar(c); }   // write c to stdout. extern functions are unsafe
    }
}

My dumbass at 1am forgot true existed and I ended up shaving off about 20 characters.
I highly doubt this can get any smaller without a different approach. x could have been reused by making it mutable but that wouldn't affect the character count.

@ISSOtm ISSOtm closed this as completed in 8d69c93 Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant