Super User is a question and answer site for computer enthusiasts and power users. 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

Here's what I'm trying to do:

Correct answers: A C A B D B ...

Student:         Answers:            Score:
--------         --------            ------
Charlie A.       A D A B D C ...     4/6
George B.        A C A B D D ...     5/6

How do you count the right answers by comparing the answers from each student with the answers in the first row? I want to be able to compute the score of the tests by entering in the answers.

share|improve this question
Are the answers in their own cells? How many answers are there? – Paul Dec 30 '12 at 13:18

Here's a shell script that just prints the number of same characters without doing any formatting:


input="Charlie A.,ADABDC
George B.,ACABDD"
for line in $input; do
  for i in $(seq ${#solutions}); do
    [ ${answers:$i:1} == ${solutions:$i:1} ] && ((correct++))
  echo "$line,$correct"

And a Ruby version that formats the results as a monospace table:

solutions = "ACABDB"
"Charlie A.,ADABDC
George B.,ACABDD".split("\n").each { |line|
  name, answer = line.split(",")
  correct = 0
  ( { |i|
    correct += 1 if answer[i] == solutions[i]
  puts "#{"%-17s" % name}#{"%-20s" % answer.split("").join(" ")}#{correct}/#{solutions.length}"

You can save the scripts with TextEdit (in plain text mode) and then run them from Terminal with something like bash ~/Desktop/ or ruby ~/Desktop/script.rb.

share|improve this answer

Your Answer


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.