Skip to content

Instantly share code, notes, and snippets.

@ff8c00
Last active March 9, 2018 10:23
Show Gist options
  • Save ff8c00/a88d7e2c5a8919b75260d774302f58b3 to your computer and use it in GitHub Desktop.
Save ff8c00/a88d7e2c5a8919b75260d774302f58b3 to your computer and use it in GitHub Desktop.
Reddit Daily Programmer 353 Easy
<html>
<head>
<script>
function distance(a, b) {
var i = 0;
var j = 0;
for (i = 0; i < a.length; i++) {
if (a[i] != b[i]) {
j = j + 1;
}
}
return j;
}
function run() {
var a = [];
var i = 0;
var j = 0;
var b = [];
var c = [];
a = [
"CTCCATCACAC",
"AATATCTACAT",
"ACATTCTCCAT",
"CCTCCCCACTC"
];
for (i = 0; i < a.length; i++) {
b[i] = [];
for (j = 0; j < a.length; j++) {
b[i][j] = distance(a[i], a[j]);
}
}
for (i = 0; i < a.length; i++) {
c[i] = b[i].reduce(function(a, b) {
return a + b;
}, 0);
}
j = 0;
for (i = 0; i < c.length; i++) {
if (c[i] < c[j]) {
j = i;
}
}
return a[j];
}
</script>
</head>
<body onload="document.write(run())">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment