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
Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It only takes a minute to sign up.
Sign up to join this communityYou 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
BASH 34 characters
yes ":)" | head -$(($RANDOM%255))
I had to use a head
in my code ;)
(":)")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.
,(->|":)"(-))
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
,[->>+++++++[-<++++++++>]<++.>++++[-<---->]<-.[-]<]
This is just the compiled EBF
code. It seems pretty compact.
Because, why not
declare @c int;set @c=rand()*255;while(@c<255) begin print ':)';set @c=@c+1;end
class P
def main
for i in Random().next(256),print ":)"
@set /aa=%random%%%256
@for /l %%i in (0,1,%a%) do @echo :)
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)
So, uh, yeah.
repeat random number from 0 to 255 times log":)" end
I think this is fairly self explanatory.
Y8#mr":)"*
I'm very new to golfing (this is my first post), so I'm not quite sure what to say here. :-P
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.
(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)^':)' "")
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"