Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active September 7, 2019 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/fea05da5c6b9be112d47d6c896dd8ad6 to your computer and use it in GitHub Desktop.
Save havenwood/fea05da5c6b9be112d47d6c896dd8ad6 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'minitest/autorun'
def intelo(foo, bar)
head = foo.flat_map.with_index do |n, i|
[n, bar[i * 2, 2]]
end
tail = bar[head.size..-1].to_a
(head + tail).flatten.compact
end
describe "Intelo's problem" do
it 'is as desired' do
assert_equal [], intelo([], [])
assert_equal [1, 2, 3, 4], intelo([], [1, 2, 3, 4])
assert_equal [1, 2, 3, 4], intelo([1], [2, 3, 4])
assert_equal [1, 3, 4, 2], intelo([1, 2], [3, 4])
assert_equal [1, 4, 2, 3], intelo([1, 2, 3], [4])
assert_equal [1, 2, 3, 4], intelo([1, 2, 3, 4], [])
end
end
@havenwood
Copy link
Author

Running:

.

Finished in 0.000796s, 1256.2814 runs/s, 7537.6884 assertions/s.
1 runs, 6 assertions, 0 failures, 0 errors, 0 skips

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment