23
2
Output one random character for each character of source code (as illustrated below). The probability of each character is its frequency in the original source code. Thus the output will be fake source code resembling a quine.
Specification
- Restrictions
- Standard quine constrains apply. No empty programs or functions. Also no reading your own source.
- Output
- The number of characters output should be exactly the number of characters in the source code
- Each output character should be randomly choosen
- The probability of choosing any character is equal to
(occurrences in source) / (length of source)
- This means that even a unary solution needs to 'randomly' choose 1 with probability
1
. Which is to say that the output can't be hard coded.
- Winning
- This is code golf, so fewest bytes wins
Example
Program Frequency Probability Possible Output
------- --------- ----------- ---------------
a@!@ a - 1 a - 25% @@a@
! - 1 ! - 25%
@ - 2 @ - 50%
Program Frequency Probability Possible Output
------- --------- ----------- ---------------
caBaDBcDaBDB a - 3 a - 25% aaaBBBBccDDD
B - 4 B - 33%
c - 2 c - 17%
D - 3 D - 25%
Are single-character quines allowed? – Nathan Merrill – 2016-09-07T21:59:04.663
@NathanMerrill Yes, single character (and other unary) solutions are allowed. However, their output still needs to be randomly chosen. – NonlinearFruit – 2016-09-07T22:03:23.270
How shall I find the occurences of characters in a file if I am not allowed to read it? – Titus – 2016-09-07T22:38:07.663
That is the
quine
part. Usually quines have the actual source code and a string that contains a copy of the source code. Here is a Python quine_='_=%r;print _%%_';print _%_
– NonlinearFruit – 2016-09-07T22:47:12.953Yup, I got it from the Jelly explanation. thanks. – Titus – 2016-09-07T22:57:47.630
@NonlinearFruit my program "randomly" chooses the letter s from the set of letters "s" it is truly random too! – Rohan Jhunjhunwala – 2016-09-07T23:12:18.007
1Is this [tag:code-golf]? – OldBunny2800 – 2016-09-07T23:54:45.913
@OldBunny2800 Good catch! I forgot the winning criterion (-‸ლ) – NonlinearFruit – 2016-09-08T00:00:08.343
@RohanJhunjhunwala That is a bit of a loophole. In the Specification, I was trying to outlaw solutions like that. I'm sorry if it wasn't clear.
Which is to say that the output can't be hard coded.
– NonlinearFruit – 2016-09-08T00:05:10.820@NonlinearFruit so are unary quine answers unacceptable? – Rohan Jhunjhunwala – 2016-09-08T00:07:52.863
@RohanJhunjhunwala Unary solutions are welcome, that is why I chose the wording I used. But they have to conform (like everyone else) to the random criterion. Printing
– NonlinearFruit – 2016-09-08T00:55:11.197s
and choosings
randomly from a one element set have the same result but are semantically different. This is a little nit-picky, but without it some solutions could curtail the gist of this challenge.Is it mistake in the first example output?
@@a@
should be@@a!
? – VolAnd – 2016-09-08T05:25:46.1031@VolAnd No. The probability of each character appearing is based on the character frequency. If you flip a coin twice and it lands on heads once, it doesn't have to hand on tails the second time. – wizzwizz4 – 2016-09-08T06:29:23.840
@wizzwizz4 I understand, it was necessary to use a random number to generate output – VolAnd – 2016-09-08T06:55:52.717
Is it ok to generate a random permutation of the source? – Adám – 2016-09-08T19:01:13.110
@Adam No, each output character should be chosen independently of the other output characters – NonlinearFruit – 2016-09-08T19:08:20.227