5 kyu

Eight ways to iterate over table

41 of 129mugiseyebrows

Description:

Problem

Since table has four corners, there are eight ways to iterate over its' elements ((by rows then by columns | by columns then by rows) * (top left to bottom right | top right to bottom left | bottom left to top right | bottom right to top left)).

Implement forward iterator that can be constucted with two directions as parameters that returns table items in specified order. (c++: implement begin(dir0,dir1) and end() functions, python: implement walk(dir0,dir1) function)

For example iterator with directions up left must return (one by one):

9, 6, 3, 8, 5, 2, 7, 4, 1

for table

{{1,2,3},
 {4,5,6},
 {7,8,9}}

For simplicity lets assume that table have at least one row and at least one column and we dont need to test for that.

C++

Iterator must support assignment.

Python

Iterator must be lazy (assuming Table.data have __getitem__(key) and __len__() implemented on both dimensions).

Iterators
Algorithms

Stats:

CreatedMay 11, 2018
PublishedMay 11, 2018
Warriors Trained818
Total Skips115
Total Code Submissions1614
Total Times Completed129
C++ Completions41
Python Completions91
Total Stars33
% of votes with a positive feedback rating97% of 32
Total "Very Satisfied" Votes30
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes0
Total Rank Assessments7
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • mugiseyebrows Avatar
  • Blind4Basics Avatar
Ad