Please help me with solving this array problem (Min Steps in Infinite Grid) (Page 1) ● SmileBASIC Source Forums

Register
• #2 ✎ 173 Nathaniel Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements Scholar Received for knowing a great deal about programming topics Achievements Final(?) Contest Winner I won the (possibly) final SmileBASIC Source Contest! October 2018 Programming Contest Here's a simple solution: ```ACLS 'SETUP RESTORE @POINTS READ NUMBER DIM POINTS_XY[NUMBER*2] FOR I=0 TO NUMBER*2-1 READ POINTS_XY[I] NEXT 'OUTPUT ?MIN_STEPS(POINTS_XY) 'FUNCTION DEF MIN_STEPS(ARRAY_XY) VAR I,STEPS,LENGTH=LEN(ARRAY_XY)/2-1 FOR I=0 TO LENGTH-1 VAR DIST_X=ABS(ARRAY_XY[I*2 ]-ARRAY_XY[I*2+2]) VAR DIST_Y=ABS(ARRAY_XY[I*2+1]-ARRAY_XY[I*2+3]) INC STEPS,MAX(DIST_X,DIST_Y) NEXT RETURN STEPS END 'INPUT @POINTS DATA 3 'NUMBER OF POINTS DATA 0,0 DATA 1,1 DATA 1,2``` Posted Edited by Nathaniel
Here's a simple solution: ```ACLS 'SETUP RESTORE @POINTS READ NUMBER DIM POINTS_XY[NUMBER*2] FOR I=0 TO NUMBER*2-1 READ POINTS_XY[I] NEXT 'OUTPUT ?MIN_STEPS(POINTS_XY) 'FUNCTION DEF MIN_STEPS(ARRAY_XY) VAR I,STEPS,LENGTH=LEN(ARRAY_XY)/2-1 FOR I=0 TO LENGTH-1 VAR DIST_X=ABS(ARRAY_XY[I*2 ]-ARRAY_XY[I*2+2]) VAR DIST_X=ABS(ARRAY_XY[I*2+1]-ARRAY_XY[I*2+3]) INC STEPS,MAX(DIST_X,DIST_Y) NEXT RETURN STEPS END 'INPUT @POINTS DATA 3 'NUMBER OF POINTS DATA 0,0 DATA 1,1 DATA 1,2```
• #4 ✎ 1658 12Me21 Head Admin Third Year My account is over 3 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself I believe this should work: ```DIM TEST[3,2] COPY TEST,@POINTS ?STEPS(TEST) @POINTS DATA 0,0 DATA 1,1 DATA 1,2 DEF STEPS(POINTS[]) VAR SUM=0 VAR I FOR I=1 TO LEN(POINTS)/2-1 INC SUM,MAX(ABS(POINTS[I,0]-POINTS[I-1,0]),ABS(POINTS[I,1]-POINTS[I-1,1])) NEXT RETURN SUM END ``` EDIT: I didn't look at Nathaniel's answer until after I posted this, and it turns out he did basically the same thing. Posted Edited by 12Me21