1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-07-18 02:20:12 +02:00

feat(challenges): add offset-arrays

This commit is contained in:
Divlo 2021-06-29 19:26:47 +02:00
parent 9a700a0220
commit b9d99fb522
No known key found for this signature in database
GPG Key ID: 185ED2F15F104E52
23 changed files with 167 additions and 1 deletions

View File

@ -48,7 +48,11 @@ The name of the defibrillator located the closest to the users position.
### Constraints
0 < `N` < 10 000
- 0 < `N` < 10 000
## Source
- [CodinGame](https://www.codingame.com/ide/puzzle/defibrillators)
## Examples

View File

@ -0,0 +1,57 @@
# offset-arrays
Created by [@Divlo](https://github.com/Divlo) on 29 June 2021.
## Instructions
### Goal
To settle the debate of 0-based vs 1-based indexing I have created a language where you must explicitly state the range of indices an array should have.
For example, given an array definition "A[-1..1] = 1 2 3", you would have:
- A[-1] = 1
- A[0] = 2
- A[1] = 3
You are given a list of `n` array definitions and your job is to figure out what number is found in a given index `i` of an array `arr`. Note that the indexing operations may be nested (in the above example, A[A[-1]] would produce result 3).
### Input
- **Line 1:** An integer `n` for the number of array assignments
- **`N` next lines:** One array assignment per line: `array_identifier` [ `first_index` .. `last_index` ] = `last_index - first_index + 1` integers separated by space
- **Line `n+2`:** Element to print: `arr` [ `i` ]
### Constraints
- 1 <= `n` <= 100
- Array names consist only of uppercase letters A to Z
- Array lengths are between 1 and 100 (no empty arrays)
- Indexing operations have at most 50 levels of nesting
- Indices are always within bounds in the test cases
## Source
- [CodinGame](https://www.codingame.com/ide/puzzle/offset-arrays)
## Examples
See the `test` folder for examples of input/output.
### Example 1
#### Input
```txt
3
A[-1..1] = 1 2 3
B[3..7] = 3 4 5 6 7
C[-2..1] = 1 2 3 4
A[0]
```
#### Output
```txt
2
```

View File

@ -0,0 +1,5 @@
3
A[-1..1] = 1 2 3
B[3..7] = 3 4 5 6 7
C[-2..1] = 1 2 3 4
A[0]

View File

@ -0,0 +1 @@
2

View File

@ -0,0 +1,28 @@
26
A[-169..-136] = 310 -351 221 -156 307 -384 215 -51 -294 221 172 45 352 -1 57 235 -203 -258 240 -330 -149 -188 356 -391 127 164 -292 244 -216 -13 9 167 -359 -157
B[256..277] = 4 -84 206 -197 -50 -26 78 186 166 329 -25 205 -310 257 -100 -51 296 141 -201 89 328 221
C[26..120] = 373 120 -186 352 -127 -198 -338 395 -17 113 227 -313 277 183 -22 -124 -313 338 81 -301 -256 278 180 -84 274 -26 204 1 223 83 194 -185 110 251 398 -58 -393 -72 75 309 -348 157 -57 238 -362 297 -96 84 385 -164 143 45 -192 -145 299 -120 10 277 -158 129 179 -189 124 -162 -129 -220 -48 -266 -127 -112 229 327 102 5 -285 -193 148 356 219 -287 -336 325 110 -212 132 372 -395 284 173 -306 -101 -97 -224 261 242
D[-205..-119] = -309 380 185 -54 -26 -336 344 -285 -223 210 -108 -382 24 -139 168 266 170 174 -155 33 282 -32 -247 156 103 -338 -233 -56 -218 373 295 39 -140 -190 -84 -390 -119 135 -211 -303 -280 375 -93 216 258 53 -129 -98 16 79 291 -398 -374 335 -375 -54 -187 -186 341 -379 121 -18 337 137 -42 -96 8 -327 69 267 218 302 369 362 -122 -394 329 317 -312 222 89 -358 218 6 210 231 64
E[5..97] = 41 -35 92 -299 -243 -241 237 373 56 92 1 -318 -106 27 57 -222 -65 356 380 -108 -205 151 346 -154 330 114 123 64 -238 269 391 -96 -374 323 -167 202 208 -304 363 60 -392 167 -243 357 374 -352 260 -41 -147 178 389 27 193 189 -59 -56 -264 -13 -5 263 297 206 189 -375 -250 -12 -302 240 164 -268 -333 -107 -164 -373 -242 241 -28 -167 399 392 -213 -390 -318 -203 -72 -76 203 -284 -44 -400 -350 -185 -233
F[78..172] = 229 -386 -208 -54 -210 -194 68 174 -18 230 -203 247 -265 23 264 385 389 -148 -228 175 314 -319 198 -316 331 288 -199 -308 -86 -326 389 125 -137 -400 392 -395 337 290 106 -298 -313 -102 -88 183 288 -172 -2 148 70 -364 -138 279 -94 352 44 -180 -372 320 -97 -153 -128 191 169 -265 -385 -225 -233 -388 -326 -65 139 -332 -266 329 -383 122 242 -153 -354 -144 -315 215 188 225 -101 81 40 -342 316 -302 173 204 119 233 267
G[-212..-147] = 64 -25 -142 94 -389 311 197 215 2 -164 -271 -158 135 365 -146 -269 -240 -393 230 307 213 -62 127 214 366 -124 -270 244 150 20 -158 -115 27 232 384 -15 -128 337 -195 12 342 103 -29 -378 -142 168 276 45 182 -82 2 372 394 277 -92 -206 225 -305 363 -122 -75 -157 341 -226 46 233
H[48..67] = -133 205 -75 -290 153 -123 47 358 -339 124 -169 321 -335 -330 341 339 -373 7 -188 -332
I[-80..4] = 68 -334 -191 70 -187 -151 -268 213 -285 87 67 -90 -204 140 39 400 93 158 -209 72 -7 285 -122 131 393 140 -33 -361 165 -1 108 -157 69 272 19 6 142 -14 66 -98 -208 344 -327 188 -159 261 94 148 -106 -286 -17 -146 -142 -52 -290 35 341 228 -110 339 -281 -393 328 375 -291 350 355 -292 -166 316 -249 118 1 185 237 343 -117 -102 -301 21 330 383 -289 -210 -340
J[-342..-290] = 305 365 60 -112 -320 -67 70 -258 -87 76 -300 316 225 -179 -207 -52 203 -121 13 -163 300 -140 -324 361 -286 140 -146 -383 -154 -287 -142 -336 -275 -124 -223 283 -269 -61 221 -227 75 -195 -84 -71 -332 -245 122 370 -17 3 -44 -108 -331
K[-269..-209] = 122 -102 -360 294 348 -78 -85 -193 172 -276 156 124 -22 -182 339 3 -325 -385 -128 -17 -360 166 60 349 -150 74 156 292 -92 262 41 127 208 -25 156 -101 393 314 232 -379 -396 192 -281 -141 128 -41 -327 -314 -100 -378 343 273 -129 -376 138 16 323 -358 -173 -256 -191
L[77..111] = 257 259 173 374 222 -68 -397 -157 -176 60 194 24 316 222 33 331 -32 155 221 -323 -340 278 203 -121 298 -265 -273 -384 389 114 -52 -333 365 -231 119
M[-44..-23] = 58 -79 176 -379 222 -65 339 54 314 52 338 105 -78 38 25 -200 393 139 240 -200 -65 131
N[-46..-40] = 383 373 56 -31 -40 -262 52
O[59..94] = -53 199 163 -151 245 42 338 -303 46 101 -173 -46 -68 164 -7 156 31 -364 377 -183 277 164 129 151 -79 225 30 -229 -381 -399 -311 87 52 291 323 270
P[263..318] = -90 383 -75 149 -383 181 -224 82 -133 -375 -185 117 -320 205 -365 -330 13 -80 -197 78 113 47 -148 -209 -245 384 -362 -39 213 -88 -258 -135 -263 -176 -251 144 63 -266 -333 -73 173 353 -177 152 -86 247 -373 203 -290 -341 -323 292 225 -30 9 -278
Q[48..130] = -100 -391 -21 -235 316 340 224 -144 250 236 369 5 -169 90 -97 -382 352 -294 230 380 181 -372 -84 -330 -265 -327 350 173 -346 -371 -274 -176 -376 -317 113 217 24 263 -343 367 276 -374 -60 382 269 -280 -359 -232 -361 98 214 46 -223 214 340 6 -19 -381 38 54 -173 -96 81 -141 210 -306 139 -46 -215 288 183 263 -240 234 -290 -49 22 277 -384 332 343 307 144
R[-227..-154] = -132 272 -154 -365 266 -317 337 199 -27 -134 -191 -311 93 -111 42 187 47 -71 291 -344 -99 116 266 57 -108 -165 -362 -119 -338 -253 -220 141 -81 136 178 -181 -167 288 256 -20 -25 -359 -161 -302 -373 280 283 32 52 390 357 -142 -153 35 287 -335 -112 -149 316 -240 208 -386 252 14 201 30 -277 -217 -144 322 -48 -216 -300 147
S[-8..14] = 125 -165 -14 235 -349 133 70 385 -252 -133 285 -63 -169 309 -393 271 -327 362 -334 237 364 -174 -375
T[-172..-156] = -180 -162 -173 -253 -119 309 327 369 -113 180 -307 355 -288 365 -192 -398 324
U[269..313] = -215 -393 288 79 48 -249 -249 232 61 -153 135 -83 395 -125 -232 -15 1 202 93 -193 39 359 -176 28 58 -16 79 87 198 -264 -373 -30 -379 -393 35 354 -57 -247 -116 -104 13 224 -215 336 -98
V[-28..56] = -226 -26 69 351 175 -248 -366 -231 -19 181 33 152 394 216 -245 -287 -279 -125 -336 395 -99 -274 -319 -214 72 -193 -200 -54 296 85 -173 -192 -318 398 218 315 85 215 73 188 292 118 102 -175 8 155 134 -42 -2 -86 -331 168 -376 174 -281 -121 -128 39 -150 -224 -2 175 153 69 -268 226 70 -231 99 -362 -136 -387 -269 -382 366 209 172 -368 319 144 -14 -46 -129 374 -118
W[-258..-160] = -206 242 154 -90 -236 -307 169 37 344 -49 -103 -379 306 3 -124 -37 -71 -103 278 -266 172 -91 -44 138 -241 -252 -166 -314 69 97 -8 -118 88 -339 -328 -233 396 154 114 130 175 -318 -137 -361 -340 -252 -210 186 253 262 199 -101 103 7 -106 -388 305 224 -227 -209 46 -208 384 -358 -383 60 -48 52 -74 335 -321 221 35 -253 386 75 -315 -146 250 -327 -229 52 -104 12 69 270 -64 -311 164 -93 -302 86 -179 -177 -308 27 322 48 392
X[-376..-358] = -22 -39 399 -86 78 -117 354 363 -216 -62 -45 273 61 -108 230 85 347 319 -386
Y[16..43] = -250 -193 217 207 -279 107 -62 -326 -12 286 -123 -36 -199 51 -393 -105 349 82 320 164 -188 -153 -232 355 306 13 -37 -127
Z[169..228] = -253 4 287 -66 -188 -377 180 83 334 -19 352 -71 -397 221 -106 -103 -203 -84 -100 325 -238 -43 -344 290 -151 -177 -59 345 -79 238 -248 222 82 -60 295 -134 262 -32 113 127 -304 -247 -230 128 -215 -40 -306 -54 -245 -25 213 -193 335 -175 -9 -43 -190 -26 232 -398
I[F[R[J[K[E[20]]]]]]

View File

@ -0,0 +1 @@
400

View File

@ -0,0 +1,3 @@
1
ARR[-5..-3] = 11 22 33
ARR[-4]

View File

@ -0,0 +1 @@
22

View File

@ -0,0 +1,3 @@
1
X[0..3] = 1 3 3 7
X[X[2]]

View File

@ -0,0 +1 @@
7

View File

@ -0,0 +1,6 @@
4
FIRST[1..5] = 1 2 3 4 5
SECOND[1..3] = -69 2 6
THIRD[1..4] = 1000 20 2 1
FOURTH[1..2] = 85 -123
SECOND[THIRD[4]]

View File

@ -0,0 +1 @@
-69

View File

@ -0,0 +1,5 @@
3
A[0..0] = 69
B[-3..-3] = 1547
C[133..133] = 55
B[-3]

View File

@ -0,0 +1 @@
1547

View File

@ -0,0 +1,5 @@
3
A[36739847..36739849] = 291 506 0
B[-13045362..-13045360] = 300 461 395
C[-3871032..-3871030] = 307 695 53
A[36739848]

View File

@ -0,0 +1 @@
506

View File

@ -0,0 +1,5 @@
3
A[576147366..576147374] = -17512462 -22180312 4762377 -60705817 179472508 -38657648 50851350 -5387060 -44606386
B[179472503..179472512] = 52472490 -50737470 34836079 43012312 18582898 24184051 22890798 -64190110 -51059274 39321141
C[-329054773..-329054765] = 32107330 -25691875 576147370 64171916 10643863 -53879001 25078797 -36882933 42194855
B[A[C[-329054771]]]

View File

@ -0,0 +1 @@
24184051

View File

@ -0,0 +1,7 @@
5
A[15..54] = 42 47 45 40 12 29 15 18 23 50 26 27 23 47 44 35 50 11 48 50 46 18 37 23 35 45 27 26 15 39 13 40 47 17 28 11 38 36 22 13
B[17..56] = 20 24 19 31 23 12 21 40 21 43 44 28 50 11 49 32 48 14 26 27 37 23 46 42 26 47 28 21 31 16 28 15 21 34 44 43 45 11 45 28
C[11..50] = 40 10 49 22 48 32 42 30 29 44 47 49 40 45 37 32 49 26 19 17 50 15 40 17 36 29 21 13 35 40 28 40 44 12 12 31 16 29 26 23
D[17..56] = 43 25 32 45 20 18 46 23 42 36 27 12 43 15 35 13 35 26 42 39 34 32 22 44 17 32 25 24 18 32 39 48 41 34 21 24 25 21 46 31
E[12..51] = 46 16 20 25 43 25 24 25 45 42 28 18 19 19 36 24 43 17 28 16 21 14 48 16 41 50 24 37 14 48 27 17 12 45 20 35 45 13 50 16
B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[B[52]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

View File

@ -0,0 +1 @@
28

View File

@ -0,0 +1,28 @@
26
A[-19..-13] = 3 -3 -10 8 -3 -2 14
B[7..11] = -1 5 7 4 1
C[-8..1] = -13 4 11 -7 19 10 8 9 -9 20
D[1..4] = 14 6 8 -13
E[1..4] = 9 -14 14 -1
F[14..18] = 12 -15 -18 18 18
G[3..7] = -10 -16 -1 5 -18
H[9..12] = -1 -9 7 -16
I[2..10] = 16 14 18 -11 14 -12 -11 7 18
J[11..15] = 2 1 19 -7 13
K[-11..-5] = -2 -2 20 20 -15 19 4
L[-15..-9] = -5 15 3 -4 19 8 -6
M[4..10] = 17 20 4 3 -16 1 5
N[-10..-1] = 6 -4 -19 10 17 -5 -10 -13 18 -10
O[-13..-11] = 10 13 -19
P[3..11] = 8 -12 -17 18 -3 4 6 -8 4
Q[12..18] = 2 -20 14 -16 -15 10 14
R[2..8] = 19 -10 -15 -11 -6 -15 3
S[-18..-15] = 3 13 -9 1
T[-2..4] = -3 12 -5 17 -6 -1 18
U[5..9] = -7 2 -14 6 19
V[-4..1] = -10 12 16 17 16 -2
W[-20..-11] = -15 -14 9 12 0 17 -10 -6 -7 19
X[2..10] = 20 8 15 -10 16 -6 1 17 -1
Y[-10..-8] = -17 -15 13
Z[-4..0] = -13 11 9 -19 -14
V[S[W[Q[S[P[M[C[A[R[B[Z[V[S[Q[V[V[J[W[-17]]]]]]]]]]]]]]]]]]]

View File

@ -0,0 +1 @@
-2