You have to write a function/program that takes input via the
stdin/command-line arguments/function arguments, mixes up characters in a string, and then output the final string via the
Input will first contain a string (not empty or
null), a space, and then an even number of non-negative numbers all separated by spaces. If input is taken via function arguments, the string will be the one of the arguments while the integers, which are seperated by a space, will be the other. You must swap the characters of the string at the indices corresponding to consecutive pairs of numbers.
Hello_world! 0 6
must result in
- You may choose between 0-based and 1-based indexing, and may assume that the given indexes will always be in range.
- The string will not be longer than 100 characters and will only contain ASCII characters in range
~(character codes 0x21 to 0x7E, inclusive). See ASCII table for reference.
- The two indices in a pair may be identical (in which case, nothing is swapped in that step).
This is code golf, so the shortest submission (in bytes) wins.
Hello_world! 0 6 => wello_Horld! First 1 2 1 0 0 4 => tFisr (Second!$$) 8 7 10 1 => ()econd$!$S ~Third~ 0 0 6 6 0 6 6 0 => ~Third~