Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

12
Task/Rot-13/D/rot-13-1.d Normal file
View file

@ -0,0 +1,12 @@
import std.stdio;
import std.ascii: letters, U = uppercase, L = lowercase;
import std.string: makeTrans, translate;
immutable r13 = makeTrans(letters,
//U[13 .. $] ~ U[0 .. 13] ~
U[13 .. U.length] ~ U[0 .. 13] ~
L[13 .. L.length] ~ L[0 .. 13]);
void main() {
writeln("This is the 1st test!".translate(r13, null));
}

21
Task/Rot-13/D/rot-13-2.d Normal file
View file

@ -0,0 +1,21 @@
import std.stdio, std.string, std.traits;
pure S rot13(S)(in S s) if (isSomeString!S) {
return rot(s, 13);
}
pure S rot(S)(in S s, in int key) if (isSomeString!S) {
auto r = s.dup;
foreach (i, ref c; r) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26 + 'A');
}
return cast(S) r;
}
void main() {
"Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt!".rot13().writeln();
}