5 edited body
source | link

Background

Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance:

|              BA              |
[0   0   0   0   1   2   3   0]
               |     AB     | 

Now say, we split the array BA into consecutive subarrays of length d (with a shorter final array, if the d doesn't divide the length of BA). For d = 3:

[0   0   0   0   1   2   3   0]
           |           |
[0   0   0] [0   1   2] [3   0]

And now sum up each of those arrays:

[0 3 3]

And discard zero sums:

[3 3]

The Challenge

You're to write a function which prints that final array of sums in any convenient array format, given the following 5 parameters (or any subset thereof, if you don't need all of them):

  • The small array B.
  • The size of the small array B (3 in the above example).
  • The size of the big array A (8 in the above example).
  • The index where the small array begins (4 in the above example).
  • The length d of the subarrays (3 in the above example).

The Rules

  • You are not allowed to construct the big array A explicitly!
  • You are not allowed to construct any of the subarrays of length d explicitly!
  • That means you have to get the computation directly from the B and the other parameters at your disposal!

Fewest characters wins!

Background

Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance:

|              B              |
[0   0   0   0   1   2   3   0]
               |     A     | 

Now say, we split the array B into consecutive subarrays of length d (with a shorter final array, if the d doesn't divide the length of B). For d = 3:

[0   0   0   0   1   2   3   0]
           |           |
[0   0   0] [0   1   2] [3   0]

And now sum up each of those arrays:

[0 3 3]

And discard zero sums:

[3 3]

The Challenge

You're to write a function which prints that final array of sums in any convenient array format, given the following 5 parameters (or any subset thereof, if you don't need all of them):

  • The small array B.
  • The size of the small array B (3 in the above example).
  • The size of the big array A (8 in the above example).
  • The index where the small array begins (4 in the above example).
  • The length d of the subarrays (3 in the above example).

The Rules

  • You are not allowed to construct the big array A explicitly!
  • You are not allowed to construct any of the subarrays of length d explicitly!
  • That means you have to get the computation directly from the B and the other parameters at your disposal!

Fewest characters wins!

Background

Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance:

|              A              |
[0   0   0   0   1   2   3   0]
               |     B     | 

Now say, we split the array A into consecutive subarrays of length d (with a shorter final array, if the d doesn't divide the length of A). For d = 3:

[0   0   0   0   1   2   3   0]
           |           |
[0   0   0] [0   1   2] [3   0]

And now sum up each of those arrays:

[0 3 3]

And discard zero sums:

[3 3]

The Challenge

You're to write a function which prints that final array of sums in any convenient array format, given the following 5 parameters (or any subset thereof, if you don't need all of them):

  • The small array B.
  • The size of the small array B (3 in the above example).
  • The size of the big array A (8 in the above example).
  • The index where the small array begins (4 in the above example).
  • The length d of the subarrays (3 in the above example).

The Rules

  • You are not allowed to construct the big array A explicitly!
  • You are not allowed to construct any of the subarrays of length d explicitly!
  • That means you have to get the computation directly from the B and the other parameters at your disposal!

Fewest characters wins!

4 tidy up explanation
source | link

Shortest programmprogram to split special array

The challengeBackground

write a function

func(small_array, size_bigarray, divisor, index_where_small_array_begins, size_smallarray)

The function does the following:

Imagine a big array with size bigarray. (you don't, you have thea big array explicity)

It is filled with zeros. Except from index_where_small_array_begins the values of the big_arrayA are identically with, which is mostly zeroes, but contains a short subarray small_array.

small_arrayB containswhich has only strictly positive numbersentries. (not zero)For instance:

So small_array is a part of big_array. (you can assume it fits, that means index_where_small_array_begins + size_smallarray <= size_bigarray)

|              B              |
[0   0   0   0   1   2   3   0]
               |     A     | 

Now say, we split the big_array inarray mini_arraysB into consecutive subarrays of sizelength divisord. (If divisor is notwith a divisor of size_bigarray, the lastshorter final array is smaller)

(Example size_bigarray = 10, divisor = 3, then you have four arrays of size: 3, 3, 3, 1)

For each of the mini_array you addif the values together, call it sum_of_the_miniarray.

Print out an array with sum_of_the_miniarray for all miniarraysd for whichdoesn't divide the length of sum_of_the_miniarrayB is nonzero). (You can conclude that from index_where_small_array_begins andFor size_smallarrayd = 3)

Example: Given:

small_array[0 = [1,2,3]
index_where_small_array_begins =0 4
size_bigarray = 8
divisor0 = 3

then big_array would be:

big_array = [0,0,0,0,   1,   2,   3,   0]

the mini arrays would be

           |           |
[0,   0,   0] [0,   1,   2] [3,   0]

the sums would beAnd now sum up each of those arrays:

0[0 3 33]

But you only output [3,3] because the first one isAnd discard zero. sums:


 
[3 3]

The rulesChallenge

You are not allowedYou're to construct the bigwrite a function which prints that final array explicitly!

You are not allowed to constructof sums in any convenient array format, given the mini arrays explicitly!

That meansfollowing 5 parameters (or any subset thereof, if you have to get the computation directly from the small_array!don't need all of them):

  • The small array B.
  • The size of the small array B (3 in the above example).
  • The size of the big array A (8 in the above example).
  • The index where the small array begins (4 in the above example).
  • The length d of the subarrays (3 in the above example).

The Rules

  • You are not allowed to construct the big array A explicitly!
  • You are not allowed to construct any of the subarrays of length d explicitly!
  • That means you have to get the computation directly from the B and the other parameters at your disposal!

Fewest characters wins!

Good luck!

Shortest programm to split special array

The challenge

write a function

func(small_array, size_bigarray, divisor, index_where_small_array_begins, size_smallarray)

The function does the following:

Imagine a big array with size bigarray. (you don't have the array explicity)

It is filled with zeros. Except from index_where_small_array_begins the values of the big_array are identically with small_array.

small_array contains only positive numbers. (not zero)

So small_array is a part of big_array. (you can assume it fits, that means index_where_small_array_begins + size_smallarray <= size_bigarray)

Now split the big_array in mini_arrays of size divisor. (If divisor is not a divisor of size_bigarray, the last array is smaller)

(Example size_bigarray = 10, divisor = 3, then you have four arrays of size: 3, 3, 3, 1)

For each of the mini_array you add the values together, call it sum_of_the_miniarray.

Print out an array with sum_of_the_miniarray for all miniarrays for which the sum_of_the_miniarray is nonzero. (You can conclude that from index_where_small_array_begins and size_smallarray)

Example: Given:

small_array = [1,2,3]
index_where_small_array_begins = 4
size_bigarray = 8
divisor = 3

then big_array would be:

big_array = [0,0,0,0,1,2,3,0]

the mini arrays would be

[0,0,0] [0,1,2] [3,0]

the sums would be

0 3 3

But you only output [3,3] because the first one is zero.


 

The rules

You are not allowed to construct the big array explicitly!

You are not allowed to construct the mini arrays explicitly!

That means you have to get the computation directly from the small_array!

Fewest characters wins!

Good luck!

Shortest program to split special array

Background

Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance:

|              B              |
[0   0   0   0   1   2   3   0]
               |     A     | 

Now say, we split the array B into consecutive subarrays of length d (with a shorter final array, if the d doesn't divide the length of B). For d = 3:

[0   0   0   0   1   2   3   0]
           |           |
[0   0   0] [0   1   2] [3   0]

And now sum up each of those arrays:

[0 3 3]

And discard zero sums:

[3 3]

The Challenge

You're to write a function which prints that final array of sums in any convenient array format, given the following 5 parameters (or any subset thereof, if you don't need all of them):

  • The small array B.
  • The size of the small array B (3 in the above example).
  • The size of the big array A (8 in the above example).
  • The index where the small array begins (4 in the above example).
  • The length d of the subarrays (3 in the above example).

The Rules

  • You are not allowed to construct the big array A explicitly!
  • You are not allowed to construct any of the subarrays of length d explicitly!
  • That means you have to get the computation directly from the B and the other parameters at your disposal!

Fewest characters wins!

    Tweeted twitter.com/#!/StackCodeGolf/status/536944788902522881
3 added 23 characters in body
source | link

The challenge:

The challenge

write a function func(small_array, size_bigarray, divisor, index_where_small_array_begins, size_smallarray):

func(small_array, size_bigarray, divisor, index_where_small_array_begins, size_smallarray)

The function does the following:

Imagine a big array with size bigarray. (you don't have the array explicity)

It is filled with zeros. Except from index_where_small_array_begins the values of the big_array are identically with small_array.

small_array contains only positive numbers. (not zero)

So small_array is a part of big_array. (you can assume it fits, that means index_where_small_array_begins + size_smallarray <= size_bigarray)

Now split the big_array in mini_arrays of size divisor. (If divisor is not a divisor of size_bigarray, the last array is smaller)

(Example size_bigarray = 10, divisor = 3, then you have four arrays of size: 3, 3, 3, 1)

For each of the mini_array you add the values together, call it sum_of_the_miniarray.

Print out an array with sum_of_the_miniarray for all miniarrays for which the sum_of_the_miniarray is nonzero. (You can conclude that from index_where_small_array_begins and size_smallarray)

Example: Given: small_array = [1,2,3] index_where_small_array_begins = 4 size_bigarray = 8 divisor = 3 then

small_array = [1,2,3]
index_where_small_array_begins = 4
size_bigarray = 8
divisor = 3

then big_array would be: big_array = [0,0,0,0,1,2,3,0] the

big_array = [0,0,0,0,1,2,3,0]

the mini arrays would be

[0,0,0] [0,1,2] [3,0]

[0,0,0] [0,1,2] [3,0]

the sums would be

0 3 3

0 3 3

But you only output [3,3][3,3] because the first one is zero.


The rules

The rules

You are not allowed to construct the big array explicitly!

You are not allowed to construct the mini arrays explicitly!

That means you have to get the computation directly from the small_array!

Fewest characters wins!

Good luck!

The challenge:

write a function func(small_array, size_bigarray, divisor, index_where_small_array_begins, size_smallarray):

The function does the following:

Imagine a big array with size bigarray. (you don't have the array explicity)

It is filled with zeros. Except from index_where_small_array_begins the values of the big_array are identically with small_array.

small_array contains only positive numbers. (not zero)

So small_array is a part of big_array. (you can assume it fits, that means index_where_small_array_begins + size_smallarray <= size_bigarray)

Now split the big_array in mini_arrays of size divisor. (If divisor is not a divisor of size_bigarray, the last array is smaller)

(Example size_bigarray = 10, divisor = 3, then you have four arrays of size: 3, 3, 3, 1)

For each of the mini_array you add the values together, call it sum_of_the_miniarray.

Print out an array with sum_of_the_miniarray for all miniarrays for which the sum_of_the_miniarray is nonzero. (You can conclude that from index_where_small_array_begins and size_smallarray)

Example: Given: small_array = [1,2,3] index_where_small_array_begins = 4 size_bigarray = 8 divisor = 3 then big_array would be: big_array = [0,0,0,0,1,2,3,0] the mini arrays would be

[0,0,0] [0,1,2] [3,0]

the sums would be

0 3 3

But you only output [3,3] because the first one is zero.


The rules

You are not allowed to construct the big array explicitly!

You are not allowed to construct the mini arrays explicitly!

That means you have to get the computation directly from the small_array!

Fewest characters wins!

Good luck!

The challenge

write a function

func(small_array, size_bigarray, divisor, index_where_small_array_begins, size_smallarray)

The function does the following:

Imagine a big array with size bigarray. (you don't have the array explicity)

It is filled with zeros. Except from index_where_small_array_begins the values of the big_array are identically with small_array.

small_array contains only positive numbers. (not zero)

So small_array is a part of big_array. (you can assume it fits, that means index_where_small_array_begins + size_smallarray <= size_bigarray)

Now split the big_array in mini_arrays of size divisor. (If divisor is not a divisor of size_bigarray, the last array is smaller)

(Example size_bigarray = 10, divisor = 3, then you have four arrays of size: 3, 3, 3, 1)

For each of the mini_array you add the values together, call it sum_of_the_miniarray.

Print out an array with sum_of_the_miniarray for all miniarrays for which the sum_of_the_miniarray is nonzero. (You can conclude that from index_where_small_array_begins and size_smallarray)

Example: Given:

small_array = [1,2,3]
index_where_small_array_begins = 4
size_bigarray = 8
divisor = 3

then big_array would be:

big_array = [0,0,0,0,1,2,3,0]

the mini arrays would be

[0,0,0] [0,1,2] [3,0]

the sums would be

0 3 3

But you only output [3,3] because the first one is zero.


The rules

You are not allowed to construct the big array explicitly!

You are not allowed to construct the mini arrays explicitly!

That means you have to get the computation directly from the small_array!

Fewest characters wins!

Good luck!

2 edited body
source | link
1
source | link