19
2
Being short of cash, you have signed up to build donuts for The Doughnut Shop™, the biggest digital doughnut company in the world, mostly because they sell every size of doughnut imaginable.
Now, given that trading standards nowadays is very tough, you need to write a piece of code as short as possible to create these doughnuts so that the source code that created them can be put on the outside of the packet.
Challenge
Given 4 inputs, radius of the outer ring, radius of the inner ring, the possible sprinkles and the chance of a cell having a sprinkle, output a doughnut covered in those sprinkles which has the correct inner and outer radii.
- The input may be taken how you wish (arguments to a function, stdin, program arguments) and in any order.
- The sprinkles will be given in the form of 1 character per sprinkle type
^+*-
as sprinkle input would be a list of 4 sprinkles,^
,+
,*
,-
- The chance of a sprinkle will be entered as a floating point value between 0 and 1. eg:
0.1
,0.23
- You must print out the output to stdout or equivalent.
- Sprinkles can't be on the edges of the doughnut.
- Each type of sprinkle must have an equally likely chance of being on each cell.
- The radii are given in 1-cell units.
- If the inner radius equals either 0 OR the outer radius, the doughnut is said to have no ring.
- Both radii will be non-negative integers.
- The inner and outer edges of the doughnut must be represented using hashes (
#
) A test to see if a point is in a circle, given a radius and the center of the circle is:
(x-center)**2+(y-center)**2 < radius**2
Example input with output
(outer radius, inner radius, sprinkles, chance of sprinkle)
10, 4, "^+*-", 0.1
######### # # ## ++ * *## # # # ^^ - * # # ##### ^ # #+ # # # # # #- # # # # * # # # #+ # # # # # #^ +# # # # # # # # * ##### # # + - # # ^ # ## ^ + ## # ^ # #########
5, 2, ":^+*", 0.9
##### #^^+ ^# #**### # #:# #^# #^# #*# #:# #*# #:+###* # # *:^:# #####
This is code golf, the shortest answer in bytes wins
Should there be an equal distribution of sparkles, or non uniform distribution will also do. – Kishan Kumar – 2015-09-25T16:04:28.710
There should be an equal distribution of sprinkles. – Blue – 2015-09-25T16:52:00.990
It's not clear to me from the spec which positions correspond to the borders of the circles. – Dennis – 2016-06-25T04:58:08.973
@Dennis I'd rather not change it and disqualify the only answer (that's a nice answer too) but I meant for a border to be where circle met non-circle (point is in circle but not all neighbors are) – Blue – 2016-06-25T19:21:00.690
Your example output pretty much invalidates it already, since the shapes for
10, 4
and5, 2
are pretty different. I was going to leave a comment on the answer, but I realized that I didn't really understand how the output should look like for any dimensions but those in the examples. If you want to change your original idea match the output from the answer, that's up to you, but the challenge should clearly define how to draw the borders either way. – Dennis – 2016-06-25T20:30:36.843