Skip to content

Instantly share code, notes, and snippets.

@harlanhaskins
Created May 13, 2017 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harlanhaskins/1124877c59786a081690bd93fd0e1571 to your computer and use it in GitHub Desktop.
Save harlanhaskins/1124877c59786a081690bd93fd0e1571 to your computer and use it in GitHub Desktop.
use std::env;
fn print_spongebob(vals: &[String]) {
let statement = vals.join(" ");
let mut lower = true;
for c in statement.chars() {
let new_c = if lower { c.to_lowercase().next() }
else { c.to_uppercase().next() };
if let Some(c) = new_c {
print!("{}", c);
}
lower = !lower;
}
print!("\n");
}
fn main() {
let args: Vec<_> = env::args().collect();
if let Some((_, tail)) = args.split_first() {
print_spongebob(tail);
} else {
println!("usage: spongebobify [statement...]")
}
}
@harlanhaskins
Copy link
Author

harlanhaskins commented May 13, 2017

This turns all command line arguments into the Mocking SpongeBob Meme text.

tHiS TuRnS AlL CoMmAnD LiNe aRgUmEnTs iNtO ThE MoCkInG SpOnGeBoB MeMe tExT

@harlanhaskins
Copy link
Author

harlanhaskins commented May 13, 2017

Haskell version:

import Data.Char
import System.Environment
import Data.List

spongebobify s = spongebobify' s True
  where spongebobify' "" _ = ""
        spongebobify' (x:xs) lower = (flipC lower x) : spongebobify' xs (not lower)
        flipC True = toLower
        flipC False = toUpper

main = getArgs >>= putStrLn . spongebobify . intercalate " "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment