Skip to main content
Added syntax highlighting; `--` aren't rust comments, `//` are.
Source Link
extern crate rand;fn main(){let t=("extern crate rand;fn main(){let t=", ";let mut s=format!(\"{}{:?}{}\",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!(\"{}\",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}");let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!("{}",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}
extern crate rand;fn main(){let t=("extern crate rand;fn main(){let t=", ";let mut s=format!(\"{}{:?}{}\",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!(\"{}\",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}");let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!("{}",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}
-- Random numbers are removed from the standard library in Rust,
-- I had to make a cargo project to even compile this...
-- Rust is hardly a golfing language.
extern crate rand;

fn main(){

    -- The quine is fairly simple, we just make a tuple with 
    -- "everything before this tuple" as first element, and
    -- "everything after this tuple" with any quotes escaped 
    -- as second. That makes it really easy to print.
    let t=("[...before...]", "[...after...]");
    
    -- Instead of printing it, we save it as a byte vector
    -- and append 0
    let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();
    s.push(0);

    -- Start with the first character
    let mut c=s[0];
    let mut r=rand::thread_rng();

    while c!=0 {
        print!("{}",c as char);

        -- We slide a 2 wide window over it to save a vector
        -- of all bigrams. 
        let u=s.windows(2);

        -- Filter it to only those which have the current character 
        -- as first. Take one at random, its second is our next 
        -- character.
        c=rand::sample(&mut r, u.filter(|x|x[0]==c), 1)[0][1];

        -- Keep at it until the 0 byte is generated.
    }
}
// Random numbers are removed from the standard library in Rust,
// I had to make a cargo project to even compile this...
// Rust is hardly a golfing language.
extern crate rand;

fn main(){

    // The quine is fairly simple, we just make a tuple with 
    // "everything before this tuple" as first element, and
    // "everything after this tuple" with any quotes escaped 
    // as second. That makes it really easy to print.
    let t=("[...before...]", "[...after...]");
    
    // Instead of printing it, we save it as a byte vector
    // and append 0
    let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();
    s.push(0);

    // Start with the first character
    let mut c=s[0];
    let mut r=rand::thread_rng();

    while c!=0 {
        print!("{}",c as char);

        // We slide a 2 wide window over it to save a vector
        // of all bigrams. 
        let u=s.windows(2);

        // Filter it to only those which have the current character 
        // as first. Take one at random, its second is our next 
        // character.
        c=rand::sample(&mut r, u.filter(|x|x[0]==c), 1)[0][1];

        // Keep at it until the 0 byte is generated.
    }
}
eran(),0{ller=samarin chas c).pr,teteran mut madoletet manthilaplerng().wind_byt.wit();let.u.0][*s=[*s.plleas.wshit, rnd:Vec<_byte mputextet ut t leat=r,t rant!=r().filllet rng();lar("{}{let.ind_byt.what amusarando_ramut!=st ct!(\").0]=colet!(&lec<_ret.plec=s.whrararandormpr=saile ret=r,0]=r);le(\"),t und;fint.prilt!();ler(2).forap(&ler=s(),t ut rat mu:t=ramund:Ve s.putec==[0];wst and_byt sh(\"et c s[1), munwhras[0];c=s=s="etornws(2)[0, ain(|x|x[0,0,0];fowile c ct(&l=",tes().co_byt().wrmat ash(|x|x[*s.lethrant.wrarmu.file(\"et, r==[1);uterile().0,t ando_rinwhas=[0{}"ect.wilant!("{ple mut, mut mamprmant,0];le(&lec=s.1),t co_>=fin mamustec!(\",c=[0];}}",0];leteteat.ust(",ternwhashrarmut ler("erat,0]==file and_reter==s.utet an letet.ut=", ras.1);fin("{:?}"et t letes[*sado_bytet rnd::Verain s[0];whant(){}{}\"echin s(2);lerad;wst reth(\",t u.iletermat c 1];}{}
eran(),0{ller=samarin chas c).pr,teteran mut madoletet manthilaplerng().wind_byt.wit();let.u.0][*s=[*s.plleas.wshit, rnd:Vec<_byte mputextet ut t leat=r,t rant!=r().filllet rng();lar("{}{let.ind_byt.what amusarando_ramut!=st ct!(\").0]=colet!(&lec<_ret.plec=s.whrararandormpr=saile ret=r,0]=r);le(\"),t und;fint.prilt!();ler(2).forap(&ler=s(),t ut rat mu:t=ramund:Ve s.putec==[0];wst and_byt sh(\"et c s[1), munwhras[0];c=s=s="etornws(2)[0, ain(|x|x[0,0,0];fowile c ct(&l=",tes().co_byt().wrmat ash(|x|x[*s.lethrant.wrarmu.file(\"et, r==[1);uterile().0,t ando_rinwhas=[0{}"ect.wilant!("{ple mut, mut mamprmant,0];le(&lec=s.1),t co_>=fin mamustec!(\",c=[0];}}",0];leteteat.ust(",ternwhashrarmut ler("erat,0]==file and_reter==s.utet an letet.ut=", ras.1);fin("{:?}"et t letes[*sado_bytet rnd::Verain s[0];whant(){}{}\"echin s(2);lerad;wst reth(\",t u.iletermat c 1];}{}
et!().0][0][0{}
et!().0][0][0{}
extern crate rand;fn main(){let t=("extern crate rand;fn main(){let t=", ";let mut s=format!(\"{}{:?}{}\",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!(\"{}\",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}");let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!("{}",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}
-- Random numbers are removed from the standard library in Rust,
-- I had to make a cargo project to even compile this...
-- Rust is hardly a golfing language.
extern crate rand;

fn main(){

    -- The quine is fairly simple, we just make a tuple with 
    -- "everything before this tuple" as first element, and
    -- "everything after this tuple" with any quotes escaped 
    -- as second. That makes it really easy to print.
    let t=("[...before...]", "[...after...]");
    
    -- Instead of printing it, we save it as a byte vector
    -- and append 0
    let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();
    s.push(0);

    -- Start with the first character
    let mut c=s[0];
    let mut r=rand::thread_rng();

    while c!=0 {
        print!("{}",c as char);

        -- We slide a 2 wide window over it to save a vector
        -- of all bigrams. 
        let u=s.windows(2);

        -- Filter it to only those which have the current character 
        -- as first. Take one at random, its second is our next 
        -- character.
        c=rand::sample(&mut r, u.filter(|x|x[0]==c), 1)[0][1];

        -- Keep at it until the 0 byte is generated.
    }
}
eran(),0{ller=samarin chas c).pr,teteran mut madoletet manthilaplerng().wind_byt.wit();let.u.0][*s=[*s.plleas.wshit, rnd:Vec<_byte mputextet ut t leat=r,t rant!=r().filllet rng();lar("{}{let.ind_byt.what amusarando_ramut!=st ct!(\").0]=colet!(&lec<_ret.plec=s.whrararandormpr=saile ret=r,0]=r);le(\"),t und;fint.prilt!();ler(2).forap(&ler=s(),t ut rat mu:t=ramund:Ve s.putec==[0];wst and_byt sh(\"et c s[1), munwhras[0];c=s=s="etornws(2)[0, ain(|x|x[0,0,0];fowile c ct(&l=",tes().co_byt().wrmat ash(|x|x[*s.lethrant.wrarmu.file(\"et, r==[1);uterile().0,t ando_rinwhas=[0{}"ect.wilant!("{ple mut, mut mamprmant,0];le(&lec=s.1),t co_>=fin mamustec!(\",c=[0];}}",0];leteteat.ust(",ternwhashrarmut ler("erat,0]==file and_reter==s.utet an letet.ut=", ras.1);fin("{:?}"et t letes[*sado_bytet rnd::Verain s[0];whant(){}{}\"echin s(2);lerad;wst reth(\",t u.iletermat c 1];}{}
et!().0][0][0{}
extern crate rand;fn main(){let t=("extern crate rand;fn main(){let t=", ";let mut s=format!(\"{}{:?}{}\",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!(\"{}\",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}");let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!("{}",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}
// Random numbers are removed from the standard library in Rust,
// I had to make a cargo project to even compile this...
// Rust is hardly a golfing language.
extern crate rand;

fn main(){

    // The quine is fairly simple, we just make a tuple with 
    // "everything before this tuple" as first element, and
    // "everything after this tuple" with any quotes escaped 
    // as second. That makes it really easy to print.
    let t=("[...before...]", "[...after...]");
    
    // Instead of printing it, we save it as a byte vector
    // and append 0
    let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();
    s.push(0);

    // Start with the first character
    let mut c=s[0];
    let mut r=rand::thread_rng();

    while c!=0 {
        print!("{}",c as char);

        // We slide a 2 wide window over it to save a vector
        // of all bigrams. 
        let u=s.windows(2);

        // Filter it to only those which have the current character 
        // as first. Take one at random, its second is our next 
        // character.
        c=rand::sample(&mut r, u.filter(|x|x[0]==c), 1)[0][1];

        // Keep at it until the 0 byte is generated.
    }
}
eran(),0{ller=samarin chas c).pr,teteran mut madoletet manthilaplerng().wind_byt.wit();let.u.0][*s=[*s.plleas.wshit, rnd:Vec<_byte mputextet ut t leat=r,t rant!=r().filllet rng();lar("{}{let.ind_byt.what amusarando_ramut!=st ct!(\").0]=colet!(&lec<_ret.plec=s.whrararandormpr=saile ret=r,0]=r);le(\"),t und;fint.prilt!();ler(2).forap(&ler=s(),t ut rat mu:t=ramund:Ve s.putec==[0];wst and_byt sh(\"et c s[1), munwhras[0];c=s=s="etornws(2)[0, ain(|x|x[0,0,0];fowile c ct(&l=",tes().co_byt().wrmat ash(|x|x[*s.lethrant.wrarmu.file(\"et, r==[1);uterile().0,t ando_rinwhas=[0{}"ect.wilant!("{ple mut, mut mamprmant,0];le(&lec=s.1),t co_>=fin mamustec!(\",c=[0];}}",0];leteteat.ust(",ternwhashrarmut ler("erat,0]==file and_reter==s.utet an letet.ut=", ras.1);fin("{:?}"et t letes[*sado_bytet rnd::Verain s[0];whant(){}{}\"echin s(2);lerad;wst reth(\",t u.iletermat c 1];}{}
et!().0][0][0{}
I just had to add some obvious optimizations.
Source Link
user61264
user61264

Rust, 618564 bytes (not competitive)

extern crate rand;fn main(){let t=("extern crate rand;fn main(){let t=", ";let mut s=format!(\"{}{:?}{}\",t.0,t,t.1).into_bytes();let l=[*s.last().unwrap(),0];let mut u:Vec<_>=s.windows(2).collect();u;s.push(&l0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!(\"{}\",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.iter().filter(|x|x[0]==c),1)[0][1];}}");let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();let l=[*s.last().unwrap(),0];let mut u:Vec<_>=s.windows(2).collect();u;s.push(&l0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!("{}",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.iter().filter(|x|x[0]==c),1)[0][1];}}
-- Random numbers are removed from the standard library in Rust,
-- I had to make a cargo project to even compile this...
-- Rust is hardly a golfing language.
extern crate rand;

fn main(){

    -- The quine is fairly simple, we just make a tuple with 
    -- "everything before this tuple" as first element, and
    -- "everything after this tuple" with any quotes escaped 
    -- as second. That makes it really easy to print.
    let t=("[...before...]", "[...after...]");
    
    -- Instead of printing it, we save it as a byte vector
    -- and append 0
    let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();
 
    -- We slide as.push(0);

 2 wide window over-- itStart towith savethe afirst vectorcharacter
    -- oflet allmut bigrams.c=s[0];
 We append (the lastlet character,mut 0r=rand::thread_rng();
  
   -- as a specialwhile bigramc!=0 to{
 mark the end.
    let l=[*s.last().unwrapprint!()"{}",0];
    letc mutas u:Vec<_>=s.windows(2).collect(char); 

    u.push(&l);

    -- StartWe withslide thea first2 character
wide window over it to letsave muta c=s[0];vector
    let mut r=rand::thread_rng();

  -- of whileall c!=0bigrams. {
        print!("{}",c aslet charu=s.windows(2);

        -- Filter the list of bigramsit to only those which have the current character 
        -- current character as first. Take one at random, its
  second is our next  
   -- second is our next -- character.
        c=rand::sample(&mut r, u.iter().filter(|x|x[0]==c), 1)[0][1];

        -- Keep at it until the 0 byte is generated.
    }
}

Rust, 618 bytes (not competitive)

extern crate rand;fn main(){let t=("extern crate rand;fn main(){let t=", ";let s=format!(\"{}{:?}{}\",t.0,t,t.1).into_bytes();let l=[*s.last().unwrap(),0];let mut u:Vec<_>=s.windows(2).collect();u.push(&l);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!(\"{}\",c as char);c=rand::sample(&mut r,u.iter().filter(|x|x[0]==c),1)[0][1];}}");let s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();let l=[*s.last().unwrap(),0];let mut u:Vec<_>=s.windows(2).collect();u.push(&l);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!("{}",c as char);c=rand::sample(&mut r,u.iter().filter(|x|x[0]==c),1)[0][1];}}
-- Random numbers are removed from the standard library in Rust,
-- I had to make a cargo project to even compile this...
-- Rust is hardly a golfing language.
extern crate rand;

fn main(){

    -- The quine is fairly simple, we just make a tuple with 
    -- "everything before this tuple" as first element, and
    -- "everything after this tuple" with any quotes escaped 
    -- as second. That makes it really easy to print.
    let t=("[...before...]", "[...after...]");
    
    -- Instead of printing it, we save it as a byte vector
    let s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();
 
    -- We slide a 2 wide window over it to save a vector
    -- of all bigrams. We append (the last character, 0)
    -- as a special bigram to mark the end.
    let l=[*s.last().unwrap(),0];
    let mut u:Vec<_>=s.windows(2).collect();
    u.push(&l);

    -- Start with the first character
    let mut c=s[0];
    let mut r=rand::thread_rng();

    while c!=0 {
        print!("{}",c as char);

        -- Filter the list of bigrams to only those which have the
        -- current character as first. Take one at random, its
         -- second is our next character.
        c=rand::sample(&mut r, u.iter().filter(|x|x[0]==c), 1)[0][1];

        -- Keep at it until the 0 byte is generated.
    }
}

Rust, 564 bytes (not competitive)

extern crate rand;fn main(){let t=("extern crate rand;fn main(){let t=", ";let mut s=format!(\"{}{:?}{}\",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!(\"{}\",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}");let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();s.push(0);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!("{}",c as char);let u=s.windows(2);c=rand::sample(&mut r,u.filter(|x|x[0]==c),1)[0][1];}}
-- Random numbers are removed from the standard library in Rust,
-- I had to make a cargo project to even compile this...
-- Rust is hardly a golfing language.
extern crate rand;

fn main(){

    -- The quine is fairly simple, we just make a tuple with 
    -- "everything before this tuple" as first element, and
    -- "everything after this tuple" with any quotes escaped 
    -- as second. That makes it really easy to print.
    let t=("[...before...]", "[...after...]");
    
    -- Instead of printing it, we save it as a byte vector
    -- and append 0
    let mut s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();
    s.push(0);

    -- Start with the first character
    let mut c=s[0];
    let mut r=rand::thread_rng();
 
    while c!=0 {
        print!("{}",c as char); 

        -- We slide a 2 wide window over it to save a vector
        -- of all bigrams. 
        let u=s.windows(2);

        -- Filter it to only those which have the current character 
        -- as first. Take one at random, its second is our next  
        -- character.
        c=rand::sample(&mut r, u.filter(|x|x[0]==c), 1)[0][1];

        -- Keep at it until the 0 byte is generated.
    }
}
Source Link
user61264
user61264

Rust, 618 bytes (not competitive)

extern crate rand;fn main(){let t=("extern crate rand;fn main(){let t=", ";let s=format!(\"{}{:?}{}\",t.0,t,t.1).into_bytes();let l=[*s.last().unwrap(),0];let mut u:Vec<_>=s.windows(2).collect();u.push(&l);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!(\"{}\",c as char);c=rand::sample(&mut r,u.iter().filter(|x|x[0]==c),1)[0][1];}}");let s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();let l=[*s.last().unwrap(),0];let mut u:Vec<_>=s.windows(2).collect();u.push(&l);let mut r=rand::thread_rng();let mut c=s[0];while c!=0{print!("{}",c as char);c=rand::sample(&mut r,u.iter().filter(|x|x[0]==c),1)[0][1];}}

Since I already had written a pretty neat Rust quine for another question, I thought I'd adapt it for this, since it seemed simple enough. While the original was small, though, for this I have made very little attempt to minimize size. Here's an expanded version to explain what's going on:

-- Random numbers are removed from the standard library in Rust,
-- I had to make a cargo project to even compile this...
-- Rust is hardly a golfing language.
extern crate rand;

fn main(){

    -- The quine is fairly simple, we just make a tuple with 
    -- "everything before this tuple" as first element, and
    -- "everything after this tuple" with any quotes escaped 
    -- as second. That makes it really easy to print.
    let t=("[...before...]", "[...after...]");
    
    -- Instead of printing it, we save it as a byte vector
    let s=format!("{}{:?}{}",t.0,t,t.1).into_bytes();

    -- We slide a 2 wide window over it to save a vector
    -- of all bigrams. We append (the last character, 0)
    -- as a special bigram to mark the end.
    let l=[*s.last().unwrap(),0];
    let mut u:Vec<_>=s.windows(2).collect();
    u.push(&l);

    -- Start with the first character
    let mut c=s[0];
    let mut r=rand::thread_rng();

    while c!=0 {
        print!("{}",c as char);

        -- Filter the list of bigrams to only those which have the
        -- current character as first. Take one at random, its
        -- second is our next character.
        c=rand::sample(&mut r, u.iter().filter(|x|x[0]==c), 1)[0][1];

        -- Keep at it until the 0 byte is generated.
    }
}

Sample output 1:

eran(),0{ller=samarin chas c).pr,teteran mut madoletet manthilaplerng().wind_byt.wit();let.u.0][*s=[*s.plleas.wshit, rnd:Vec<_byte mputextet ut t leat=r,t rant!=r().filllet rng();lar("{}{let.ind_byt.what amusarando_ramut!=st ct!(\").0]=colet!(&lec<_ret.plec=s.whrararandormpr=saile ret=r,0]=r);le(\"),t und;fint.prilt!();ler(2).forap(&ler=s(),t ut rat mu:t=ramund:Ve s.putec==[0];wst and_byt sh(\"et c s[1), munwhras[0];c=s=s="etornws(2)[0, ain(|x|x[0,0,0];fowile c ct(&l=",tes().co_byt().wrmat ash(|x|x[*s.lethrant.wrarmu.file(\"et, r==[1);uterile().0,t ando_rinwhas=[0{}"ect.wilant!("{ple mut, mut mamprmant,0];le(&lec=s.1),t co_>=fin mamustec!(\",c=[0];}}",0];leteteat.ust(",ternwhashrarmut ler("erat,0]==file and_reter==s.utet an letet.ut=", ras.1);fin("{:?}"et t letes[*sado_bytet rnd::Verain s[0];whant(){}{}\"echin s(2);lerad;wst reth(\",t u.iletermat c 1];}{}

Sample output 2:

et!().0][0][0{}