https://www.codingame.com/training/easy/offset-arrays
Send your feedback or ask for help here!
Created by @Andriamanitra,validated by @Konstant,@TBali and @awnion.
If you have any issues, feel free to ping them.
https://www.codingame.com/training/easy/offset-arrays
Send your feedback or ask for help here!
Created by @Andriamanitra,validated by @Konstant,@TBali and @awnion.
If you have any issues, feel free to ping them.
Nice puzzle, a lot of fun in solving it. Managed to solve it without using Recursion, instead I used Dictionary.
Itās interesting
But i validated all test cases, yet validator 5 donāt validateā¦
And as i have no feedback on whatās going on with validatorsā¦ iām stuck @ 90%
I use regex and recursion, everything works perfectly in test cases, but validator 5 must have something that is not covered in test casesā¦
(iām doing it in javascript)
Validator 5 is very similar to the test āOnly one elementā - the difference is that the indexes are positive.
The test case 5 āOnly one elementā validatesā¦ (as i said all the tests validates)
Iāve tried it in cutom changing to positive indexes and it worksā¦
3
A[0ā¦0] = 69
B[-3ā¦-3] = 1547
C[133ā¦133] = 55
C[133]
My code returns 55
i also tried it with:
3
A[0ā¦0] = -3
B[-3ā¦-3] = 133
C[133ā¦133] = 55
C[B[A[0]]]
returns 55
I really donāt get where the problem isā¦
No idea what your problem might be
Hereās the Validator 5:
3
A[8..8] = 722
B[54..54] = 2
C[0..0] = 4
A[8]
722
VinceD.Ziree, Itās an easy puzzle! Try another way, without regular expressions and other complexities.
Arfā¦
got a ā+ā instead of ā*ā in my regexā¦(which makes no sense now that iāve noticed it, but it worked with all test cases and validators except that validator 5 lol)
If iād tried in custom case with positive single digit array values i would have noticed itā¦
My code isnāt that complex (iām too lazy to bother with something complex lol), and the regex for this arenāt that complex eitherā¦
Iāve just been a little dumb
Anywayā¦ Thank you !
Same here, I dont think recursion is needed
Please Help me. I passed all test case. But 8/10 validators passed (not 2 and 4).
My Code is this.
Python3
import re
ordered_names = [
"FIRST", "SECOND", "THIRD", "FOURTH", "FIFTH", "SIXTH",
"SEVENTH", "EIGHTH", "NINTH", "TENTH", "ELEVENTH", "TWELFTH",
"THIRTEENTH", "FOURTEENTH", "FIFTEENTH", "SIXTEENTH", "SEVENTEENTH",
"EIGHTEENTH", "NINETEENTH", "TWENTIETH", "TWENTY_FIRST", "TWENTY_SECOND",
"TWENTY_THIRD", "TWENTY_FOURTH", "TWENTY_FIFTH", "TWENTY_SIXTH"
]
ARR = dict()
n = int(input())
nb_array = 0
for i in range(n):
expression = input()
arr_name = expression[0]
interval = expression[expression.index("[") + 1: expression.index("]")]
interval = re.sub(r"(\.+)", " ", interval).split()
values = expression[expression.index("=") + 1:]
values = values.split()
first_index, last_index = map(int, interval)
# intialize Array with dict if not exist
try:
eval(arr_name)
except:
exec(f"{arr_name} = dict()")
exec(f"{ordered_names[nb_array]} = {arr_name}")
if not ARR: ARR = eval(arr_name)
nb_array += 1
else:
pass
for index in range(first_index, last_index + 1):
value = values[index - first_index]
exec(f"{arr_name}[{index}] = {value}")
#print(eval(arr_name))
x = input()
# replace "-" by "_": example: TWENTY-FIRST[-1] -> TWENTY_FIRST[-1]
x = re.sub(r"([A-Z])-([A-Z])", r"\1_\2", x)
print(eval(x))
Please, give me additional test cases to test this last.
arr_name = expression[0] goes wrong when the arr_name is more than 1 character long or the first characters of different arraysā names are the same.
Hi @Andriamanitra, thanks for this puzzle.
There is an issue on the test called āNegative indexingā :
1
ARR[-5..-3] = 11 22 33
ARR[-4]
You use the name āARRā for the array while in the description of the puzzle, you say explicitly in the constraints section that
Array names consist only of uppercase letters A to Z
The array ARR should be renamed to A to fit correctly the constraints section (or the constraint about the name should be removed).
Thanks!
I think the constraint was accurate as is, but I rephrased it as āEach array name consists of only uppercase letters (A to Z)ā to avoid any possible confusion.
Thatās a nice way of fixing this issue, thanks for your time.
Same opinion, I also managed to solve it without recursion, but with while.