[Community Puzzle] 1D Spreadsheet


#1

https://www.codingame.com/training/easy/1d-spreadsheet

Send your feedback or ask for help here!

Created by @PolyB,validated by @bbb000bbbyyy,@JBM and @Zorg1.
If you have any issues, feel free to ping them.


#2

I managed the 10 first tests but then I don’t, I noticed that there could be an order in the execution of operations (VALUE first) but there may be others that I didn’t found. So I wonder : Is there some rules I missed ? Is there some priority between ADD, SUB and MULT or according to the cells $0, $1… ?


#3

There is no need for precedence, as each cell can only have a single operation. On the other hand, you obviously can’t compute a cell’s value before you have computed the operands it depends on.


#4

Mon code passe tous les tests sauf “Backward dependency”. Le premier argument donné fait référence à une cellule inexistante, que je positionne alors à 0.
Mais il semble que le résultat attendu soit dans ce cas un mélange des arguments de 2 lignes de calcul, comme on peut voir si dessous :
Sortie standard :
'cells : ’
‘arg1 : $1 OP : ADD et arg 2 : 20’
‘cells : 20’
‘arg1 : 32 OP : VALUE et arg 2 : _’
20
32
Échec
Trouvé : 20
Attendu : 52
Est-ce vraiment ce qui est attendu, ou s’agit-il d’une erreur dans le jeu de données de test ?


#5

@akaliphen L’input est :

2
ADD $1 20
VALUE 32 _

Il y a donc 2 cellules, $0 = $1 + 20 et $1 = 32, d’où $0 = 52.


#6

OK, je vois :thinking: Merci


#7

I don’t understand how we can predict the value of a cell if the ones it refers have no value except 0 because of initialization. As I said I can’t manage the tests after 11 even if I putted values in cells for operation with either VALUE or any other operation with only numbers and no references. Please could anyone give me an advice ?


#8

You are already doing very well to have passed 10 test cases.
Ever think of a spreadsheet having no VALUE at all? Try this:

5
ADD $1 $2
SUB $4 $2
ADD $4 $4
MULT $0 $1
SUB $3 $3


#9

C’est vraiment ce qui est attendu.
Il semble que la somme ne soit pas faite… un problème de d’assignation/retour?


#10

Here’s a Google Sheets transcription of the “Diamond Dependency” test case, just to show how you could solve the test cases even if you didn’t understand the algorithm behind.

Capture%20d%E2%80%99%C3%A9cran%20de%202019-07-12%2012-33-08


#11

My code give the following answer :

0
0
0
0
0

Because all cells are initialized at 0
Is that correct ?


#12

The rules of the puzzle say

There won’t be any cyclic references: a cell that reference itself or a cell that references it, directly or indirectly.

So the test written by java_coffee_cup is not valid and won’t be tested.

However java_coffe_cup is right that a spreadsheet can have no VALUE at all like this:

2
ADD $1 20
ADD 32 4

The expected result here is
56
36