Play the "bzzt" game
CJam - 25
501{3sI3%<Is-I"bzzt"?N}fI
Thanks Howard :)
Try it at http://cjam.aditsu.net/
Explanation:
501{…}fI
is basically for(int I=0; I<501; ++I) {…}
3s
converts 3 to string, i.e. "3"
I3%
is I
% 3
<
gets the left substring - "3".substring(0, I % 3)
- which is "" for I
% 3 == 0 and "3" otherwise
Is
converts I
to string
-
with 2 strings does a set difference, resulting in an empty string iff I
% 3 == 0 (the first string was empty) or I
has a 3 digit in it
…I"bzzt"?
is like … ? I : "bzzt"
; the previous string is treated as a boolean value, where "" is false and any other string is true
N
adds a newline
Ruby, 43
501.times{|a|puts"#{a}"[?3]||a%3<1?:Bzzt:a}
Pretty straightforward.
Edit: Saved one byte, thanks Howard!
seq and GNU sed - 42 33 31 30
Works directly in dash, some other shells might need to have history expansion disabled, e.g. with bash set +H
:
seq 500|sed 0~3!{/3/!b}\;cbzzt