24
1
You must use one language to write programs that perform the following nine tasks, in any order you want.
- Convert an inputted number from base 10 to base 36.
- Sample input:
1000
- Sample output:
RS
(output must be upper case)
- Sample input:
- Convert each character in a string to its base 10 decimal ASCII codes and print the codes concatenated together.
- Sample input:
Scrambled 3GG5
- Sample output:
839911497109981081011002051717153
- Sample input:
- Determine if an inputted number is divisible by 1738.
- Return a truthy value if it is and a falsy value if it isn't.
- Determine if a string has the letter
q
in it.- Return a truthy value if it does and a falsy value if it doesn't.
- Encode an inputted string of letters with a Caesar cipher of +1.
- Case must be preserved. Non-letter characters will be printed without modification.
- Sample input:
Good morning, World!
- Sample output:
Hppe npsojoh, Xpsme!
- Find and print the sum of the prime factors of a number.
- Sample input:
1320
- Sample output:
21
- Sample input:
- Print
PPCG
. - Print the first
n
positive integers that are divisible byfloor(sqrt(n))
.n
is an inputted integer.
- Replace every
o
andO
in an inputted string withಠ
.- Sample input:
Onomatopoeia
- Sample output:
ಠnಠmatಠpಠeia
- Sample input:
You will have noticed that this challenge is Code Billiards
, not Code Golf
. The objective of this challenge, like in billiards, is to set up your code so it can be modified only slightly for the next challenge. This is why your programs do not have to solve the above tasks in order.
Your score is determined as follows
- Your score goes up by
1
each byte in your programs. - Your score goes up by
floor(n^(1.5))
if two consecutive programs have a Levenshtein distance ofn
. For example if your first program ispotato
and your second program istaters
, your score goes up by 12 for 12 bytes and by11
=floor(5^(1.5))
for a Levenshtein distance of 5.
The objective of this challenge is to have as low a score as possible after all nine programs have been written. Standard CG rules apply.
To see the leaderboard, click "Show code snippet", scroll to the bottom and click "► Run code snippet". Snippet made by Optimizer.
/* Configuration */
var QUESTION_ID = 63675; // Obtain this from the url
// It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 43444; // This should be the user ID of the challenge author.
/* App */
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) {
return "http://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}
function commentUrl(index, answers) {
return "http://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}
function getAnswers() {
jQuery.ajax({
url: answersUrl(answer_page++),
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
answers.push.apply(answers, data.items);
answers_hash = [];
answer_ids = [];
data.items.forEach(function(a) {
a.comments = [];
var id = +a.share_link.match(/\d+/);
answer_ids.push(id);
answers_hash[id] = a;
});
if (!data.has_more) more_answers = false;
comment_page = 1;
getComments();
}
});
}
function getComments() {
jQuery.ajax({
url: commentUrl(comment_page++, answer_ids),
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(c) {
if (c.owner.user_id === OVERRIDE_USER)
answers_hash[c.post_id].comments.push(c);
});
if (data.has_more) getComments();
else if (more_answers) getAnswers();
else process();
}
});
}
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
function getAuthorName(a) {
return a.owner.display_name;
}
function process() {
var valid = [];
answers.forEach(function(a) {
var body = a.body;
a.comments.forEach(function(c) {
if(OVERRIDE_REG.test(c.body))
body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
});
var match = body.match(SCORE_REG);
if (match)
valid.push({
user: getAuthorName(a),
size: +match[2],
language: match[1],
link: a.share_link,
});
else console.log(body);
});
valid.sort(function (a, b) {
var aB = a.size,
bB = b.size;
return aB - bB
});
var languages = {};
var place = 1;
var lastSize = null;
var lastPlace = 1;
valid.forEach(function (a) {
if (a.size != lastSize)
lastPlace = place;
lastSize = a.size;
++place;
var answer = jQuery("#answer-template").html();
answer = answer.replace("{{PLACE}}", lastPlace + ".")
.replace("{{NAME}}", a.user)
.replace("{{LANGUAGE}}", a.language)
.replace("{{SIZE}}", a.size)
.replace("{{LINK}}", a.link);
answer = jQuery(answer);
jQuery("#answers").append(answer);
var lang = a.language;
lang = jQuery('<a>'+lang+'</a>').text();
languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
});
var langs = [];
for (var lang in languages)
if (languages.hasOwnProperty(lang))
langs.push(languages[lang]);
langs.sort(function (a, b) {
if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
return 0;
});
for (var i = 0; i < langs.length; ++i)
{
var language = jQuery("#language-template").html();
var lang = langs[i];
language = language.replace("{{LANGUAGE}}", lang.lang)
.replace("{{NAME}}", lang.user)
.replace("{{SIZE}}", lang.size)
.replace("{{LINK}}", lang.link);
language = jQuery(language);
jQuery("#languages").append(language);
}
}
body { text-align: left !important}
#answer-list {
padding: 10px;
width: 290px;
float: left;
}
#language-list {
padding: 10px;
width: 290px;
float: left;
}
table thead {
font-weight: bold;
}
table td {
padding: 5px;
}
<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="language-list">
<h2>Shortest Solution by Language</h2>
<table class="language-list">
<thead>
<tr><td>Language</td><td>User</td><td>Score</td></tr>
</thead>
<tbody id="languages">
</tbody>
</table>
</div>
<div id="answer-list">
<h2>Leaderboard</h2>
<table class="answer-list">
<thead>
<tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
</thead>
<tbody id="answers">
</tbody>
</table>
</div>
<table style="display: none">
<tbody id="answer-template">
<tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
</tbody>
</table>
<table style="display: none">
<tbody id="language-template">
<tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
</tbody>
</table>
1Whoa... I literally had the EXACT same idea for a challenge last night. How weird... – ETHproductions – 2015-11-12T17:21:47.043
@ETHproductions I got the idea last night as well, and wrote something about it on the Sandbox. Did your idea come from there? If not, the coincidence is really funny. – Arcturus – 2015-11-12T17:27:51.323
1No, I had the idea as I was on my way to bed. Didn't see your post at all! I guess this is an example of "code-golf minds think alike" ;) – ETHproductions – 2015-11-12T17:29:16.943
What's the Levenshtein-distance of
ಠ
anda
? Is it 1 (countingಠ
as 1 char) or 2 (becauseಠ
is actually 2 bytes)? – Jakube – 2015-11-13T14:26:32.073What's the Caesar-Chiphre of "zZ"?. Is it "aA" or "Aa"? – Jakube – 2015-11-13T14:34:22.777
@Jakube
Aa
. Capitalization is held constant. Since it is a substitution, the distance is 1. – Arcturus – 2015-11-13T15:49:25.200So which is it?
Aa
has the inverse capitalization ofzZ
. – Lynn – 2015-11-13T17:12:55.613@Mego Well, it's kind of slow. – SuperJedi224 – 2015-11-13T20:13:14.197
1
@Mego Here's a faster algorithm. :) Also, you may not have seen this, but in my answer is a snippet that automatically arranges the programs in the optimal order, and it uses the super-fast algorithm, too.
– ETHproductions – 2015-11-14T05:13:22.163