Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a teacher, and in a few days I have to give my students a test. Now, I'm always worried about my loveliest students being hurt by the least loveliest ones when they cheat, so I want to randomize the tests so no one can cheat off of anyone.

Right now, I have my tests saved in this format:

When was Java invented?
  Why does this matter?
  1941
  War was beginning
  None of the above

What is the increment operator in Java?
  Stack Overflow>how 2 incrememnt
  Google>how 2 incrememnt
  increment
  ++

That is, the questions are separated by a single blank line, and the answers are all preceded by two spaces. This is the output I need:

What is the increment operator in Java?
  ++
  increment
  Google>how 2 incrememnt
  Stack Overflow>how 2 incrememnt

When was Java invented?
  War was beginning
  1941
  Why does this matter?
  None of the above

That is, each answer on a question in a random order, and the question order randomized as well. Keep in mind that if the answer choice is "None of the above", it should stay at the bottom. Every question always has exactly four answers, and "None of the above" only ever appears as the last answer choice -- and never appears as a substring of an answer choice that is not "None of the above". Unfortunately, I can't rewrite all of my tests, so you'll have to take them in that format. Also, my students have to be able to read it, so I can't really take output any other way (except as described below).

I don't need it to be perfectly random. As long as it's close.

Standard loopholes are banned.


Bonus

Now, my students are used to that plain format, but if you can make it look like this...

1. What is the increment operator in Java?
  A. ++
  B. increment
  C. Google>how 2 incrememnt
  D. Stack Overflow>how 2 incrememnt

2. When was Java invented?
  A. War was beginning
  B. 1941
  C. Why does this matter?
  D. None of the above

I'll take 25% off of your final score. You'll get input the same way, though.

That is, if you number the questions and label the answers. Please keep in mind that questions should start at 1, and the answers are from A to D.


NB: The examples are different from the ones in the answers because I changed them after the fact. The specific examples aren't the point anyway; answers had to work with any arbitrary question(s).

share|improve this question
    
Bonuses in code golf are generally discouraged. None of the current submissions take the bonus (except this one, but with the bonus is a worse score than without), so that's a pretty good indicator that the challenge would be better without the bonus. – Mego Apr 24 at 9:09
    
@Mego It fits the theme of the question and is easy to understand. There's no harm in it. – QPaysTaxes Apr 24 at 14:16
up vote 6 down vote accepted

Pyth - 48 42 41 39 bytes

Will packed string.

js.Sm++hd/D"None of the above".Stdkc.zk

Try it online here.

share|improve this answer
    
Accepting this answer because this question was [code-golf] and this answer is the shortest. Well done! – QPaysTaxes Apr 24 at 0:34

JavaScript ES6, 170 bytes

Is an anonymous function, name it. Note: this uses the random sort method, which isn't entirely random, but is sufficient, provided you aren't a probability teacher.

t=>t.split`

`.map(x=>(x=x.split`
`,R=[],(k=x.pop())=="  None of the above"?(R=[k]):x.push(k),[x.shift(),...x.sort(r=_=>.5-Math.random()),...R].join`
`)).sort(r).join`

`

With the bonus, 180.75 bytes

t=>t.split`

`.map(x=>(x=x.split`
`,R=[],(k=x.pop())=="  None of the above"?(R=[k]):x.push(k),[x.shift(),...x.sort(r=_=>.5-Math.random()),...R].map((k,i)=>(i?`  ${" ABCD"[i]}. `:"")+k.trim()).join`
`),a=0).sort(r).map(e=>++a+". "+e).join`

`

Test it out!

F=t=>t.split`

`.map(x=>(x=x.split`
`,R=[],(k=x.pop())=="  None of the above"?(R=[k]):x.push(k),[x.shift(),...x.sort(r=_=>.5-Math.random()),...R].join`
`)).sort(r).join`

`;

g.onclick=function(){o.innerHTML = ""; o.appendChild(document.createTextNode(F(i.value)));}
g.click();
textarea{width:100%;height:14em;}textarea,div,button{font-family:Consolas,monospace;white-space:pre;}
<textarea id=i>When was the War of 1812?
  1812.5
  1776
  1812
  1821

What is the capital of France?
  46
  F
  Nice
  None of the above

What is the square root of -1 (simplified)?
  i
  i don't know
  square root of -1
  wait this is a math test?</textarea><button id=g>go &rarr;</button><div id=o></div>

share|improve this answer
    
Did you try going for the bonus? – CalculatorFeline Mar 11 at 1:03
    
@CatsAreFluffy No, net yet ;) – Cᴏɴᴏʀ O'Bʀɪᴇɴ Mar 11 at 1:03
1  
@CatsAreFluffy Well, it's a highly technical... thing. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Mar 11 at 1:06
3  
What's a highly? What's a thing? What's a technical? What's a ? What's a ...? What's a 493 characters left? – CalculatorFeline Mar 11 at 1:09
1  
@fond42518 My pleasure! However, in that random sort, I am saving the function _=>.5-Math.random() to the variable r, which I reference later on the fifth line. I am actually performing two random sorts: one on the items, and the other on the questions. If you want to learn more ES6, I suggest reading here. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Mar 11 at 2:34

CJam, 54 53 55 52 bytes

Saved 1 byte from using a later release (avaliable on TIO). Gained 2 bytes because I forgot to randomize order of questions. Saved 2 bytes from yet another bug fixed on TIO.

qNN+/mr{N/(\mr_"  None of the above"#3e\N*N\++}%NN+*

Try it online!

share|improve this answer
    
Only two bytes gained? o_O – Cᴏɴᴏʀ O'Bʀɪᴇɴ Mar 11 at 1:10
    
@CᴏɴᴏʀO'Bʀɪᴇɴ lol yeah, I split based on questions at the beginning, then so I just added the mr operator (randomize) to randomize order of questions before the answer logic takes place. – GamrCorps Mar 11 at 1:11
    
Oh, cool! ..... – Cᴏɴᴏʀ O'Bʀɪᴇɴ Mar 11 at 1:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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