Perl Weekly Challenge 70: Character Swapping and Gray Code Sequence
These are some answers to the Week 70 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Task 1: Character Swapping
You are given a string $S of size $N.
You are also given swap count $C and offset $O such that $C >= 1, $O >= 1, $C <= $O and $C + $O <= $N.
Write a script to perform character swapping like below:
$S[ 1 % $N ] <=> $S[ (1 + $O) % $N ]
$S[ 2 % $N ] <=> $S[ (2 + $O) % $N ]
$S[ 3 % $N ] <=> $S[ (3 + $O) % $N ]
...
...
$S[ $C % $N ] <=> $S[ ($C + $O) % $N ]
Example 1:

