Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 293973

Submitted on 1 Aug 2013 by @bmtran

Correct

19Size
Leading solution size is 18.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
p=1; q=3;
y_correct = 6;
assert(isequal(cantor_rational2index(p,q),y_correct))
ans =
     6
2
Pass
 
%%
p=2; q=3;
y_correct = 9;
assert(isequal(cantor_rational2index(p,q),y_correct))
ans =
     9
3
Pass
 
%%
p=22; q=7;
y_correct = 385;
assert(isequal(cantor_rational2index(p,q),y_correct))
ans =
   385
4
Pass
 
%%
p=355; q=113;
y_correct = 108924;
assert(isequal(cantor_rational2index(p,q),y_correct))
ans =
      108924