Play the "bzzt" game

56

9

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).

Jon

Posted 2014-06-23T06:58:08.417

Reputation: 1 505

"whopping" means "exceptionally large or great" - exactly the opposite of this intended meaning! maybe replace with "astounding" or an antonym: "diminutive", "minuscule", or perhaps "whoppingly small" – Claudiu – 2014-12-19T07:09:55.420

You can output the numbers one at a time (ex, output 1, then 2, then bzzt, then 4, etc) or all at once (ex, output 1 2 bzzt 4 5) Do you mean "you can output the number one on each line or all on one line - either way is fine"? – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2014-06-23T07:02:13.910

Yes, that's exactly what I mean. – Jon – 2014-06-23T07:04:54.387

1For purposes of this question, is 0 divisible by 3? – Οurous – 2014-06-23T07:07:07.090

Also, 3 should be printed as a number not as bzzt.. This meets both requirements, contains 3 and divisible by 3. – Teun Pronk – 2014-06-23T07:11:11.037

@Ourous either. – Jon – 2014-06-23T07:12:24.003

@TeunPronk See point two. – Jon – 2014-06-23T07:13:06.180

@Chipperyman you say 30 should be printed right? It seems to say that. if thats the case 3 should be printed too and so does 33 and so on. – Teun Pronk – 2014-06-23T07:14:17.240

@TeunPronk By that I meant that 30 would count as buzz. I edited the question to be more clear. – Jon – 2014-06-23T07:16:03.873

@Chipperyman fair enough. – Teun Pronk – 2014-06-23T07:16:17.520

There's a similar question here.

– grc – 2014-06-23T08:01:46.993

Similar but not a dupe. – Jon – 2014-06-23T08:10:38.480

Is a seperator required or is 12bzzt4 ok? – Martijn – 2014-06-23T08:34:24.047

2Is it "buzz" or "bzzt"? You wrote "buzz" twice so far. – aditsu quit because SE is EVIL – 2014-06-23T08:40:37.627

General question for CG, I've got an answer in two languages, do I make two posts or combine them in 1? – Martijn – 2014-06-23T08:42:15.687

@Martijn Two posts, unless they're very similar answers. – grc – 2014-06-23T08:51:19.343

They are very similar, same logic, but language specific functions. – Martijn – 2014-06-23T08:55:26.253

3Please 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 – 2014-06-23T12:41:45.717

4I'd say bzzt for 1234. It's a 'common' drinking game here (only we often do it with 7) – Martijn – 2014-06-23T13:38:33.327

@Martijn 3 is more drinking :) – Cruncher – 2014-06-23T14:41:11.210

66"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 – 2014-06-23T15:54:06.000

Rule 2 seems to suggest that we only have to check one of the cases. Please clarify. – nyuszika7h – 2014-06-25T15:51:38.923

@nyuszika7h That is correct. – Jon – 2014-06-25T19:19:24.537

@Chipperyman Thanks, that means many of us can make our solutions shorter. – nyuszika7h – 2014-06-25T19:20:08.247

1@nyuszika7h Wait I think I misunderstood you. Each number only needs to meet one requirement. You have to check both – Jon – 2014-06-25T19:20:50.483

@Chipperyman Ah, that's what I thought. – nyuszika7h – 2014-06-25T19:21:38.350

I like this level of games. Not to easy, not to mathematical :) – Martijn – 2014-06-26T07:06:56.050

@Chipperyman: I think it is clearer to say that it is sufficient to produce one 'bzzt' even if both requirements are met. – sigma – 2014-06-26T11:55:05.787

1@Chipperyman Clarification required of last requirement 313 should the output be Bzzt or Bzzt1Bzzt ? – Adam Speight – 2014-06-26T13:41:51.577

@AdamSpeight Bzzt is what all the other answers have. – Οurous – 2014-06-26T21:28:39.670

@nyuszika7h You shouldn't output either 12bzzt4 or bzzt for 1234, because you should have stopped at 500. – Chris Cudmore – 2014-06-26T21:52:10.330

@ChrisCudmore That was just an example, duh. – nyuszika7h – 2014-06-26T21:52:52.100

1The question has a bug too. "Some type of separator is mandatory (12bzzt14 doesn't count)" The output there should have been bzzt bzzt 14. – Paul – 2014-06-27T22:03:22.800

I thought "Can't hardcode the numbers" implied you can't use the number 3 in the code. What did I miss? – Henk Langeveld – 2014-06-29T09:17:58.273

Means you can't make a table of { "3", "6", "9", "12", "13" }, etc. – Jon – 2014-06-29T17:35:22.780

Also, my code (...)*100000. Is there any problem with that? According to the logs, this doesn't work. Why? – proud haskeller – 2014-08-23T19:46:11.403

Answers

33

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

aditsu quit because SE is EVIL

Posted 2014-06-23T06:58:08.417

Reputation: 22 326

You can use the same trick as in my golfscript solution and save the logical and: 501{3sI3%<Is-I"bzzt"?N}fI. – Howard – 2014-06-23T10:29:51.630

29

Ruby, 43

501.times{|a|puts"#{a}"[?3]||a%3<1?:Bzzt:a}

Pretty straightforward.

Edit: Saved one byte, thanks Howard!

Ventero

Posted 2014-06-23T06:58:08.417

Reputation: 9 842

1You can save a single whitespace if you write "#{a}"[?3]||a%3<1. – Howard – 2014-06-23T09:52:51.317

@Howard: Indeed, thanks a lot! – Ventero – 2014-06-23T10:07:48.797

1Even more unreadable but unfortunately same length: "#{a}"[?3[0,a%3]]. – Howard – 2014-06-23T10:19:13.973

What about replacing puts with p and saving 3 chars ? – David Unric – 2014-06-26T22:03:56.280

1@DavidUnric p prints the result of calling inspect on its argument (compared to puts, which calls to_s). So instead of printing Bzzt (which is :Bzzt.to_s), it would print :Bzzt, which doesn't match the output specifications. – Ventero – 2014-06-26T22:14:37.993

Yep, got it. Just guessed it won't mind to display symbol instead of string. – David Unric – 2014-06-26T22:29:03.280

25

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

Thor

Posted 2014-06-23T06:58:08.417

Reputation: 2 526

How does it work? – nbubis – 2014-06-25T05:27:30.580

History expansion is disabled by default in shell scripts. – nyuszika7h – 2014-06-25T16:14:38.420

@nyuszika7h: true, but I expect many will try the answer in an interactive shell. – Thor – 2014-06-25T21:47:20.743

1@nbubis: the updated version works by generating the sequence with seq. 0~3! runs {/3/!b} and together these expressions leave the line as is if it is not divisible by and does not contain a 3. The last bit "corrects" the line to bzzt. – Thor – 2014-06-27T06:23:27.150

18

x86 machine code on DOS (.com file) - 71 bytes

00000000  31 c9 68 20 24 89 e5 89  c8 bb 03 00 31 d2 f7 f3  |1.h $.......1...|
00000010  85 d2 74 1a 89 c8 b3 0a  31 d2 f7 f3 80 fa 03 74  |..t.....1......t|
00000020  0d 80 c2 30 86 d6 52 44  85 c0 75 ea eb 08 89 ec  |...0..RD..u.....|
00000030  68 7a 74 68 62 7a 89 e2  b4 09 cd 21 89 ec 41 81  |hzthbz.....!..A.|
00000040  f9 f4 01 7e c2 59 c3                              |...~.Y.|

Prints the required output to stdout with space as a delimiter; can be run without problems in DosBox.

Commented assembly:

    org 100h

start:
    ; 0 - 500 counter
    xor cx,cx
    ; we'll use the stack as scratch space to build the strings to print
    ; first of all, push ' $' on the stack (in reverse order); this will be
    ; the end of each string we'll print
    push 2420h
    ; save the stack pointer, to get back to this position after each print
    mov bp,sp
mainloop:
    ; first try to divide by three
    mov ax,cx
    mov bx,3
    xor dx,dx
    div bx
    test dx,dx
    ; no remainder => bzzt
    jz bzzt
    ; otherwise, go into the decimal-print loop
    mov ax,cx
divloop:
    ; bh is already at zero due to the mov bx,3 above
    mov bl,10
    xor dx,dx
    ; divide by 10
    div bx
    ; remainder is 3 => bzzt
    cmp dl,3
    je bzzt
    ; convert number to digit
    add dl,'0'
    ; trick: we move the digit to the upper byte of dx: this allows us to
    ; push the whole dx (you cannot do push dl) but to easily kill the
    ; undesidered byte by touching the stack pointer (it will be overwritten
    ; by the next stack operation/ignored by the print)
    xchg dl,dh
    push dx
    inc sp
    ; check is there anything left to print, rinse & repeat
    test ax,ax
    jnz divloop
    ; skip straight to print
    jmp print
bzzt:
    ; since we may be here from inside divloop, reset the stack pointer to
    ; where we left ' $'
    mov sp,bp
    ; push 'bzzt'
    push 747ah
    push 7a62h
print:
    ; print what is on the stack
    mov dx,sp
    mov ah,9h
    int 21h
    ; move us back to ' $'
    mov sp,bp

    ; increment cx and repeat while we are <=500
    inc cx
    cmp cx,500
    jle mainloop
end:
    ; fix back the stack pointer to the original value (=kill the first push)
    pop cx
    ; quit
    ret

Matteo Italia

Posted 2014-06-23T06:58:08.417

Reputation: 3 669

5RESPECT!!!!! Amazing! – yossico – 2014-06-25T18:33:37.903

@yossico: thank you! :) actually, it's nothing really special, I'm sure that people who actually wrote assembly for DOS could surely shave some more bytes off. – Matteo Italia – 2014-06-25T22:47:21.353

17

Perl - 35 40 42

print$_*!/3/%3?$_:bzzt,$/for 1..500

core1024

Posted 2014-06-23T06:58:08.417

Reputation: 1 811

17

PHP, no separator - 62, 61,59,58,52,49 47

It doesn't say there should be a space/newline/separator between them, without:

while(++$i<501)echo$i%3*!strpbrk($i,3)?$i:bzzt;

With the separator, 68,67,65,64,58/55,53/52 51/50

while(++$i<501)echo$i%3*!strpbrk($i,3)?$i:bzzt,' '; // 51
while(++$i<501)echo$i%3*!strpbrk($i,3)?$i:bzzt,~õ; // 50
  • Just found a small 'cheat', don't need a space after echo, saved me a bit.
  • The creates a newline
  • Another small 'cheat', the bzzt doesn't need quotes (tested it). Not the way to go, but it works.

Javascript - 54,51 50

Same principle, but javascript functions:

for(i=0;i++<500;)alert(i%3<1|/3/.test(i)?'bzzt':i)

Martijn

Posted 2014-06-23T06:58:08.417

Reputation: 713

1You can replace !strpbrk($1,3) with trim(3,$i) to save 4 bytes – aross – 2016-04-11T09:13:27.663

Save two bytes on the delimiter version with underscore or any letter as delimiter (needs no parentheses). – Titus – 2016-10-30T09:40:54.597

Rules state that Some type of separator is mandatory. – Titus – 2016-10-30T09:42:19.537

Any separator will do; so _ instead of should be fine. – Titus – 2019-03-05T15:26:44.170

Thanks@core for the brackets and for() tip. The for made me crash my browser a few times ^^ – Martijn – 2014-06-23T08:53:49.690

Haha. I tested it with console.log() obviously, but this is shorter. – Martijn – 2014-06-23T08:56:11.280

1Your Javascript solution counts to 501. – nderscore – 2014-06-23T15:22:17.980

Indeed it did. The ++ is after the variable, the php one hs it in front :) – Martijn – 2014-06-24T07:04:39.790

change the 501 to 500 and your JS is golden – Eric Lagergren – 2014-06-24T08:01:36.540

1PHP for 52: <?for(;500>$i++;)echo$i%3*!strpbrk($i,3)?$i:bzzt,~õ; The õ is char 245, a bit-inverted \n. – primo – 2014-06-24T08:10:10.513

The for didn't make a difference lengthwise, but the strpbrk did (had to look it up). Not 100% sure how this works now, don't have the time atm to check some things. I've added the as a 'seperate' entry, did took the comma trick for adding a space, thanks :)_ – Martijn – 2014-06-24T09:29:49.690

strpbrk has the advantage over strpos that it can never return 0 as a 'found' value (at least, when searching for a 3). Also, the quotes around bzzt aren't strictly necessary, if E_NOTICE is disabled/ignored (for the purposes of codegolf, I think this can be assumed). However, I do feel that the opening tag <? should be counted. There is no setting or option which allows a script to be run without it - it's as manditory as a main declaration in C. – primo – 2014-06-24T11:15:32.750

Tested the qoutes, don't need them. Not the way to go and I would never do this in a real situation, but... it saved 2 bytes. IMO the <?= should not be counted. That means javascript would need <script> and also, other phpcodes on this site (often) don't do this :) Thanks for the tips – Martijn – 2014-06-24T13:24:02.287

I may not be the most prolific PHP golfer on the site, but I'm certainly one of them - I don't think there's many users who have submitted more than 56 answers in PHP. As a matter of precedent, I have never once not included the opening tag, unless the question specifically asked for a function, simply because the code will not run without it. <script> is of course HTML, and not Javascript. Including it would cause any stand-alone interpreter to choke - quite the opposite situation from PHP's opening tag.

– primo – 2014-06-24T14:14:28.680

for(i=0;i++<500;)alert(i%3<1|/3/.test(i)?'bzzt':i) for 50 characters... Bitwise Or | works just as well as a Logical Or || in this case... – WallyWest – 2014-06-25T11:33:18.683

Thanks, implemented it. I love joining these contest, a lot food for thinking and research :) – Martijn – 2014-06-25T11:35:14.613

Please submit the JavaScript solution as a separate answer. – nyuszika7h – 2014-06-25T16:15:58.587

At this point that would be unfair because there might be upvotes for both the JS and the PHP. This was my first real answer, next time I'm gonna split it in two :) – Martijn – 2014-06-25T16:48:37.070

why the <1? whats wring wit 0? – Math chiller – 2014-06-26T13:04:51.190

Because I want it to be 0. If I test if it is zero: ==0 which is 3 chars. If I test <1 which does the same, its 1 char shorter. In real life I would've choosen the ===0 for readability, but when golfing, you go for the shortest option :) – Martijn – 2014-06-26T13:16:37.897

16

Javascript 50 49

-1 byte thanks to core1024

for(i=0;i++<500;)alert(i%3*!/3/.test(i)?i:'bzzt')

nderscore

Posted 2014-06-23T06:58:08.417

Reputation: 4 912

I knew that could be done! But didn't find how – edc65 – 2014-06-23T15:34:26.607

1You can imagine my face when a JavaScript solution beats my LiveScript one. – nyuszika7h – 2014-06-23T19:55:33.987

in yout second solution you could remove one & sign and it will still work – user902383 – 2014-06-24T08:56:28.837

@user902383 It's not a valid result without a boolean && operator. For example: 497 % 3 = 2 => 2 & true = 0 => bzzt – nderscore – 2014-06-24T12:19:33.780

for(i=0;++i<501;)alert(!/3/.test(i)*i%3?i:'bzzt') - 49 :P – core1024 – 2014-06-25T14:46:15.123

@core1024 nice catch! – nderscore – 2014-06-25T15:14:15.650

11

GolfScript, 30 29 characters

501,{:^`3`^3%<?)'bzzt'^if n}/

Not so straightforward implementation in GolfScript, can be tested here.

Howard

Posted 2014-06-23T06:58:08.417

Reputation: 23 109

10

Perl, 36

print$_%3&&!/3/?$_:Bzzt,$/for 1..500

Edit: I'm not a Perl monk, so core1024 seems to have managed to golf another byte out of this in his answer.

Ventero

Posted 2014-06-23T06:58:08.417

Reputation: 9 842

1Use say to save 4 bytes: say$_%3&&!/3/?$_:bzzt for 1..5e2 – Zaid – 2014-06-23T14:30:05.680

@Zaid why 5e2 and not 500? – Not that Charles – 2014-06-23T20:08:28.290

@Charles: they are equivalent – Zaid – 2014-06-24T01:27:07.217

1@Zaid so why not be clearer? – Not that Charles – 2014-06-24T03:12:14.283

4@Charles : In the context of a code-golf challenge, should one even care? – Zaid – 2014-06-24T09:26:21.073

@Zaid If one could have the same length with better legibility, why wouldn't one go for the better legibility? – ɐɔıʇǝɥʇuʎs – 2014-06-26T07:14:38.647

10

C# (71)

Can be directly executed in LinqPad.

for(var i=0;++i<501;)(i%3<1|(i+"").Contains("3")?"buzz":i+"").Dump();

EvilFonti

Posted 2014-06-23T06:58:08.417

Reputation: 301

1You can save a char by using bitwise-or (|) instead of logical-or. – Johnbot – 2014-06-24T09:23:34.923

@Johnbot Thanks for your suggestion. – EvilFonti – 2014-06-24T10:58:07.763

You can remove the parentheses around the conditional too. – Johnbot – 2014-06-24T11:09:16.003

@Johnbot: That's not bitwise-or. It's (non-short-circuiting) logical-or, since the operands are boolean. – Ryan M – 2014-06-26T21:43:38.163

Dump is just LinqPad though, correct? Doing this in C# as an application would require an extension method to be added. (And it's 'bzzt' not 'buzz' =) ) – Paul – 2014-06-27T21:14:28.257

And I must add - the ++i<501 in the loop is genius. I would not have thought of it. – Paul – 2014-06-27T21:28:41.483

9

Python (52)

Thanks grc!

for i in range(501):print[i,'Bzzt'][i%3<1or'3'in`i`]

Old version:

print['Bzzt'if'3'in`i`or i%3<1 else`i`for i in range(501)]

ɐɔıʇǝɥʇuʎs

Posted 2014-06-23T06:58:08.417

Reputation: 4 449

1A little shorter: for i in range(501):print[i,'Bzzt'][i%3<1or'3'in\i`]` – grc – 2014-06-23T08:00:06.383

4One char shorter: ['3'[:i%3]in\i`]` – xnor – 2014-06-23T23:25:44.723

7

Haskell: 88 82 80 79

main=mapM_ f[1..500]
f n|n`mod`3<1||'3'`elem`show n=putStrLn"bzzt"
f n=print n

Taylor Fausak

Posted 2014-06-23T06:58:08.417

Reputation: 761

If i were writing an answer i would ditch IO and return a string value. – proud haskeller – 2014-08-23T10:35:13.903

1You should also switch==0 with <1 – proud haskeller – 2014-08-23T10:36:45.833

Also, try making elem prefix. I think you should be able to write elem'3'$show n, which is a char shorter. Or not. I didn't check. – proud haskeller – 2014-08-23T10:38:50.950

@proudhaskeller: The spec states that the "numbers must be output", so IO has to be involved. And using elem in prefix notation doesn't save any characters because there has to be a space before the apostrophe; otherwise you'll get Not in scope: elem'3'. Good eye with <1, though! – Taylor Fausak – 2014-08-23T14:55:14.300

6

Cobra - 70

class P
    def main
        for i in 501,print if('3'in'[i]'or i%3<1,'Bzzt',i)

Batch - 222

Because I genuinely love this language... for some reason...

SETLOCAL ENABLEDELAYEDEXPANSION
for /l %%n in (1,1,500) do (
    set a=%%n&set /ai=!a!%%3
    if "!a:~0,1!"=="3" set a=Bzzt
    if "!a:~1,2!"=="3" set a=Bzzt
    if "!a:~2,3!"=="3" set a=Bzzt
    if !i!==0 set a=Bzzt
    echo !a!>>x)

Οurous

Posted 2014-06-23T06:58:08.417

Reputation: 7 916

You should be able to drop the quotation marks around the operands in the first if because you know that there is at least one digit. Also concatenating the complete block within the for with & might work to save the parentheses. – Joey – 2014-06-23T09:13:29.473

Furthermore, you can use == instead of EQU and probably drop a few spaces here and there. – Joey – 2014-06-23T09:14:21.750

@Joey Thanks for the suggestions! – Οurous – 2014-06-23T09:42:54.503

6

JavaScript 66 63 60

for(a=i=[];i<500;)a[i++]=i%3&&!/3/.test(i)?i:'bzzt';alert(a)

Thanks to edc65 for the suggestion to use array. The output will now be comma-separated.


Old versions

Version 1a - 66

Print from 1 to 500 in an alert box according to the rule. The output is space-separated.

a="";for(i=1;i<501;i++)a+=i%3&&!/3/.test(i)?i+" ":"bzzt ";alert(a)

Version 1b - 65

If we consider 0 to be not divisible by 3, we can shorten the solution to 65 character:

a=0;for(i=1;i<501;i++)a+=i%3&&!/3/.test(i)?" "+i:" bzzt";alert(a)

Version 2 - 63

for(a=i="";i<501;)a+=++i%3&&!/3/.test(i)?i+" ":"bzzt ";alert(a)

Thanks to grc for the suggestion to reduce the length.

n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

Posted 2014-06-23T06:58:08.417

Reputation: 5 683

1I think you could start with for(a=i="";i<500;)a+=++i ... – grc – 2014-06-23T08:21:22.103

I comma separeted output is OK, an array will be shorter: for(o=i=[];i<500;)o[i++]=i%3&&!/3/.test(i)?i:'bzzt';alert(o) – edc65 – 2014-06-23T08:51:37.090

6

PowerShell, 42

1..500|%{($_,'bzzt')[$_-match3-or!($_%3)]}

Mostly Ventero's work, with a little help on syntax by me ;-)

Joey

Posted 2014-06-23T06:58:08.417

Reputation: 12 260

6

R, 49 characters

a=1:500;b='bzzt';a[!a%%3]=b;a[grep(3,a)]=b;cat(a)

Explained:

a=1:500 #Creates a vector with all integers from 1 to 500
b='bzzt'
a[!a%%3]=b #Replace all multiples of 3 by 'bzzt', thus coercing all other integers to character strings
a[grep(3,a)]=b #Replaces the character strings containing 3 by 'bzzt'
cat(a) #Print to stdout

Usage:

> a=1:500;b='bzzt';a[!a%%3]=b;a[grep(3,a)]=b;cat(a)
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

plannapus

Posted 2014-06-23T06:58:08.417

Reputation: 8 610

6

TI-BASIC - 31 (32)(34)(35)(36)(43)

:While X<500
:X+1→X
:If not(fPart(X/3
:"bzzt
:Disp Ans
:End

Total: 25 + 6 lines = 31

Note that most commands on TI-BASIC are represented as single-byte entities.

The code requires X to be initialized to 0 beforehand (otherwise, it's an extra 3 bytes).

I've made several attempts to shave several bytes, so I'm not detailing everything I've done here, as to not clutter the post. They have mostly been directed at shortening the loop, which I've done in this version by a While loop and by shortening the If condition with the help of the Ans variable.

Doktoro Reichard

Posted 2014-06-23T06:58:08.417

Reputation: 419

1You miscounted the bytes here because lowercase letters are two-byte tokens. I agree with Thor's interpretation of the rules as it is the one that every answer above this uses. – lirtosiast – 2015-06-07T02:11:47.693

Correct me if I am wrong, but this does not seem to bzzt numbers containing 3's, e.g. 13. – Thor – 2014-06-24T10:37:33.037

@Thor You are correct, but I'm within the rules, as they state that I may print bzzt for only the numbers that are divisible by 3. Adding the other way could be possible, but would need more instructions. – Doktoro Reichard – 2014-06-24T13:59:16.407

1The rules say: if the number has a 3 in it, or is divisible by 3, you don't say the number. Instead, you say "Bzzt", so I would say both should be replaced. – Thor – 2014-06-24T15:07:44.843

@Thor What bothers me now most is that teeny tiny comma in the middle of the sentence. The way I've interpreted it, both ways of doing are equally valid, which also explains the 2nd rule: The number only has to satisfy 1 of the requirements... (either have a 3 or be divisible by 3) – Doktoro Reichard – 2014-06-24T15:26:41.097

5

groovy - 51

500.times{println"$it".find('3')||it%3<1?'bzzt':it}

edit: using times the printing version is now as short as the "displaying". thanks @will-p

cfrick

Posted 2014-06-23T06:58:08.417

Reputation: 313

1+1. You can swap (1..500).each for 500.times – Will Lp – 2014-06-27T17:20:17.157

5

C, 93

Just for the hell of it...

main(i){char s[9]="bzzt";while(i<498+sprintf(s+5,"%d",i))puts(s+5*(i++%3&&!strchr(s+5,51)));}

r3mainer

Posted 2014-06-23T06:58:08.417

Reputation: 19 135

This has a small glitch - it skips the output for i = 0 – anatolyg – 2014-06-23T17:27:05.783

4@anatolyg "You must count exactly to 500, starting at 1 or 0 (you chose)." — I chose to start from 1. – r3mainer – 2014-06-23T17:45:46.147

Missed that bit. Sorry! – anatolyg – 2014-06-23T18:31:33.970

Skips a lot more if you pass it arguments, lol. But, it is well golfed, I'll give you that! Right down to using the return value of sprintf as you trend towards the three digit numbers to control the while, lol. So bad....haha! – DreamWarrior – 2014-06-24T22:33:43.657

5

Julia 64 bytes

map(x->x%3==0||contains(string(x),"3")?"Bzzt":string(x),[1:500])

bakerg

Posted 2014-06-23T06:58:08.417

Reputation: 81

2[println(a%3==0||3 in digits(a)?"bzzt":a) for a=1:500] is 54 bytes. Also returning an array doesn't print the entire array, so I'm not sure if it counts as being "output". If returning an array counts then [a%3==0||3 in digits(a)?"bzzt":a for a=1:500] might count and score 45. – gggg – 2014-06-25T19:45:41.590

5

cmd.exe - 91

for /l %x in (1,1,500)do @set/a %x%3|find "0">nul&&echo bzzt||echo %x|find/v"3"||echo bzzt

...because why use a batch file when a perfectly straightforward one-liner exists...:-)

Mark

Posted 2014-06-23T06:58:08.417

Reputation: 351

4

Mathematica, 54 Characters

This feels too straightforward. Shorter solutions must be possible.

If[DigitCount[#][[3]] > 0 || #~Mod~3 < 1, Bzzt, #] & /@ Range@500

Michael Stern

Posted 2014-06-23T06:58:08.417

Reputation: 3 029

You don't need the apostrophes :) – Dr. belisarius – 2014-06-24T00:59:52.683

@belisarius indeed. Thanks. – Michael Stern – 2014-06-24T01:20:27.843

4

T-SQL 2008 - 80

Not going to win or anything but fun none the less: Tweaked thanks to @domager:

declare @ int=0t:if(@)like'%3%'or @%3=0print'bzzt'print @;set @+=1if @<501goto t

A little known fact, @ is a valid name for a variable. It feels weird as the set based code is the more SQL variant, but shorter is shorter! This version works on any database. Edit: I was able to remove two of the semis as they were not needed. I'm pretty sure this is as optimal as it gets.

Edit2: Never say never. Here it's now even grosser using goto, but it allows us to avoid the block. We can Replace while,begin,end with the shorter if,t:,goto saving 6 characters. We also rearrange statement by rewriting the loop as a pseudo do-while,semantically equivalent. Edit3: Yeah, somehow if is now shorter. Original:

select top 501iif(number like'%3%'or number%3=0,'bzzt',str(number))from spt_values where'p'=type

Must be run on the master database. I love T-SQL despite its noisy and ugly ways. There might be a way to make this simpler, but unfortunately, the iif built-in requires both sides agree on types. Sql servers precedence rules give int higher precedence than strings. Number is also really long, but aliasing is more characters than it is worth. There might be a better way to turn number in to a string. Edit: str works too. 2 less characters than ltrim

Michael B

Posted 2014-06-23T06:58:08.417

Reputation: 1 551

Hi, your script returns values with 3 regardless. Seems you are missing an else or need to use IIF. This can be golfed to 82 bytes.

– t-clausen.dk – 2019-04-04T12:14:55.623

At first I thought your code is 2012.96 bytes long. – nyuszika7h – 2014-06-23T16:25:24.047

slightly longer in @ 101, but doesn't rely on a table declare @i int=1;while(@i<501)begin;if(@i)like'%3%'or @i%3=0 print'bzzt'else print @i;set @i=@i+1 end – domager – 2014-06-23T16:29:59.953

@domager, totally right, plus we can save quite a few characters by switching the variable to @. Then using iif() is still shorter than an if(...)print else print so we gain quite a bit by using the iif expression. Also we can use the shorter @+=1 to save a char – Michael B – 2014-06-23T17:13:23.697

I didn't know T-SQL supported +=. I don't have it handy to test, but I'm pretty sure it supports ''+@ for string conversion using the invariant locale. – Peter Taylor – 2014-06-23T22:00:12.447

+= was added in 2008. It does support ''+@, but it doesn't do what you want. As I said, precedence rules cast to int first so it casts '' to int, resulting in zero so ''+@ is @ still typed as an int.str works and it isn't that much more expensive than anything else (2 extra chars for the parens). I chose t-sql 2012 here because of the IIF operator, who knows maybe 2016's release sql will get rid of some of the noise and start being competitive (unlikely). – Michael B – 2014-06-24T12:56:40.793

4

C, 80

Using spaces as separators instead of line breaks.

n;main(){for(;n++<500;)printf(n%10^3&&n/10%10^3&&n/100^3&&n%3?"%d ":"bzzt ",n);}

anatolyg

Posted 2014-06-23T06:58:08.417

Reputation: 10 719

1 bzzt 3 4 bzzt 6 7 bzzt 9 10 bzzt bzzt 13 bzzt ... There's something wrong here. – r3mainer – 2014-06-23T19:05:59.707

It seems I was too greedy, and stumbled into Undefined Behavior (variable modified and read between sequence points). Now fixed. – anatolyg – 2014-06-23T19:20:04.740

Working now :-) – r3mainer – 2014-06-23T22:18:07.747

4

VBA: 54

for x=0to 500:?iif(x/3=x\3=instr(1,x,3),x,"Bzzt"):next

Open up your favorite Office program, hit alt+F11 to open the VBA IDE and paste the code into the immediate pane and press enter.

In VBA, : is the line separator, ? is shorthand for print, iif means inline if (think x?"Y":"N"), x/3 does floating point division and x\3 does integer division, instr returns the position of a char in a string, or 0 otherwise, true=-1 and false=0.

The code basically increments x and outputs x if x/3=x\3=instr(1,x,3) is true and "Bzzt" otherwise. x/3=x\3 compares (float)(x/3) to (int)(x/3) and returns a boolean (0 is false and -1 is true). instr(1,x,3) returns 0 if "3" is not in the number, and a positive integer otherwise. The only time the expression returns true is when (x/3=x\3) is false (0) and instr(1,x,3) is 0, or in other words, when x is not divisible by 3 and does not contain the digit "3", which is exactly what we are looking for.

JesterBLUE

Posted 2014-06-23T06:58:08.417

Reputation: 696

4

k4 (37) (35)

{$(x;`bzzt)(|/51=$x)|~"."in$x%3}'!501

k4 lacks a built-in modulo command, and using the q one would take an extra character; this version (ab)uses the built-in output format to check if the string of the result of dividing x by 3 has a decimal point in it.

EDIT:

{$(x;`bzzt)(|/51=$x)|x=3*_x%3}'!501

Clever as matching the decimal point may be, I can shave two bytes by checking that 3*floor x%3 is still x.

Aaron Davies

Posted 2014-06-23T06:58:08.417

Reputation: 881

Please don't update all of your answers at ones. That will push all the active challenges off the front page. It would be nice if you only did one or two a time. (Although I don't even think changing between h1 and h2 is important enough to warrant an edit in the first place.) – Martin Ender – 2014-12-18T20:02:21.923

Upvoted for cleverly matching the decimal point! – Mark – 2014-07-01T20:23:15.230

3

Bash, 53 52 48 46

seq 500|factor|sed '/3.*:\| 3 */cBzzt
s/:.*//'

Requires GNU sed (uses the c extension).

user16402

Posted 2014-06-23T06:58:08.417

Reputation:

3

Java, 142 131 thank to WozzeC suggestion

public class a{public static void main(String[]a){for(int i=1;i<501;i++)System.out.println(i%3>0&(""+i).indexOf(51)<0?i:"bzzt");}}

user902383

Posted 2014-06-23T06:58:08.417

Reputation: 1 360

this is 122 bytes, 9 less: class A{public static void main(String[]a){for(int i=0;++i<501;System.out.println(i%3>0&(""+i).indexOf(51)<0?i:"bzzt"));}} – Luigi Cortese – 2015-07-25T20:35:34.367

1My Java is a bit rusty. But wont it be shorter with an and operand? i%3>0&&(""+i).indexOf(51)<0?i:"bzzt" . It might also be possible to skip the { } for the forloop. – WozzeC – 2014-06-23T14:29:49.380

3

R (40) (36)

This is basically plannapus answer a little bit shortened, but I can not comment yet

Update: -4 characters (see plannapus's comment)

a=1:500;a[grepl(3,a)|!a%%3]='bzzt';a

Output:

  [1] "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"

Rift

Posted 2014-06-23T06:58:08.417

Reputation: 91

Since many string operation functions (such as strsplit) throw error when fed with non-characters I assumed grepl did as well. Nice catch! +1 – plannapus – 2014-06-26T07:43:58.190

2By the way since you reduced it to one expression you don't need to define b prior to that: a=1:500;a[grepl(3,a)|!a%%3]='bzzt';a – plannapus – 2014-06-26T07:45:17.733

3

Fortran - 118 114 111

A hopelessly unlikely candidate, though originally developed to fit on punch cards. Using all the obscure constructs from the past, some short code may still be written:

do3 i=1,500
j=i
if(mod(i,3))2,1,2
1 print*,'bzzt'
cycle
2 goto(1)mod(j,10)-2
j=j/10
if(j>0)goto2
3 print*,i
end

The "computed goto" goto(L1,L2,...,Ln) x branches to one of the labels L if and only if 1 <= x <= n.

Edit: Managed to shave off 4 bytes by rearranging the loop that checks for the digit 3. As a bonus, the code now also contains the arithmetic if-statement if(x) a,b,c, which always branches to one of three labels: a if x < 0, b if x == 0 or c if x > 0.

Unfortunately, the first two versions did not produce the correct output. The digit-3 loop now works correctly, and the code now also includes a modern logical if-statement. Three more bytes are gone, because who needs an enddo statement? The output may be verified here.

sigma

Posted 2014-06-23T06:58:08.417

Reputation: 201

3

Scala, 70

Code

1 to 500 map(x=>if(x%3<1||(""+x).contains(51))"bzzt"else x)map println

Usage

scala -e '1 to 500 map(x=>if(x%3<1||(""+x).contains(51))"bzzt"else x)map println'

Demo

http://ideone.com/KfcO1M

Explanations

  • 1 to 500: produces values from 0 to 500
  • map: function which takes iterable argument at the left, and applies the function given at the right
  • x=>...: lambda expression
  • if(condition) value_if_condition_is_true else value_if_condition_is_false: returns a value (functional behavior) which can be either a java.lang.String or a scala.Int. The expression type is scala.Any in this case, because this is the lower type the two types can coerce to (see the Scala Class Hierarchy)
  • map println: takes each object (java.lang.String or scala.Int) and prints it with line feeds

Joseph C.

Posted 2014-06-23T06:58:08.417

Reputation: 31

3

Swift - 74

for i in 0..501 {println(i%3<1||"\(i)".rangeOfString("3") ?"bzzt":"\(i)")}

user26668

Posted 2014-06-23T06:58:08.417

Reputation: 41

3

05AB1E, 26 23 21 bytes (non-competing)

501FND3ÖN3å~i"bzzt"},

Try it online!

Geno Racklin Asher

Posted 2014-06-23T06:58:08.417

Reputation: 466

k®› could be replaced with å. – Emigna – 2016-11-03T11:11:20.747

I know it's been a while, but it can be 19 bytes now with ₄;END3ÖN3å~i.•è‰•}, or ₄;LεD3Öy3å~i.•è‰•]».

– Kevin Cruijssen – 2019-03-05T13:56:15.043

2

MathGolf, 19 18 bytes

♪½{î3╧î3÷+î╕▄┴_ߧp

Try it online!

Explanation

♪                     push 1000
 ½                    divide by 2, making 500
  {                   start for loop
   î                  index of current loop (1-based)
    3                 push 3
     ╧                pop a, b, a.contains(b)
      î               index of current loop (1-based)
       3              push 3
        ÷             is divisible
         +            pop a, b : push(a+b)
          î           index of current loop (1-based)
           ╕▄┴        decompress "bzzt"
              _       duplicate TOS
               ß      wrap last three elements in array (makes [<index>, "bzzt", "bzzt"])
                §     get from array
                 p    print with newline

maxb

Posted 2014-06-23T06:58:08.417

Reputation: 5 754

How does the string compression work, and is there some kind of generator program I could use for other strings? Just posted an answer with two strings, but not sure how to do string compression in MathGolf. – Kevin Cruijssen – 2019-06-03T12:27:44.123

1

The way I do it is that I check the reference page and Code page 437, and I match the column and the row of the character within the code page with the indices of the string I want. So, means indexing in the string etaoinsrdluczbfp. In that string, b has index 13, z has index 12, and t has index 1. Thus, I look at row 13 and column 12 for bz, which is character . Then I look at row 12 and column 1 for zt, which is character .

– maxb – 2019-06-03T12:39:07.723

Be wary though that it is not strictly Code page 437, since I swapped two characters (the null byte and the non-breaking space). Both of these characters should be replaced with their new counterparts (× and Þ). It should be fairly straight-forward to make a generator program for short strings, I just haven't made one. The compression is nothing fancy, but in cases like this challenge it can save you 2 bytes over the standard ÿbzzt. – maxb – 2019-06-03T12:42:10.797

Ah ok. And compressed strings of mixed characters? So partially from etaoinsrdluczbfp and partially from gwymvkxjqh ?*#.,? Or that isn't possible (yet)? To be more concrete, what would the compressed strings for ÿduck and "goose be? (Here a link to my current answer.)

– Kevin Cruijssen – 2019-06-03T12:45:01.203

I've been able to figure out how to compress "goose to 'g╕3`. As for ÿduck, I guess I could use a 3-char compression for "duc" and a loose 'k, but how does that work when they are in pairs of row-column? EDIT: Never mind, for 3-char it doesn't matter what the column is, but now I have the problem that the strings aren't joined to print. Maybe a different question: how to do a ranged loop without pushing the indexes of the loop? I now have this.

– Kevin Cruijssen – 2019-06-03T12:51:47.020

There's no support for mixing compression and non-compression right now. One thing that's high on my list is to fix better support for fetching words from the dictionary. That way you could define a string, and have it implicitly converted to a list of 16-bit numbers, and used as indices for dictionary fetching. That could probably help a challenge like this. For your answer, the best I could come up with was ƒú╒{;╖è╗'kn}'g╕3`` (you can save 1 byte by replacing{}` with the appropriate 7-byte block character. This is 1 byte longer than what you sent unfortunately. – maxb – 2019-06-03T13:11:53.523

Ok clear. I now have ƒú╒ôÿduckp╘'g╕3`, so your ƒú╒ö;╖è╗'kn'g╕3` would be the same byte-count. Thanks for the explanation, though. Will keep this in mind in the future. – Kevin Cruijssen – 2019-06-03T13:18:16.740

Also to answer your previous question, it is not possible to mix the two strings etaoinsrdluczbfp and gwymvkxjqh ?*#.,. This method of decompression was implemented very early during development, and wasn't actually intended to be a permanent feature. But it has turned out to be very helpful for a few challenges. – maxb – 2019-06-03T13:23:57.637

2

JavaScript - 57

Another JavaScript example:

for(i=0;i<500;)alert((++i+'').indexOf(3)<0&&i%3?i:'bzzt')

Дамян Станчев

Posted 2014-06-23T06:58:08.417

Reputation: 457

2

Microsoft Small Basic (115 chars, 127 bytes)

For i = 1 To 500
j=i
If(Math.Remainder(i,3)=0 Or Text.IsSubText(i,"3"))then
j="bzzt"
EndIf
TextWindow.Write(j+" ")
EndFor

Marsan

Posted 2014-06-23T06:58:08.417

Reputation: 41

2

PROLOG (144)

b:-b(R,1),print([0|R]).
b([500],500).
b([bzzt|R],N):-((0is N mod 3);(name(N,C),member(51,C))),N1 is N+1,b(R,N1).
b([N|R],N):-N1 is N+1,b(R,N1).

Usage:

b.

Wez Sie Tato

Posted 2014-06-23T06:58:08.417

Reputation: 123

2

Python2 (59)

Simple case of list comprehension

print[n if n%3or '3'in str(n)else"bzzt"for n in range(501)]

idiot.py

Posted 2014-06-23T06:58:08.417

Reputation: 161

1

With some tips you can get to 52 bytes at least.

– Linus – 2016-11-04T03:09:38.580

2

Haskell 78

main=mapM(putStrLn.f)[0..500];f x|x`mod`3<1||'3'`elem`show x="bzzt";f x=show x

DrJPepper

Posted 2014-06-23T06:58:08.417

Reputation: 499

2

Python - 53

for i in range(1,501):print[i,'Bzzt']['3'[:i%3]in`i`]

Can't add comments to above answer so posting down here. Starting range at 0 produces Bzzt at 0, need to start at 1.

tbd

Posted 2014-06-23T06:58:08.417

Reputation: 21

1

Groovy, 46 45 bytes

{(0..500).collect{x->x%3<1||x=~/3/?'bzzt':x}}

This is an unnamed closure. Try it Online!

Gurupad Mamadapur

Posted 2014-06-23T06:58:08.417

Reputation: 1 791

1I 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 – 2017-01-20T15:05:33.140

@KevinCruijssen Ah ha, thanks for that. – Gurupad Mamadapur – 2017-01-20T15:12:24.073

1

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"

Bubbler

Posted 2014-06-23T06:58:08.417

Reputation: 16 616

120 bytes – Shaggy – 2018-06-13T16:49:22.850

1

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.

Unrelated String

Posted 2014-06-23T06:58:08.417

Reputation: 5 300

1

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.

Reinstate Monica

Posted 2014-06-23T06:58:08.417

Reputation: 1 382

Why is this marked non-competing? – pppery – 2019-09-21T23:39:21.940

1

Delpi - 128

procedure x;var I: integer;begin for I:=0to 500do writeln(iif((IntToStr(i).Contains('3')or(i mod 3=0)),'bzzt',inttostr(i)));end;

Teun Pronk

Posted 2014-06-23T06:58:08.417

Reputation: 2 599

That won't compile. You never declared i. Also there's no iif in Delphi. You must use IfThen(). – Paul – 2014-06-27T21:37:41.553

I don't understand why I didnt declare I, maybe I made it a global variable which shouldnt work either.. I'll correct it. But there is an iif in delphi, its in the unit IdGlobal. – Teun Pronk – 2014-06-30T07:16:03.480

1

seq and awk 48 38

seq 500|awk '!($1%3)||/3/{$1="bzzt"}1'

Thor

Posted 2014-06-23T06:58:08.417

Reputation: 2 526

The awk code part could be $1%3&&!/3/||$1="bzzt". – manatwork – 2015-07-25T15:30:06.957

1

LiveScript (54)

for n to 500=>alert if n%3==0||/3/test n=>\bzzt else n

nyuszika7h

Posted 2014-06-23T06:58:08.417

Reputation: 1 624

1

bash – 74

I know it won't win anything, not even within bash, but thought I'd submit one where 500 or 501 is not in the solution.

seq 0 166|awk '{print"bzzt\n"($1)*3+1"\n"($1)*3+2;}'|sed 's/.*3.*/bzzt/g'

user15259

Posted 2014-06-23T06:58:08.417

Reputation:

1

Java, 127 124 95 bytes

class B{static{for(int i=0;i++<500;System.out.println(i%3<1||(i+"").contains("3")?"Bzzt":i));}}

It throws an exception at the beginning but it works, at least for me (Java version 1.7.0_60-b19 on Mac OS X 10.8.5).

stommestack

Posted 2014-06-23T06:58:08.417

Reputation: 234

That trick doesn't work in Java 7 or later. It looks for a main method before executing static initializers. – tbodt – 2014-06-23T21:48:24.103

@tbodt I have Java 7 and it works – stommestack – 2014-06-23T21:51:53.033

Is there any way you can get a modern toolset to compile and run this, please add it to the answer? (I use 1.7.0_55 on linux) If you need a specific version you need to mention it in your answer. – Sylwester – 2014-06-23T21:52:33.943

I tested it on Java 6 (works then throws exception) and Java 8 (doesn't work). – tbodt – 2014-06-23T22:09:51.810

1

C# (110)

Enumerable.Range(1,500).All(x =>{Console.Write((x%3==0)||(x + "").Contains("3")?"Bzzt ":x+" ");return true;});

stephenbayer

Posted 2014-06-23T06:58:08.417

Reputation: 111

You can get a lower byte count by removing unnecessary whitespace. Actually, you don't need any whitespace here. – ProgramFOX – 2014-06-23T16:31:43.570

What version of C# has an IEnumerable<T>.ForEach method? – Peter Taylor – 2014-06-23T16:38:27.887

I get an error on Mono's C# compiler: Unexpected symbol: \Enumerable'` – Jwosty – 2014-06-23T16:54:18.980

(x+"").Contains("3") should work instead of the ToString() to shorten it. – WozzeC – 2014-06-23T19:15:24.227

Made the changes, removed ForEach which was a extension method from a 3rd party library. – stephenbayer – 2014-06-23T19:39:06.667

Can you return 1 instead of true? Also, there are whitespaces in (x + "") – WozzeC – 2014-06-24T10:43:01.653

1

F# - 86

for i in 0..500 do if(string i).Contains"3"||i%3=0 then printfn"Bzzt"else printfn"%i"i

Jwosty

Posted 2014-06-23T06:58:08.417

Reputation: 3 530

1

Ruby, 57

Not a competitive Ruby answer, but I like it because it's weird.

i=-1;([b=:bzzt,p,p]*167).map{|a|puts"#{i+=1}"[?3]?b:a||i}

Not that Charles

Posted 2014-06-23T06:58:08.417

Reputation: 1 905

1

Befunge 93 - idk

Just for fun:

&   > ::::91+/91+*-01p91+/:91+/91+*-: 11p91+91+*/21p >  01g3-  !!     |
   9                                                                  "
30 9g                                                                  
   *4                                                                 t
   90                                                                 z
   5p                                                                 z
   *4                                                                 b
   +0                                                                 "
   3+                                       v                   $,,,,,<
   -*                                                                  
   99                                       v   .<   |    !! -g20g0*87<
   >^                                            |%3:<                p
                                                 "                     
    v               _@#`0: -1   p0*87    g21<                         0
                                                 t                    *
                                                 z   ^                8
                                                 z                    7
                                            $    b                    +
                                            ,    "                    1
                                            ^,,,,<                    g

                                                                      0
                                                                      *
                                                                      8
                                                                      7

Decidedly un-golfyfied, but it was fun creating a complete program.

AndoDaan

Posted 2014-06-23T06:58:08.417

Reputation: 2 232

"Decidedly un-golfyfied" = "not a serious contender" = "subject to deletion" – pppery – 2020-01-07T00:19:19.470

1

PHP, no seperator - 53

while(++$i<501)echo$i%3<1||strpos(-$i,'3')?'bzzt':$i;

It's a improved version of @Martijn's code. I would like to add comment to his answer, but I haven't enough reputation to do that...

Jack Song

Posted 2014-06-23T06:58:08.417

Reputation: 11

1

Python2 (63)

Corrected version of @idiot.py's code (I don't have enough reputation to comment on his post).

print[n if n%3and'3'not in str(n)else"bzzt"for n in range(501)]

or, equivalently,

print["bzzt"if not n%3or'3'in str(n)else n for n in range(501)]

You have to negate the second condition, otherwise it gives incorrect output.

output:

['bzzt', 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]

Laura Huysamen

Posted 2014-06-23T06:58:08.417

Reputation: 111

1

C, 90 86 81

i,s;main(){while(++i<501)sprintf(&s,"%d",i),puts(i%3&&!strchr(&s,51)?&s:"bzzt");}

Not a serious contender. This is essentially bacchusbeale's answer golfed better, as I suggested in comments to his answer. As well as those changes, I used strchr as a shorter test than a for loop to see if the string version of the integer contains the character 3 (character 51 in ASCII).

Edit: down to 81 characters incorporating edc65's sick trick from the comments (assumes int is at least 32 bits). Thanks!

David Richerby

Posted 2014-06-23T06:58:08.417

Reputation: 193

181: i,s;main(){while(++i<501)sprintf(&s,"%d",i),puts(i%3&&!strchr(&s,51)?&s:"bzzt"); (need a 32 bits int or longer) – edc65 – 2014-06-25T21:43:33.190

1

Tcl 90

set i 0;while {$i < 501} {if {[regexp 3 $i]||($i %3)<1} {puts "bzzt"} {puts "$i"};incr i}

I'm sure other tclers could make this more terse, but the interpreter is funny about whitespaces.

user3275885

Posted 2014-06-23T06:58:08.417

Reputation: 111

1

C, 79

i;main(s){while(++i<498+sprintf(&s,"%d",i))puts(i%3*!strchr(&s,51)?&s:"bzzt");}

Improved version of squeamish ossifrage's solution. Now it's the shortest C solution.

ciamej

Posted 2014-06-23T06:58:08.417

Reputation: 131

1

JavaScript, 70

First entry into a code golf

i=0;while(i<501)console.log(((""+i).match(/3/g)||i%3==0)?'bzzt':i),i++

Can probably be made shorter, but this one doesn't do alert and make you want to kill the developer.

Zach Mertes

Posted 2014-06-23T06:58:08.417

Reputation: 286

Count up to 500, for better than while as you use i=0;i++;,alert(once!) better than console.log, test better than match,invert condition to avoid ==0, then you have [http://codegolf.stackexchange.com/questions/32267/play-the-bzzt-game#32270] – edc65 – 2014-06-26T15:54:59.573

1

C#

Code can be executed directly in LinQPad.

Number is divisible by 3 (49)

var i=0;while(i++<501)(i%3<1?"bzzt":i+"").Dump();

This one should count as the question stated:

The number only has to satisfy at least 1 of the following requirements.


Number contains 3 (64)

var i=0;while(i++<501)((i+"").Contains("3")?"bzzt":i+"").Dump();

Both conditions apply (70)

var i=0;while(i++<501)(i%3<1|(i+"").Contains("3")?"buzz":i+"").Dump();

Abbas

Posted 2014-06-23T06:58:08.417

Reputation: 349

1

Delphi - 119

repeat ShowMessage(IfThen((Tag mod 3=0) or (pos('3',IntToStr(Tag))>0),'bzzt',IntToStr(Tag))); Tag:=Tag+1 until Tag=500

Uses the fact that "self" is assumed so the form's Tag property can be accessed directly without actually declaring a variable. I had critiqued another Delphi answer here a few minutes ago so I thought it was only fair I posted one too.

Paul

Posted 2014-06-23T06:58:08.417

Reputation: 328

1

JAGL V1.0 - 35

1 501r{ddg@3%nSg51e|"bzzt"SnI32+p}/

Probably could have done better. May try to revise it.

Explaination:

1 501r                                     Make a range of 1 to 500 inclusive
      {ddg                                 Duplicate twice and convert top to string
          @3%n                             Rotate top 3 on stack, and push not(top mod 3)
              Sg                           Swap top two values, and convert top to string
                51e                        Check if 51 (3) is in the string rep
                   |"bzzt"                 Take the logical "or", and push "bzzt"
                          SnI              Swap, reverse, and if not divisible, drop "bzzt"
                             32+p          Add a space, and print
                                 }/        End block, and map over range

globby

Posted 2014-06-23T06:58:08.417

Reputation: 1 132

1

Java, 139 132 128 127 bytes

class A{public static void main(String[] a){for(int i=0;i++<500;)System.out.print(i%3==0|(i+"").contains("3")?"bzzt ":i+" ");}}

Utsav

Posted 2014-06-23T06:58:08.417

Reputation: 19

1You can shave off a couple of characters by removing the {} braces on your for loop and doing a i++<501;) check. – Nathan Merrill – 2015-07-02T14:14:27.367

Sure @NathanMerrill....shortened 'args' variable name as well – Utsav – 2015-07-02T14:28:18.423

1

Too many parenthesis: both % and == have higher precedence than || and all of them have higher precendece than ?:: System.out.print(i%3==0||(i+"").contains("3")?"bzzt ":i+" ").

– manatwork – 2015-07-02T14:50:51.340

well said @manatwork I never cared/thought about using precedence before. Will keep in mind for code-golf – Utsav – 2015-07-02T15:13:36.940

As now it became too similar to Jop V.'s Java answer, here is another trick: use bitwise | instead of logical ||. In this case gives the same result.

– manatwork – 2015-07-02T15:21:27.243

@manatwork Just a matter of chance. And can't think of a MUCH different Java answer – Utsav – 2015-07-02T15:40:56.717

1

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.)

manatwork

Posted 2014-06-23T06:58:08.417

Reputation: 17 865

1

Mouse-2002, 34 bytes

I'm proud that lil' ol' Mouse, first implemented in 1979 and the most recent iteration updated Aug '07 (excluding the one by me), can do so well! :')

(x.501<^x.d\[x.!J!'|"bzzt!"]x.1+x:)

Explained:

(             ~ while true
  x. 501 < ^  ~ push x; push 1 if less than 501 and break if 0
  x. d \      ~ push x mod 3
  [           ~ if 0; then
    x. ! J!'  ~ push x and print, push the ascii code 9 and print
  |           ~ else
    "bzzt!"   ~ print this string
  ]           ~ endif
  x. b+ x:    ~ push x, increment by 1
)             ~ endwhile
$             ~ (implicit for scripts) end prog

Sample run:

$ mouse bzzt.mou | head
bzzt
1       2       bzzt
4       5       bzzt
7       8       bzzt
10      11      bzzt
13      14      bzzt
16      17      bzzt
19      20      bzzt
22      23      bzzt
25      26      bzzt

Tab chars because I say so.

My reboot of this language's legacy can do this exact thing in 27 bytes:

(x501<^xd\[x.|"bzzt".]1!x+)

And I'm not even aiming for it to be a golfing lang, just a small syntax! No interpreter yet.

cat

Posted 2014-06-23T06:58:08.417

Reputation: 4 989

1

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~%~3Kd`bzzt`g?Pp
*0>F3~%'d`bzzt`@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.

M L

Posted 2014-06-23T06:58:08.417

Reputation: 2 865

0

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');

Spedwards

Posted 2014-06-23T06:58:08.417

Reputation: 159

You know this is about shortest right? The function only makes it longer, and console.log can be replaced with alert. – Martijn – 2014-06-23T08:31:20.423

@Martijn Honestly didn't think about alert. And I thought I saw function in the rules. – Spedwards – 2014-06-23T08:38:24.987

@Martijn Also, no one would want to run it if it were alerts haha – Spedwards – 2014-06-23T08:39:54.697

Haha. You could add comment in the uncompressed //console instead of alert for testingpurposes so people'll get it :) – Martijn – 2014-06-23T08:43:11.863

0

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;}

bacchusbeale

Posted 2014-06-23T06:58:08.417

Reputation: 1 235

1You 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 – 2014-06-23T22:37:01.083

@David puts put a newline by itself. – edc65 – 2014-06-25T11:26:44.997

@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 – 2014-06-25T14:47:13.373

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 – 2014-06-25T16:06:57.473

0

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'

izb

Posted 2014-06-23T06:58:08.417

Reputation: 101

0

Python3, 62

for i in range(501):print('bzzt'if'3'in str(i) or i%3<1 else i)

klingt.net

Posted 2014-06-23T06:58:08.417

Reputation: 876

0

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.).

Adam Speight

Posted 2014-06-23T06:58:08.417

Reputation: 1 234

0

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.

Karol S

Posted 2014-06-23T06:58:08.417

Reputation: 161

0

Haskell - 73

b n|mod n 3<1||'3'`elem`show n="bzzt"|1<2=show n
main=print$map b[0..500]

nyuszika7h

Posted 2014-06-23T06:58:08.417

Reputation: 1 624

0

Racket 80

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

Matthew Butterick

Posted 2014-06-23T06:58:08.417

Reputation: 401

0

Pyth, 20

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

Explanation:

V501            for N in range(501):
?               _ if _ else _
 N              print(N)
 &              _ and _
  %N3           N mod 3
  -`3`N         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

-`3`N

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.

isaacg

Posted 2014-06-23T06:58:08.417

Reputation: 39 268

0

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)))

Michael Easter

Posted 2014-06-23T06:58:08.417

Reputation: 585

0

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

Pyth, 20

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

Explanation:

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

Try it here.

isaacg

Posted 2014-06-23T06:58:08.417

Reputation: 39 268

0

Swift 2.0, 71

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

Kametrixom

Posted 2014-06-23T06:58:08.417

Reputation: 426

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)}

Apollonian

Posted 2014-06-23T06:58:08.417

Reputation: 61

Are all the spaces required? Or is Swift just weird with them? – Oliver Ni – 2016-11-02T05:02:45.943

I believe at least I eliminated all unnecessary ones. – Apollonian – 2016-11-02T06:07:16.610

-1

JavaScript, 63characters

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

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

EyeOfTheHawks

Posted 2014-06-23T06:58:08.417

Reputation: 99

1i don't think this meets the criteria – Not that Charles – 2014-06-26T21:16:58.083

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 – 2014-06-27T05:57:04.970