Last active
August 29, 2015 14:14
-
-
Save michaelrepper/2f445372bb1c5710ce9e to your computer and use it in GitHub Desktop.
r/Dailyprogrammer Challenge #199 Test Harness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Live preview of this Gist: | |
http://htmlpreview.github.io/?https://gist.githubusercontent.com/michaelrepper/2f445372bb1c5710ce9e/raw/1c30d30d6fc18ef69d805213d2f43fc235ff44b3/rdp_199_harness.html | |
--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="author" content="Michael Repper"> | |
<meta name="contact" content="query [ a * t ] gridoodle [ d * o * t ] com"> | |
<title>r/Dailyprogrammer Challenge #199 Test Harness</title> | |
<script src="https://rawgit.com/michaelrepper/2f445372bb1c5710ce9e/raw/efd65172cd961efe17013be1840c91b57efea89e/rdp_199_parse.js"></script> | |
<script src="https://rawgit.com/michaelrepper/5e7a2556e033d6e17748/raw/f19ef473630e234480fa5ec0ac69d384303a096b/rdp_199_reverse.js"></script> | |
<style> | |
body | |
{ | |
font-family: "Lucida Console", Monaco, monospace; | |
font-size: 14px; | |
overflow: hidden; | |
} | |
#web_form | |
{ | |
width: 300px; | |
margin: auto; | |
padding-bottom: 20px; | |
} | |
#container | |
{ | |
top: calc(50vh - 200px); | |
width: 600px; | |
height: 200px; | |
margin: auto auto auto auto; | |
position: relative; | |
} | |
#title_text | |
{ | |
width: 600px; | |
margin: auto auto 80px auto; | |
position: relative; | |
text-align: center; | |
} | |
#info_text | |
{ | |
margin-top: 10px; | |
font-size: 12px; | |
} | |
</style> | |
<script> | |
function verify() | |
{ | |
var input = document.getElementById('number_input').value; | |
if (input.length != 9) | |
{ | |
info_text_update('Account numbers must be exactly 9 digits and can contain numbers only.'); | |
return; | |
} | |
for (var i = 0; i < input.length; i++) | |
{ | |
if (typeof num_dict[input[i]] === 'undefined') | |
{ | |
info_text_update('Numbers only, please.'); | |
return; | |
} | |
} | |
console.log(reverse(parse(input))); | |
} | |
function info_text_update(text) | |
{ | |
var info_text_div = document.getElementById('info_text'); | |
info_text_div.innerHTML = text; | |
if (info_text !== text) | |
{ | |
setTimeout(function () { | |
info_text_div.innerHTML = info_text; | |
}, 3000); | |
} | |
} | |
function test() | |
{ | |
var num_strings = ['000000000', '111111111', '490067715']; | |
for (var i = 0; i < num_strings.length; i++) | |
{ | |
console.log(reverse(parse(num_strings[i]))); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<div id="container"> | |
<div id="title_text"> | |
<h2> | |
<a href="http://www.reddit.com/r/dailyprogrammer/comments/2tr6yn/2015126_challenge_199_bank_number_banners_pt_1/" target="_blank">r/Dailyprogrammer Challenge #199 Test Harness</a> | |
</h2> | |
<p>Solution by Michael Repper</p> | |
</div> | |
<div id="web_form"> | |
<form> | |
<input type="text" id="number_input"> | |
<button onclick="verify(); return false;">Parse</button> | |
</form> | |
<div id="info_text"></div> | |
</div> | |
</div> | |
<script> | |
(function(){ | |
info_text = 'Outputs parsed numbers to Console.log()'; | |
info_text_update(info_text); | |
test(); | |
})(); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* r/Dailyprogrammer Challenge #199: Part 1 | |
* | |
* Solution by: Michael Repper | |
* | |
**/ | |
num_dict = { | |
'0' : { | |
0 : ' _ ', | |
1 : '| |', | |
2 : '|_|' | |
}, | |
'1' : { | |
0 : ' ', | |
1 : ' |', | |
2 : ' |' | |
}, | |
'2' : { | |
0 : ' _ ', | |
1 : ' _|', | |
2 : '|_ ' | |
}, | |
'3' : { | |
0 : ' _ ', | |
1 : ' _|', | |
2 : ' _|' | |
}, | |
'4' : { | |
0 : ' ', | |
1 : '|_|', | |
2 : ' |' | |
}, | |
'5' : { | |
0 : ' _ ', | |
1 : '|_ ', | |
2 : ' _|' | |
}, | |
'6' : { | |
0 : ' _ ', | |
1 : '|_ ', | |
2 : '|_|' | |
}, | |
'7' : { | |
0 : ' _ ', | |
1 : ' |', | |
2 : ' |' | |
}, | |
'8' : { | |
0 : ' _ ', | |
1 : '|_|', | |
2 : '|_|' | |
}, | |
'9' : { | |
0 : ' _ ', | |
1 : '|_|', | |
2 : ' |' | |
} | |
}; | |
function parse(numbers) | |
{ | |
var lines = ['', '', '']; | |
var num_len = numbers.length; | |
for (var i = 0; i < num_len; i++) | |
{ | |
lines[0] += num_dict[numbers[i]][0]; | |
lines[1] += num_dict[numbers[i]][1]; | |
lines[2] += num_dict[numbers[i]][2]; | |
} | |
console.log('\n' + lines.join('\n')); | |
return lines; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* r/Dailyprogrammer Challenge #199: Part 2 | |
* | |
* Solution by: Michael Repper | |
* | |
**/ | |
reverse_dict = { | |
' _ ' : { | |
'| |' : { | |
'|_|' : '0' | |
}, | |
' _|' : { | |
'|_ ' : '2', | |
' _|' : '3' | |
}, | |
'|_|' : { | |
'|_|' : '8', | |
' |' : '9' | |
}, | |
'|_ ' : { | |
' _|' : '5', | |
'|_|' : '6' | |
}, | |
' |' : { | |
' |' : '7' | |
} | |
}, | |
' ' : { | |
' |' : { | |
' |' :'1' | |
}, | |
'|_|' : { | |
' |' : '4' | |
} | |
} | |
}; | |
function reverse(strings) | |
{ | |
var acct_num = '', this_index; | |
for (var i = 0; i < 9; i++) | |
{ | |
this_index = i * 3; | |
acct_num += reverse_dict[strings[0].slice(this_index, this_index + 3)][strings[1].slice(this_index, this_index + 3)][strings[2].slice(this_index, this_index + 3)]; | |
} | |
return acct_num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment