diff options
| author | irifkin <ianrifkin@ianrifkin.com> | 2023-10-28 17:56:44 -0400 |
|---|---|---|
| committer | irifkin <ianrifkin@ianrifkin.com> | 2023-10-28 17:56:44 -0400 |
| commit | c6e15af7dacac227742bc2253a5223648b2457de (patch) | |
| tree | 280c85dfcc375325e321ae42c6a5d88d92955570 | |
| parent | 5d10a6e13bb7823cc671eec3bd682cef6bed5ef7 (diff) | |
| download | perlweeklychallenge-club-c6e15af7dacac227742bc2253a5223648b2457de.tar.gz perlweeklychallenge-club-c6e15af7dacac227742bc2253a5223648b2457de.tar.bz2 perlweeklychallenge-club-c6e15af7dacac227742bc2253a5223648b2457de.zip | |
formatting of README and link to it
| -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 |
