15
1
There exists a very simple cipher that replaces a letter with it's position in the alphabet. For example, abc
would become 1 2 3
in this cipher.
This challenge is an alternative take on this cipher.
The Challenge
Create a program that takes an input of ASCII characters, and outputs a space-separated string of:
integers
-26
through26
letters
a
throughj
The output should come through STDOUT or your language's closest alternative.
Specifications
Capital letters should be negated. A capital
D
for example would be-4
, while a lowercased
would be4
.Digits should be changed to their alpha counterparts.
1
beinga
, and so on. Any zeroes in the input will bej
.All non-alphanumeric characters (except spaces) should be ignored.
Spaces are
0
.Adjacent spaces in the output should be reduced to a single space.
Input: You + Me Correct Output: -25 15 21 0 -13 5 Incorrect Output: -25 15 21 0 0 0 -13 5
A single trailing space or newline is allowed.
Examples
Input: programming puzzles
Output: 16 18 15 7 18 1 13 13 9 14 7 0 16 21 26 26 12 5 19
Input: Code Golf
Output: -3 15 4 5 0 -7 15 12 6
Input: Programming Puzzles & Code Golf
Output: -16 18 15 7 18 1 13 13 9 14 7 0 -16 21 26 26 12 5 19 0 -3 15 4 5 0 -7 15 12 6
Input: C0d3 G0lf
Output: -3 j 4 c 0 -7 j 12 6
Input: abc_ABC
Output: 1 2 3 -1 -2 -3
Scoreboard
For your score to appear on the board, it should be in this format:
# Language, Bytes
Strikethroughs shouldn't cause a problem.
function getURL(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){$.ajax({url:getURL(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),useData(answers)}})}function getOwnerName(e){return e.owner.display_name}function useData(e){var s=[];e.forEach(function(e){var a=e.body.replace(/<s>.*<\/s>/,"").replace(/<strike>.*<\/strike>/,"");console.log(a),VALID_HEAD.test(a)&&s.push({user:getOwnerName(e),language:a.match(VALID_HEAD)[1],score:+a.match(VALID_HEAD)[2],link:e.share_link})}),s.sort(function(e,s){var a=e.score,r=s.score;return a-r}),s.forEach(function(e,s){var a=$("#score-template").html();a=a.replace("{{RANK}}",s+1+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SCORE}}",e.score),a=$(a),$("#scores").append(a)})}var QUESTION_ID=58107,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],answer_ids,answers_hash,answer_page=1;getAnswers();var VALID_HEAD=/<h\d>([^\n,]*)[, ]*(\d+).*<\/h\d>/;
body{text-align:left!important}table thead{font-weight:700}table td{padding:10px 0 0 10px}#scores-cont{padding:10px;width:600px}#scores tr td:first-of-type{padding-left:0}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><div id="scores-cont"><h2>Scores</h2><table class="score-table"><thead> <tr><td></td><td>User</td><td>Language</td><td>Score</td></tr></thead> <tbody id="scores"></tbody></table></div><table style="display: none"> <tbody id="score-template"><tr><td>{{RANK}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SCORE}}</td></tr></tbody></table>
1
Related: http://codegolf.stackexchange.com/q/12253/4372
– daniero – 2015-09-16T20:26:49.307Can the output have a trailing space? – Dennis – 2015-09-16T22:35:33.837
Yes. A single trailing space or newline is allowed. @Dennis – Zach Gates – 2015-09-16T22:37:34.340
Is a function returning/printing a string a valid answer? Also can you add a test case like "abc_ABC" to rule out all the [^\w] and [\W] regex? – Max – 2015-09-17T07:46:24.823
I wasn't entirely sure what you were asking, but I've added that test case. I hope that's what you were looking for; if not, let me know. @Max – Zach Gates – 2015-09-17T12:11:43.143