How many balloons do I need in each corner?

You have a square board with a bunch of items laid out on it in one of a $$\3 \times 3\$$ grid of cells and you want to lift it up using balloons, but you can only attach balloons to the corners of the board. Your task is to determine the minimum number of balloons in each corner to make sure the board won't tip over in flight, but can still lift all its contents.

"Physics" Model

• Each balloon can lift 0.25kg (these are very strong balloons)
• The board itself weighs 1kg, so you would need 1 balloon in each corner to lift an empty board
• Items in each corner cell only exert force on their respective corners (i.e. 4 balloons are needed in the corresponding corner per kg)
• Items on each edge cell split their force evenly between their neighboring corners (i.e. 2 balloons on each of the two corresponding corners per kg)
• Items in the center cell split their force evenly across all corners (i.e. 1 balloon is needed in each corner per kg)

Input:
0 0 0
0 0 0
0 0 0

Output:
1 1
1 1

Input:
1 2 1
2 4 2
1 2 1

Output:
17 17
17 17

Input:
5 0 0
0 0 2
0 1 0

Output:
21 5
3 7

Input:
12  9 35
1 32  2
4  6 18

Output:
101 195
63 121

Input:
9999 9999 9999
9999 9999 9999
9999 9999 9999

Output:
89992 89992
89992 89992

Input:
9999    2 9001
0 9999 9999
9999  999 9999

Output:
50000 66006
51994 71992

Rules and Assumptions

• You may assume each cell is filled with a whole number between $$\0\$$ and $$\9999\$$ kg weight worth of items
• Use any convenient format for I/O
• Shortest code wins!
• Can we do the input and output numbers in any order if we use a flat list?
– xnor
Mar 12 '20 at 22:02
• @xnor yes, as long as it's consistent Mar 12 '20 at 22:05
• Mar 13 '20 at 0:35
• I believe some of your input and output are incorrect. #5 and #6 at least are all of by one. 9999*4,2,2,1 makes 89,991 but you forgot the +1 for the platform it's on. Mar 13 '20 at 17:50
• @Arnauld Corrected. Mar 16 '20 at 16:28

3Ḷ×þZU$Ƭ×µ§§‘ Try it online! Takes input as a 3x3 matrix and outputs a list going clockwise starting from the bottom-right. Explanation 3Ḷ×þZU$Ƭ×µ§§‘     Main Link
3Ḷ                 [0, 1, 2]
×þ              outer product by multiplication with itself ([0, 0, 0], [0, 1, 2], [0, 2, 4])
Ƭ          (include the original, plus) rotate clockwise until results are no longer unique (4 results total)

Try it online!

Input:

If the grid is denoted as:

a b c
d e f
g h i

Then the input is space separated:

a b c d e f g h i

Output:

Output is line separated:

balloons attached at a
balloons attached at c
balloons attached at g
balloons attached at i

Jelly, 21 19 bytes

3,1pạ€3Rp¤P€€×³§‘

Try it online!

How?

Notice that we can create the weight matrices for each corner by finding the absolute difference to the opposite corners.

For example, for the first balloon, the weight matrix is

4 2 0
2 1 0
0 0 0

This can be found by, for each coordinate, find the absolute difference to the corner (3, 3), and product. For example, (1, 1) has an absolute difference (2, 2) and product 4.

3,1pạ€3Rp¤P€€×³§‘    Main link
3,1                      Get 3,1 pair
p                    cartesian product with itself, gives the 3 corner coordinates
3Rp¤             Get all the coordinates
ạ€                  get the absolute differences for each corner coordinate
P€€          product each subsublist
×³        vectorize multiply with the input
§‘      sum each sublist and increment

Jelly, 14 bytes

ŒJḂ§2*ṁ×⁸+Ɲ⁺€‘

A monadic Link accepting a list of lists of integers which yields a list of list of integers:
[[top-left, top-right], [bottom-left, bottom-right]]

Try it online!

How?

ŒJḂ§2*ṁ×⁸+Ɲ⁺€‘ - Link: list of lists of integers, T    e.g. [[ 3, 9, 5],[ 1, 3, 2],[ 4, 6, 1]]
ŒJ             - multidimensional indices (T)               [[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3]]
Ḃ            - least significant bit (vectorises)         [[1,1],[1,0],[1,1],[0,1],[0,0],[0,1],[1,1],[1,0],[1,1]]
§           - sums                                       [2,1,2,1,0,1,2,1,2]
2          - literal two                                2
*         - exponentiate                               [4,2,4,2,1,2,4,2,4]
ṁ        - mould like (T)                             [[ 4, 2, 4],[ 2, 1, 2],[ 4, 2, 4]]
⁸      - chain's left argument, T                   [[ 3, 9, 5],[ 1, 3, 2],[ 4, 6, 1]]
×       - multiply (vectorises)                      [[12,18,20],[ 2, 3, 4],[16,12, 4]]
Ɲ    - for neighbours:
+     -   add (vectorises)                         [[14,21,24],[18,15, 8]]
€  - for each:
⁺   -   repeat last link                         [[35,45],[33,23]]
- (...i.e +Ɲ for each)
‘ - increment (vectorises)                     [[36,46],[34,24]]

f a b c d e f g h i=[2*v+e+1|v<-[2*a+b+d,b+2*c+f,d+2*g+h,f+h+2*i]]

Try it online!

• @BjarturThorlacius thanks for your suggested edit with the improvement. However, in this community it is good practice to leave a comment with the suggestion for the golfing you find or, alternatively, leave a TIO link with the shorter code version!
– RGS
Mar 15 '20 at 17:21
• Good to know, I had no idea. Also, I accidentally wiped out the text you had written below your solution on how the solution was inspired by your Python solution. Mar 15 '20 at 17:35
• No problem x2 :) Enjoy this community! Code-golfing can be quite fun!
– RGS
Mar 15 '20 at 17:41

brainfuck, 138 bytes

,[->++++<],[->++>++<<],[->>++++<<],[->++>>++<<<],[->+>+>+>+<<<<],[->>++>>++<<<<],[->>>++++<<<],[->>>++>++<<<<],[->>>>++++<<<<]>+.>+.>+.>+.

Try it online!, just for the byte count.

Try it here, by pasting this input: \12\9\35\1\32\2\4\6\18 and hitting the "view memory" button to compare it with the expected output 101 195 063 121.

• No comments?... Mar 13 '20 at 0:05

Pyth, 24 bytes

mh+eQ+ys<.<ecPQ4d2yy@Qd4

Try it online!

I/O format: List [0, 1, 2, 3, 4, 5, 6, 7, 8] (input) and [0, 1, 2, 3] (output) with positions

Input: 0 5 1     Output: 0 1
= Q   4 8 6             3 2
3 7 2

Explanation

m                      4   # map [0, 1, 2, 3] to (current number = d)
h                         # 1 +
+eQ                      # Q[-1] + 1 +
ys                   #   2 * sum of
ec  4           #     chop       into pieces of length 4, take last element
PQ            #          Q[:-1]                 -> [4,5,6,7]
.<     d          #     rotate left by d
<        2         #     first two elements -> [4,5], [5,6], [6,7] or [7,4]
+                     # +
yy       #   4 *
@Qd    #       Q[d]

PHP, 101 bytes

A rather inelegant solution. Just multiples corners by 4, sides by 2 and adds 1 to the center than adds up each corner. Some form of matrix multiplication may be possible with array_map().

parse_str($argv);$e++;echo$a*4+$b*2+$d*2+$e,$c*4+$b*2+$f*2+$e,$g*4+$d*2+$h*2+$e,$i*4+$f*2+$h*2+$e;

Try it online!

It takes input as a string in a html query format e.g. a=9999&b=3&c=9001&d=0&e=9998&f=9999&g=9999&h=999&i=9999

+7 bytes if the output can't be an unseparated list, by making it into an array and using print_r()

PHP, 108 bytes

parse_str($argv);$e++;print_r([$a*4+$b*2+$d*2+$e,$c*4+$b*2+$f*2+$e,$g*4+$d*2+$h*2+$e,$i*4+$f*2+$h*2+$e]);

Try it online!