39
2
In this challenge, you need to solve 4 different tasks using the same set of characters. You can rearrange the characters, but you can't add or remove characters.
The winner will be the submission that solves all tasks using the smallest number of characters. All tasks must be solved in the same language.
Note that it's the smallest number of characters, not the smallest number of unique characters.
Task 1:
Output the first N
numbers of every third composite number. The codeblock below shows the first 19 composite numbers in the first row, and every third composite number on the row below.
4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30
4, 9, 14, 18, 22, 26, 30
If N=5
then the output should be 4, 9, 14, 18, 22
. You must support 1<=N<=50
.
Composite numbers are positive numbers that aren't prime numbers or 1.
The result for N=50
is:
4, 9, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 57, 62, 65, 69, 74, 77, 81, 85, 88, 92, 95, 99, 104, 108, 112, 116, 119, 122, 125, 129, 133, 136, 141, 144, 147, 152, 155, 159, 162, 166, 170, 174, 177, 182, 185, 188, 192
Task 2:
Output a N-by-N
multiplication table. You must support 1<=N<=20
Example:
N = 4
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16
The output format is optional, the following is acceptable output [[1,2,3,4],[2,4,6,8],[3,6,9,12],[4,8,12,16]]
.
Task 3:
Determine if a number is a Fibonacci number. You must support positive N
up to the default integer limit of your language. If there are both 32-bit integers and 64-bit integers then you can choose to use the one that requires the shortest code. For instance, use int
instead of long int
if you have the choice. You can not choose a smaller integers than 32-bit unless that's default (you can't use 8-bit integers if 32-bit is default).
true/false
, false/true
, 1/0
, 1/-1
, a/b
are all acceptable output as long as it's consistent.
Task 4:
Take N
as input and output the result of 1^1+2^2+3^3+...N^N
. You must support 1<=N<=10
.
The 10 different results are:
1, 5, 32, 288, 3413, 50069, 873612, 17650828, 405071317, 10405071317
This is code-golf, so the shortest submission in each language wins!
This Stack Snippet will help check your solution. It measures the minimum set of characters needed to include all four solutions, and shows the leftover characters.
function update() {
var m = {};
var a = [q1.value, q2.value, q3.value, q4.value];
var o = [{}, {}, {}, {}]
for (var i = 0; i < 4; i++) {
for (var j = 0; j < a[i].length; j++) o[i][a[i][j]] = -~o[i][a[i][j]];
for (var c in o[i]) if (!(o[i][c] < m[c])) m[c] = o[i][c];
}
var t = 0;
for (var c in m) t += m[c];
for (var i = 0; i < 4; i++) {
t += "\n";
for (var c in m) t += c.repeat(m[c] - ~~o[i][c]);
}
p.textContent = t;
}
<div oninput="update();">
<textarea id="q1"></textarea>
<textarea id="q2"></textarea>
<textarea id="q3"></textarea>
<textarea id="q4"></textarea>
</div>
<pre id="p"></pre>
1Binary: two characters – coredump – 2017-01-09T10:24:07.687
@coredump Yes, two unique characters... – Stewie Griffin – 2017-01-09T10:28:02.510