Menu
Home
Create new Paste
Log in
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
import std.stdio, std.algorithm, std.range; void main(string[] args) { stdin.byLine .map!nibbleSwapper .joiner("\n") .copy(stdout.lockingTextWriter()); } auto nibbleSwapper(R)(R range) if (isForwardRange!R) { // This won't work as chunk uses Take and a Take range is not bidirectional //return range.chunks(2).map!(chunk => chunk.retro).joiner; // Resorting to cycle.dropOne.takeExactly means that we will produce incorrect output if // the range has an odd number of elements, e.g.: // // abcde => badcee assert((range.walkLength & 1) == 0, "nibbleSwapper only works on ranges with an even length"); return range.chunks(2).map!(chunk => chunk.cycle.dropOne.takeExactly(2)).joiner; }
Result:
Success
/
Return code: 0
Application output:
badc 2143
Application input:
abcd 1234
Paste info
Author:
Guest
Views:
574
Private:
no
Expires:
Never
Uploaded:
11.12.13 0:25
Parent:
#f228d0a8
Votes
:
0
Tweet
Compilation
Compiler:
DMD 2.079.1 ( 2.079.1 )
Pointer size:
m64
Actions
Download
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason