tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
12
Task/Rot-13/D/rot-13-1.d
Normal file
12
Task/Rot-13/D/rot-13-1.d
Normal 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
21
Task/Rot-13/D/rot-13-2.d
Normal 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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue