Created
May 13, 2017 05:06
-
-
Save harlanhaskins/1124877c59786a081690bd93fd0e1571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...]") | |
} | |
} |
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
This turns all command line arguments into the Mocking SpongeBob Meme text.
tHiS TuRnS AlL CoMmAnD LiNe aRgUmEnTs iNtO ThE MoCkInG SpOnGeBoB MeMe tExT