Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
March 30th, 2013, 05:32 PM
 fyah17
Registered User

Join Date: Mar 2013
Posts: 3
Time spent in forums: 41 m 40 sec
Reputation Power: 0
Recursive code

Hi can anyone give any tips/ideas on how to generate the following sequence, using recursive calls, where the numbers are actually pixels:

1 2 5 6
3 4 7 8

9 10 13 14
11 12 15 16

It should be able to do it to make bigger squares, but that's basically the flow of the pixels.

The function call may be in the form:

square( initial_x, initial_y, lower_x, lower_y, upper_x, upper_y);

#2
March 30th, 2013, 09:08 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,213
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 4 m 30 sec
Reputation Power: 455
Code:
```   ,./"3 i.2 2 2 2  NB. solution in j, www.jsoftware.com
0  1  4  5
2  3  6  7

8  9 12 13
10 11 14 15

NB. explanation
[A =: i.2 2 2 2  NB. integers, rank 4
0  1
2  3

4  5
6  7

8  9
10 11

12 13
14 15

,./"3 A  NB. stitch the integers at rank 3
0  1  4  5
2  3  6  7

8  9 12 13
10 11 14 15```
__________________
[code]Code tags[/code] are essential for python code!

#3
March 30th, 2013, 09:14 PM
 fyah17
Registered User

Join Date: Mar 2013
Posts: 3
Time spent in forums: 41 m 40 sec
Reputation Power: 0
Thanks for the solution, however I'm really not following..I'm coding in c++ and I don't recognize what's there

#4
March 30th, 2013, 09:32 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,213
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 4 m 30 sec
Reputation Power: 455
The essentials:
j is interactive; the j prompt is three spaces on a new line. New line terminates a j sentence. All the rest is output from the j engine.

#5
March 31st, 2013, 01:31 AM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,264
Time spent in forums: 2 Months 4 Weeks 1 Day 17 h 18 m 9 sec
Reputation Power: 1827
Code:
``` 1  2  5  6
3  4  7  8
9 10 13 14
11 12 15 16```

Where
red is 4^0
blue is 4^1
green is 4^2
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Recursive code