Download or view gradingProblem.frink in plain text format
/* This is a proposed solution for Patrick Honner's question about scoring the
"correctness" of an ordered list. It uses the Levenshtein-Damerau edit
distance (eliminating outright replacements) to calculate how many
insertions, deletions, and adjacent character swaps it would take to turn
one sequence into the "right" one.
The arguments are:
editDistanceDamerau[str1, str2, deleteCost, insertCost, replaceCost, swapCost]
In this sample, replaceCost is set very high to eliminate replacements.
See:
http://mrhonner.com/archives/10229
*/
opts = ["A","B","C","D"]
correct = join["", opts]
// Generate all permutations of the list in lexicographic order.
for p = opts.lexicographicPermute[]
{
// Turn the permuted array back into a string.
alt = join["", p]
// The 1000 here is the replacement cost, made to be higher than the length
// of the string, effectively making the algorithm ignore replacements.
score = editDistanceDamerau[alt, correct, 1, 1, 1000, 1]
println["$alt\t$score"]
}
Download or view gradingProblem.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen was born 20217 days, 23 hours, 37 minutes ago.