Go Tour Slices Exercise logic

Do I need to create a for loop in which I assign every element of my slice to a value in the range of dx?

Yes:

  • an outer loop to assign a[x] with a []uint8 slice of dx size,
  • with an inner loop 'y' for each element a[x] (which is a []uint8) in order to assign a[x][y] with the asked value (ie, one of the "interesting functions" like x^y, (x+y)/2, and x*y).
    x and y are indexes in a range over a slice (a, then a[x]): see "For statements".

I like (x ^ y) * (x ^ y):

res

As rwilson04 comments below:

x*x + y*y is another good one

x square plus y square

Tags:

Slice

Go