www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Where are the solutions for the exercises of the dlang tour???

reply Richter <jmmorales49 gmail.com> writes:
I've been trying to solve the exercise of the caesar encryption 
for practicing with arrays with no luck. I'm new to D

Thanks for your help. :D
Jun 09 2016
parent Seb <seb wilzba.ch> writes:
On Friday, 10 June 2016 at 05:31:18 UTC, Richter wrote:
 I've been trying to solve the exercise of the caesar encryption 
 for practicing with arrays with no luck. I'm new to D

 Thanks for your help. :D
1) First of all - sorry that you couldn't find the solution. The tour is still heavily worked on, hence I opened an issue for you https://github.com/stonemaster/dlang-tour/issues/226 2) The example isn't that good, because neither loops nor ranges have been exampled before. However that being said, here's my solution to the task. It's a bit more advanced as it uses `map`, but it also shows the power of D: ``` import std.array: array; import std.algorithm: map; return input.map!((x) => cast(char) (((x - 97) + shift) % 26 + 97)).array; ``` For more info, see: https://dlang.org/phobos/std_algorithm_iteration.html#.map (I opened another issue for this - https://github.com/stonemaster/dlang-tour/issues/227) => continue to rock with D and let us know all the rough corners that you encounter. Thanks again!
Jun 10 2016