# Winner: Aditsu's CJam answer! A whopping 25 bytes! Nice!

You may continue to submit your answer, however you can no longer win. Original post kept for posterity:

The "Bzzt" game is a game where you must count to a number (in this case 500). However, if the number has a 3 in it, or is divisible by 3, you don't say the number. Instead, you say "Bzzt".

Rules:

• You can't hard-code the numbers.
• The number only has to satisfy at least 1 of the following requirements
• Divisible by 3
• Number contains a 3
• Some type of separator is mandatory (12bzzt14 doesn't count)
• Score is measured in bytes.
• You must count exactly to 500, starting at 1 or 0 (you chose).
• The numbers must be output, but it doesn't matter how (e.g., stdout, writing to a text file, etc.).
• 0 can be divisible by 3 or not divisible. You can choose.
• You can output the numbers one at a time (ex, output 1, then 2, then bzzt, then 4, etc) or all at once (e.g., output 1 2 bzzt 4 5).
• You must replace the letter 3 with the word "bzzt". This is not case sensitive (bZzt, Bzzt, bzzt are all okay).

• This is a challenge, so the shortest code wins.
• This contest ends June 30th 2014 (7 days from posting).
• For purposes of this question, is 0 divisible by 3? – Οurous Jun 23 '14 at 7:07
• Is it "buzz" or "bzzt"? You wrote "buzz" twice so far. – aditsu Jun 23 '14 at 8:40
• Please clarify. Do I have to output buzz or bzzt if both of the requirements apply? Do I have to output 12bzzt4 or bzzt for 1234? – nyuszika7h Jun 23 '14 at 12:41
• I'd say bzzt for 1234. It's a 'common' drinking game here (only we often do it with 7) – Martijn Jun 23 '14 at 13:38
• "0 can be divisible by 3 or not divisible. You can choose." I really don't think you can choose. 0 mod 3 is 0, that's not really a matter of opinion. – David Conrad Jun 23 '14 at 15:54

# jq: 59 bytes

(56 characters code + 3 characters command line option.)

range(501)|select(.%3<1or("\(.)"|test("3"))|not)//"bzzt"


Sample run:

bash-4.3$jq -n -r 'range(501)|select(.%3<1or("\(.)"|test("3"))|not)//"bzzt"' | head bzzt 1 2 bzzt 4 5 bzzt 7 8 bzzt  On-line test (Passing -r through URL is not supported – check Raw Output yourself.) # beeswax, 148 bytes beeswax was created after the challenge, but why shouldn’t I give the challenge a try anyway? ;) Not golfed to death yet, but it satisfies both requirements:  ;pK~gFP{?gp' < < >F B~6-!P~2 .Pfz1~h#>@-"d~9P~:Fd 4 N >@f>F9P~%~3Kdbzztg?Pp *0>F3~%'dbzzt@Pp dN < <  Output: julia> beeswax("bzzt.bswx") bzzt 1 2 bzzt 4 5 bzzt 7 8 bzzt 10 11 bzzt bzzt 14 bzzt 16 ... 29 bzzt bzzt bzzt bzzt bzzt bzzt bzzt bzzt bzzt bzzt 40 41 ... 296 bzzt 298 299 bzzt bzzt bzzt bzzt bzzt bzzt bzzt bzzt bzzt ... bzzt bzzt bzzt bzzt 400 401 bzzt bzzt 404 ... 494 bzzt 496 497 bzzt 499 500 Program finished!  You can clone my beeswax interpreter (written in Julia) from my GitHub repository. ## Groovy, 46 45 bytes {(0..500).collect{x->x%3<1||x=~/3/?'bzzt':x}}  This is an unnamed closure. Try it Online! • I never programmed in Groovy, but if I read it correctly you can save one by byte changing x%3==0 to x%3<1 (this trick can only be used if the result cannot be negative, which is the case in your 0 to 500 loop). – Kevin Cruijssen Jan 20 '17 at 15:05 • @KevinCruijssen Ah ha, thanks for that. – Gurupad Mamadapur Jan 20 '17 at 15:12 # Japt, 21 bytes 501Ç%3«/3/tZ ?Z:"bzzt  Try it online! Almost direct translation of nderscore's JS submission. ### Unpacked & How it works 501oZ{Z%3&&!/3/tZ ?Z:"bzzt 501oZ{ Map range(501) to a function... Z%3&&!/3/tZ If Z is not a multiple of 3 and Z doesn't have digit 3 ?Z Return Z :"bzzt Otherwise, return "bzzt"  • 20 bytes – Shaggy Jun 13 '18 at 16:49 # Brachylog, 23 bytes (posted way after the end of the challenge) 500⟦{{f|}∋3∧"bzzt"|}ᵐẉᵐ  Try it online!  { }ᵐ For every 500⟦ number from 0 to 500, "bzzt" the string "bzzt" ∋3∧ if 3 is an element of {f } the input's factors | or the input itself, | the input if neither condition is satisfied. ẉᵐ Write that all with one line per item.  # Python 3, 56 bytes (Non-Competing) for x in range(501):print([x,'bzzt']['3'[:x%3]in'%s'%x])  Try it online! Shortest I could get it in Python 3. Can't yet comment on the existing Python 3 solution so posting as a separate answer. • Why is this marked non-competing? – pppery Sep 21 at 23:39 # Javascript - 109 97 Compressed: function b(m,c,z){for(i=1;i<=m;i++){if((i+'').indexOf(c)>-1||i%c==0){alert(z);continue}alert(i)}}  Replaced console.log with alert Uncompressed: function bzzt(max, contains, z) { for(i=1;i<=max;i++) { if((i+'').indexOf(contains)>-1||i%contains==0) { console.log(z); continue; } console.log(i); // console.log instead of alert for testing purposes } }  max is the number to count to, contains is the number it contains and is divisible by, z is the message, so 'bzzt' b(500, 3, 'bzzt');  • You know this is about shortest right? The function only makes it longer, and console.log can be replaced with alert. – Martijn Jun 23 '14 at 8:31 • @Martijn Honestly didn't think about alert. And I thought I saw function in the rules. – Spedwards Jun 23 '14 at 8:38 • @Martijn Also, no one would want to run it if it were alerts haha – Spedwards Jun 23 '14 at 8:39 • Haha. You could add comment in the uncompressed //console instead of alert for testingpurposes so people'll get it :) – Martijn Jun 23 '14 at 8:43 ## C 174 int i,j,k;char n[3]; int main(){ while(i++<501){k=0;sprintf(n,"%d",i); for(j=0;j<3;j++){if(n[j]=='3'){k=1;break;}} (i%3==0||k)?puts("Bzzt"):printf("%d\n",i);} return 0;}  • You can save a whole bunch of characters by not returning; not declaring the return type of main; setting k=0 to mean "there's a 3" and writing (i%3&&k):printf(...):puts(...) etc. By the way, you need a newline after "Bzzt". – David Richerby Jun 23 '14 at 22:37 • @David puts put a newline by itself. – edc65 Jun 25 '14 at 11:26 • @edc65 Thanks. That being the case, we can save even more: declare n to have length 4 (necessary anyway to avoid a potential buffer overrun from the sprintf), make the other changes I suggested in my first comment and replace the fifth line of the source with puts((i%3&&k)?n:"Bzzt");} – David Richerby Jun 25 '14 at 14:47 • I implemented my suggestions as a new answer. Also, it's much shorter to use strchr to test for the digit 3 in the string. (Another improvement to the for loop: the break is redundant, because it doesn't matter if the number has more than 3 in it and you set k=1 more than once.) – David Richerby Jun 25 '14 at 16:06 ## JavaScript, 65 OK, longer than others so far, but I've never tried this before and felt compelled to post... a='';for(i=0;i-->-500;)a+=(i%3?i:-3);a.replace(/\d*3\d*/g,'bzzt')  ### Usage: From a node repl paste the code. Output is by returned value ### Output: '-1-2-bzzt-4-5-bzzt-7-8-bzzt-10-11-bzzt-bzzt-14-bzzt-16-17-bzzt-19-20-bzzt-22-bzzt-bzzt-25-26-bzzt-28-29-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-40-41-bzzt-bzzt-44-bzzt-46-47-bzzt-49-50-bzzt-52-bzzt-bzzt-55-56-bzzt-58-59-bzzt-61-62-bzzt-64-65-bzzt-67-68-bzzt-70-71-bzzt-bzzt-74-bzzt-76-77-bzzt-79-80-bzzt-82-bzzt-bzzt-85-86-bzzt-88-89-bzzt-91-92-bzzt-94-95-bzzt-97-98-bzzt-100-101-bzzt-bzzt-104-bzzt-106-107-bzzt-109-110-bzzt-112-bzzt-bzzt-115-116-bzzt-118-119-bzzt-121-122-bzzt-124-125-bzzt-127-128-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-140-bzzt-142-bzzt-bzzt-145-146-bzzt-148-149-bzzt-151-152-bzzt-154-155-bzzt-157-158-bzzt-160-161-bzzt-bzzt-164-bzzt-166-167-bzzt-169-170-bzzt-172-bzzt-bzzt-175-176-bzzt-178-179-bzzt-181-182-bzzt-184-185-bzzt-187-188-bzzt-190-191-bzzt-bzzt-194-bzzt-196-197-bzzt-199-200-bzzt-202-bzzt-bzzt-205-206-bzzt-208-209-bzzt-211-212-bzzt-214-215-bzzt-217-218-bzzt-220-221-bzzt-bzzt-224-bzzt-226-227-bzzt-229-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-241-242-bzzt-244-245-bzzt-247-248-bzzt-250-251-bzzt-bzzt-254-bzzt-256-257-bzzt-259-260-bzzt-262-bzzt-bzzt-265-266-bzzt-268-269-bzzt-271-272-bzzt-274-275-bzzt-277-278-bzzt-280-281-bzzt-bzzt-284-bzzt-286-287-bzzt-289-290-bzzt-292-bzzt-bzzt-295-296-bzzt-298-299-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-400-401-bzzt-bzzt-404-bzzt-406-407-bzzt-409-410-bzzt-412-bzzt-bzzt-415-416-bzzt-418-419-bzzt-421-422-bzzt-424-425-bzzt-427-428-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-bzzt-440-bzzt-442-bzzt-bzzt-445-446-bzzt-448-449-bzzt-451-452-bzzt-454-455-bzzt-457-458-bzzt-460-461-bzzt-bzzt-464-bzzt-466-467-bzzt-469-470-bzzt-472-bzzt-bzzt-475-476-bzzt-478-479-bzzt-481-482-bzzt-484-485-bzzt-487-488-bzzt-490-491-bzzt-bzzt-494-bzzt-496-497-bzzt-499-500'  # Python3, 62 for i in range(501):print('bzzt'if'3'in str(i) or i%3<1 else i)  VB.net (~100c) 1) Function t() For c=0 To 500:t+=If(CStr(c).Contains("3")Or(c Mod 3)=0,"Bzzt",c)+" ":Next End Function Function t()  2) I'd forgotten about Like operator in vb. Function t() For c = 0To 500:t &=If(CStr(c)Like"*3*"Or(c Mod 3)=0,"Bzzt",c)&" ":Next End Function  The result is output as the return value of the function. The numbers must be output, but it doesn't matter how (e.g., stdout, writing to a text file, etc.). # Scala – 62 for(x<-1 to 501)println(if(x%3<1||(x+""toSet 51))"Bzzt"else x)  toSet is a nice shorthand for contains. # Haskell - 73 b n|mod n 3<1||'3'elemshow n="bzzt"|1<2=show n main=print$map b[0..500]


## Racket 80

(for/list([i 501])(if(or(=(modulo i 3)0)(memv #\3(string->list(~a i))))'bzzt i))


# Pyth, 20

V501?N&%N3-3N"bzzt


Explanation:

V501            for N in range(501):
?               _ if _ else _
N              print(N)
&              _ and _
%N3           N mod 3
-3N         Assymetric difference of str(3) and str(N)
"bzzt          "bzzt" (Final " is implicit)


Essentially, the test is the logical and of N%3, which is only 0, and thus interpreted as false iff N is divisible by 3, with

-3N


which is the empty list iff 3 is present in str(N). Setwise minus removes all appearances of characters in the second string from the first string.

If this and returns true, we print N, otherwise we print "bzzt". Having "bzzt" in the else clause saves a character, because there is no need to end-quote the string.

## Clojure - 82 chars

Newbie solution: plain and simple. Golfed:

(dotimes[n 501](if(or(.contains(str n)"3")(= 0(mod n 3)))(println "bzzt")(prn n)))


Ungolfed:

(dotimes [n 501] (if (or (.contains (str n) "3") (= 0 (mod n 3)))
(println "bzzt")
(prn n)))


# Note: This answer is invalid, because Pyth is too new a language.

## Pyth, 20

V501?N&%N3-\3N"bzzt


Explanation:

V501              for N in range(501):
?N                                print(N if
&%N3                                       N % 3 and
-\3N                                      "3" - repr(N)
"bzzt                                    else "bzzt")


Try it here.

(0...500).map{print($0%3<1||"\($0)".utf8.contains(51) ?"bzzt":"\($0)")}  # Swift 3, 62 (0...500).map{print($0%3<1||"\($0)".contains("3") ?"bzzt":$0)}

or

for n in 0...500{print(n%3<1||"\(n)".contains("3") ?"bzzt":n)}

• Are all the spaces required? Or is Swift just weird with them? – Oliver Ni Nov 2 '16 at 5:02
• I believe at least I eliminated all unnecessary ones. – Apollonian Nov 2 '16 at 6:07

### JavaScript, 63characters

Using javascript against itself >:) First ever golf :)

var i=1;while(i++){if(!(i%3))alert('bzzt');if(!(i%500))i=null;}

• i don't think this meets the criteria – Not that Charles Jun 26 '14 at 21:16
• This doesn't meet the criteria. You should output 'bzzt' if a number contains 3 or if it is divisible by 3 (or both), and you should also output the number if it isn't divisible by 3 and if it doesn't contain 3. This only outputs 'bzzt' if it is divisible by 3. – ProgramFOX Jun 27 '14 at 5:57