Cassidooβs Interview question of the week | 444
Hello π This week question is about moving numbers. Here it is. You have a 2D grid of numbers. Write a function that zooms in by an integer factor k >= 2 by turning each cell into a k x k block with...
...and although my implement-the-first-obvious-pattern solution is using 4-nested-loops (YUCK!), I won honorably 2nd place in the ad-hoc contest "Whose implementation is the most inefficient one" that we had on Ruby Users Forum: www.rubyforum.org/t/cassidoo-s...
Join us in next week's question! β€οΈ
21.02.2026 20:22 β π 0 π 0 π¬ 0 π 0
```ruby
module ZoomifyArray
refine Array do
def zoom_in_by(factor)
raise ArgumentError, "Factor MUST be an Integer greater than or equal to 2!" unless factor.is_a?(Integer) && factor >= 2
number_of_rows = size
number_of_cols = first.size
bigger_grid = Array.new(number_of_rows * factor) { Array.new(number_of_cols * factor) }
each_with_index do |row, row_index|
row.each_with_index do |cell, col_index|
0.upto(factor - 1) do |shift_row_index|
0.upto(factor - 1) do |shift_col_index|
bigger_grid[(row_index * factor) + shift_row_index][(col_index * factor) + shift_col_index] = cell
end
end
end
end
bigger_grid
end
end
end
using ZoomifyArray
# A [monkey-patched](rdoc-ref:Answer::Issue20260216::ZoomifyArray), n00by,
# implement-the-first-obvious-pattern, 'Shameless Green', 4-nested-loops (YUCK!)
# version inspired by the recent exposure to Sandi Metzβs 'Smalltalkism' ---
# I really like the idea of sending messages to the objects! π
#
def izkreny_zoom(grid, factor)
grid.zoom_in_by(factor)
end
```
Exposure to the @sandimetz.bsky.social 'Smalltalkism' (via her amazing POOD-I virtual course! πππ) inspired my monkey-patched quite n00bish and 'Shameless Green' answer to this week's @cassidoo.co interview question: BUT it is such a splendid thing to send messages to the objects!!! π₯°ππ
21.02.2026 20:20 β π 2 π 0 π¬ 1 π 0
Thanks and thank you for your writings! ππ
11.02.2026 16:33 β π 2 π 0 π¬ 0 π 0
**Given an integer array and a number `n`, move all of the `n`s to the end of the array while maintaining the relative order of the non-`n`s.**
Bonus: do this without making a copy of the array!
Example:
```
$ moveNums([0,2,0,3,10], 0)
$ [2,3,10,0,0]
```
IMPORTANT: Ruby 3.4+ required because of default `it` block parameter!
Methods used:
* [Enumerable#partition](https://docs.ruby-lang.org/en/master/Enumerable.html#method-i-partition)
* [Array#flatten](https://docs.ruby-lang.org/en/master/Array.html#method-i-flatten)
```ruby
def move_numbers(integer_array, number) = integer_array.partition { it != number }.flatten
p move_numbers([ 0, 2, 0, 3, 10 ], 0) # => [2, 3, 10, 0, 0]
```
NO AI WAS USED IN THE CODING OF THIS SOLUTION! π
Recently, I discovered @cassidoo.co's colorful and beautifully handcrafted website and immediately subscribed to her insightful and funny weekly newsletter. As a bonus, there is an Interview QOTW inside each one, and this is my answer to the last one. More details: gist.github.com/izkreny/fae8...
11.02.2026 14:21 β π 5 π 1 π¬ 1 π 0