Skip to content

Instantly share code, notes, and snippets.

@radarek
Last active August 29, 2017 11:27
Show Gist options
  • Save radarek/011f4bb39f9f35952274 to your computer and use it in GitHub Desktop.
Save radarek/011f4bb39f9f35952274 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
probability = $stdout.tty? ? (ENV["D"] || 10).to_i : 0
puts ARGF.read.chars.map { |c| rand(100) + 1 <= probability && c !~ /\s/ ? " " : c }.join
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
p fib(34)
@ankurp
Copy link

ankurp commented Dec 19, 2014

How does this work. Seems like this line is the reason why it works. I noticed that it outputs to console with whitespace but when it writes to a file it will write without whitespace character probability = $stdout.tty? ? (ENV["D"] || 10).to_i : 0

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