Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
18
Task/Fractran/D/fractran-1.d
Normal file
18
Task/Fractran/D/fractran-1.d
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import std.stdio, std.algorithm, std.conv, std.array;
|
||||
|
||||
void fractran(in string prog, int val, in uint limit) {
|
||||
const fracts = prog.split.map!(p => p.split("/").to!(int[])).array;
|
||||
|
||||
foreach (immutable n; 0 .. limit) {
|
||||
writeln(n, ": ", val);
|
||||
const found = fracts.find!(p => val % p[1] == 0);
|
||||
if (found.empty)
|
||||
break;
|
||||
val = found.front[0] * val / found.front[1];
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
fractran("17/91 78/85 19/51 23/38 29/33 77/29 95/23
|
||||
77/19 1/17 11/13 13/11 15/14 15/2 55/1", 2, 15);
|
||||
}
|
||||
26
Task/Fractran/D/fractran-2.d
Normal file
26
Task/Fractran/D/fractran-2.d
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import std.stdio, std.algorithm, std.conv, std.array, std.range;
|
||||
|
||||
struct Fractran {
|
||||
int front;
|
||||
bool empty = false;
|
||||
const int[][] fracts;
|
||||
|
||||
this(in string prog, in int val) {
|
||||
this.front = val;
|
||||
fracts = prog.split.map!(p => p.split("/").to!(int[])).array;
|
||||
}
|
||||
|
||||
void popFront() {
|
||||
const found = fracts.find!(p => front % p[1] == 0);
|
||||
if (found.empty)
|
||||
empty = true;
|
||||
else
|
||||
front = found.front[0] * front / found.front[1];
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
Fractran("17/91 78/85 19/51 23/38 29/33 77/29 95/23
|
||||
77/19 1/17 11/13 13/11 15/14 15/2 55/1", 2)
|
||||
.take(15).writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue