Advertisement
Guest User

fizzbuzz, bash, 86 characters (cheat)

a guest
Jan 17th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.61 KB | None | 0 0
  1. #!/bin/bash
  2. # 86 characters, minimal spaces.
  3. for i in {1..100};do printf "\n$i\r";(($i%3))||printf Fizz;(($i%5))||printf Buzz;done
  4.  
  5. # loop over the numbers
  6. for i in {1..100};
  7. do
  8.     printf "\n$i\r"; #newline, number, cariage return (back to beginning of line)
  9.     # if devisible by 3, print fizz, this will overwrite the number since we're back at the start of the line.
  10.     # if devisible by 3 (($i%3)) returns 0, which is false, so we use the "or" operator, not "and"
  11.     # use printf here since we don't want a newline and 'echo -n' is longer then printf
  12.     (($i%3))||printf Fizz;
  13.     # same for 5
  14.     (($i%5))||printf Buzz;
  15. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement