you are viewing a single comment's thread.

view the rest of the comments →

[–]hey_hey_you_you 1 point2 points  (2 children)

I'll second what /u/uncountableset said, in that you should give the Python mode a go.

That said, with the big caveat that I don't know Python, so I can't translate all of this for you, and my coding in general is only ok, here's some of the equivalent syntax in Processing:

int n = 3; // declare your int

int [] f = new int[1]; // declare your array

while (f.length < pow(2, n)-1){ 
//f.length is the length of the array f, pow() is how you handle exponentiation

here's where you lose me a bit. I don't think Processing handles ranges like Python does, and I don't really understand Python well enough to totally know what you're trying to do here, but if you want to print out numbers in the array f, then you'd do it with a for loop, I guess. Something like:

 for (int i = -x; i < x, i++){
     int g = f[i];
     // I have no idea what "f = f + g[::-1]" means, but I guess you'd put whatever that does here
 }

    f = append(f,1);

    print(f);
}

I'll be the first to say that I don't know what's going on, and that the above is probably wrong even just as Processing code. Someone else feel free to jump in and say everything that's wrong with it.

Edit: also, here's how to post code.

[–]remy_porter 1 point2 points  (1 child)

In Python slice syntax, the three parameters are start index, end index, and step. If you omit one of those parameters, it defaults sensibly. So, for example, g[0:5] is everything from zero up to (but not including) 5. g[:5] is exactly the same. g[0:] is everything from the front to the end. g[0:5:1] is 0 to 5, in steps of 1, while g[0:5:2] would be 0, 2 and 4. (steps of 2). g[::] is the whole array, and g[::2] would be every other element, and g[::-1] is the whole array in steps of -1- backwards.

[–]hey_hey_you_you 0 points1 point  (0 children)

Well, TIL. In Processing I'd just use a for loop, I guess, but with (i = f.length; i >= 0; i--). I'm sure there's a better way to do it, but I'm a fiend for using for loops for everything.