diff options
| -rw-r--r-- | challenge-240/ianrifkin/README.md | 4 | ||||
| -rw-r--r-- | challenge-240/ianrifkin/blog.txt | 1 |
2 files changed, 4 insertions, 1 deletions
diff --git a/challenge-240/ianrifkin/README.md b/challenge-240/ianrifkin/README.md index 9d02e81ab4..a56cf8eeb5 100644 --- a/challenge-240/ianrifkin/README.md +++ b/challenge-240/ianrifkin/README.md @@ -65,7 +65,7 @@ Input: @int = (5, 0, 1, 2, 3, 4) Output: (4, 5, 0, 1, 2, 3) ``` -Doing new[i] = old[old[i]] seemed simple enough but I do have trouble mentally processing where 0 <= i < new.length. If 'i' is a postion of the input array it is always going to be equal to or greater than 0 because of how arrays are numbered. Since each new[i] is mapped to a value calculated from the old array they should naturally end up the same length, so 'i' should never be longer than new.length because 'i' shouldn't be less than old.length either. +Doing new[i] = old[old[i]] seemed simple enough but I do have trouble mentally processing where 0 <= i < new.length. If `i` is a postion of the input array it is always going to be equal to or greater than 0 because of how arrays are numbered. Since each new[i] is mapped to a value calculated from the old array they should naturally end up the same length, so `i` should never be longer than new.length because `i` shouldn't be less than old.length either. With that out of the way, I did a simple for loop using the iterator variable `$i` -- within the loop I am literally just doing the exact mapping from the question: `new[i] = old[old[i]]` @@ -76,6 +76,8 @@ for (my $i = 0; $i < @ints; $i++) { ``` That's it! After the loop I print the new array in the desired format: +``` print "(" . join(', ', @new_ints) . ")\n"; +``` This task sounded more complicated so I will be curious to see if others took a more interesting approach.
\ No newline at end of file diff --git a/challenge-240/ianrifkin/blog.txt b/challenge-240/ianrifkin/blog.txt index e69de29bb2..bc61bb3de3 100644 --- a/challenge-240/ianrifkin/blog.txt +++ b/challenge-240/ianrifkin/blog.txt @@ -0,0 +1 @@ +https://github.com/ianrifkin/perlweeklychallenge-club/blob/ianrifkin-challenge-240/challenge-240/ianrifkin/README.md |
