6
\$\begingroup\$

You have to create a code which prints

:)  

a random number of times from 1 to 255 inclusive. Your output may not contain any whitespace.

Your score :
The count in bytes

EDIT : Also show 3 outputs of your code

\$\endgroup\$
26
  • 22
    \$\begingroup\$ What's the purpose of subtracting points from popular answers? \$\endgroup\$
    – sortfiend
    Mar 6, 2014 at 4:41
  • 24
    \$\begingroup\$ But, further, why is a code golf question scoring based on votes? It's code golf, not a popularity contest \$\endgroup\$ Mar 6, 2014 at 8:38
  • 8
    \$\begingroup\$ Can you define "random"? Do you mean a uniform distribution between 0 and 255 number of occurrences, any probability distribution where each number of occurences between 0 and 255 has a non-zero probability, or just an unpredictable amount of smileys? \$\endgroup\$
    – Bakuriu
    Mar 6, 2014 at 10:27
  • 16
    \$\begingroup\$ My php solution is 0 bytes. It is an empty php file. Since you didn't specify what "random" means: For my custom made random number generator, I chose the distribution which gives zero with probability 1 and all other numbers with 0 probability (the degenerate distribution). I am sure you will find it obeys all of your rules. \$\endgroup\$ Mar 6, 2014 at 14:10
  • 7
    \$\begingroup\$ I agree with @TimSeguine, if I could I would downvote. This is super easy, basically no option to be creative in any way, strange score system (mix of code-golf and popularity), the challenge itself isn't very innovativ. \$\endgroup\$ Mar 6, 2014 at 15:09

72 Answers 72

1 2
3
1
\$\begingroup\$

BASH 34 characters

yes ":)" | head -$(($RANDOM%255))

I had to use a head in my code ;)

\$\endgroup\$
1
\$\begingroup\$

Simplex v.0.5, 17 bytes

(":)")257{ppj1X}g
(    )257            ~~ repeat inner expression 257 times
 ":)"                ~~ set the current bytes to :, the next byte to ), and increment pointer by two
         {     }     ~~ repeat inner expression until current byte is zero
          pp         ~~ remove two cells, moving pointer backwards twice
            j        ~~ insert a new cell
             1       ~~ the cell is zero, and thus is initialized to 1
              X      ~~ sets the cell to an integer N, 0 <= N <= 1
                g    ~~ clears the strip and outputs characters as ASCII characters.

Technically, this compiles to the following Simplex code:

":)"":)"...(257 times total)...":)"{ppj1X}g

Now, this abuses the fact that the exit chance need not to be equally distributed. Here are some example outputs using my interpreter on my hard drive (working on releasing it sometime on the GitHub):

Output 1
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
Output 2
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
Output 3
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

FYI, the chance of getting one :) is:

So, yeah, it's still possible, yet unlikely.

\$\endgroup\$
0
\$\begingroup\$

Extended BrainFuck: 13

,(->|":)"(-))

This is bending the rules a little since BrainFuck (runtime of EBF) doesn't have a random function so it has to get random bytes as input.

Compilation:

sylwester@pussycat ~> bf ebf.bf < ransmiley.ebf > ransmiley.bf

3 runs:

sylwester@pussycat ~> bf ransmiley.bf </dev/random
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)⏎
sylwester@pussycat ~> bf ransmiley.bf </dev/random
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)⏎
sylwester@pussycat ~> bf ransmiley.bf </dev/random
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)⏎
sylwester@pussycat ~> 

The examples here are shown with bf which is a BrainFuck interpreter implementation available in all debian based linux distros with:

sudo apt-get install bf

Also it can be compiled from source

BrainFuck: 51

,[->>+++++++[-<++++++++>]<++.>++++[-<---->]<-.[-]<]

This is just the compiled EBF code. It seems pretty compact.

\$\endgroup\$
0
\$\begingroup\$

SQL, 79

Because, why not

declare @c int;set @c=rand()*255;while(@c<255) begin print ':)';set @c=@c+1;end
\$\endgroup\$
0
\$\begingroup\$

Cobra - 60

class P
    def main
        for i in Random().next(256),print ":)"

Batch - 60

@set /aa=%random%%%256
@for /l %%i in (0,1,%a%) do @echo :)
\$\endgroup\$
0
\$\begingroup\$

Ruby - 15 bytes

This was a fun, simple little code golf. Here's the code:

p":)"*rand(255)

which prints something like

":):):):):):):):):):):):):):):):):):):):)"

To print without the quotes you would have to add 3 bytes and say:

puts":)"*rand(255)
\$\endgroup\$
0
\$\begingroup\$

AppleScript, 52 bytes

So, uh, yeah.

repeat random number from 0 to 255 times
log":)"
end

I think this is fairly self explanatory.

\$\endgroup\$
0
\$\begingroup\$

CJam, 12 11 10 chars

Y8#mr":)"*

I'm very new to golfing (this is my first post), so I'm not quite sure what to say here. :-P

\$\endgroup\$
0
\$\begingroup\$

Hassium, 47 Bytes

func main()print(":)"*new Random().next(0,255))

Run and see expanded online here

\$\endgroup\$
0
\$\begingroup\$

Python, 16 characters

print ":)"*id(1)

Warning!!!! "Random" on my system is typically between 100-10 million or so this can take a while:

$ python dumb.py | wc -c
75397329
$ python dumb.py | wc -c
43243729

Add four bytes and mod it by 256. Woo.

\$\endgroup\$
1
  • \$\begingroup\$ Remove the number 16 from your heading and show that code differently \$\endgroup\$ Mar 9, 2014 at 12:51
0
\$\begingroup\$

Microscript II, 10 bytes

":)"s256R*
\$\endgroup\$
0
\$\begingroup\$

Hoon, 34 bytes

(runt (~(rad og eny) 256)^':)' "")

++runt prepends b a times. Giving it just an empty tape, pulling a random number from ++rad:og with the entropy variable eny.

Really, the only interesting thing in this is the syntax a^b - it's sugar for [a b] which saves two bytes, since runt really needs to be called like (runt [a b] c)

> (runt (~(rad og eny) 256)^':)' "")
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"
> (runt (~(rad og eny) 256)^':)' "")
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"
> (runt (~(rad og eny) 256)^':)' "")
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"
\$\endgroup\$
1 2
3

Not the answer you're looking for? Browse other questions tagged or ask your own question.