-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem number 05, Snake eyes.txt
More file actions
58 lines (43 loc) · 1.86 KB
/
problem number 05, Snake eyes.txt
File metadata and controls
58 lines (43 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
problem number: 05, Snake eyes
==========================================
QUESTION:-
========
In front of you are two dice. You know the numbers on the front, left, and top faces of each. Through your exquisite knowledge of dice trivia, you are also aware the numbers on opposite faces of a die add up to 7. The faces are like so:
Dice 1:
Front: 1
Left: 2
Top: 3
Dice 2:
Front: 1
Left: 3
Top: 2
You're provided with a series of directions - up (U), down (D), left (L), or right (R), to spin the current front face of each dice. If you spin the dice in the same direction at each step of the input \"LRDLU\", the front faces after each of these five instructions would be:
Ins. Dice1 Dice2
0 5 4
1 1 1
2 3 2
3 5 4
4 1 1
Above, it's clear the front faces match after instruction indices 1 and 4 (starting from 0).
After spinning the dice according to your input instructions, what is the sum of the indices where the front faces match? For the example above the answer would be 5, since the dice show a pair of ones after instruction 1 and instruction 4.
GIVEN INPUT:-
===========
LRUDDLRDLLDRUUUURLUDLLDLUDRURRDLUDRDURUURDLRULDULLRDRLLLDRDRRRLLDLRUUUDRLRDRLDRRUURDRLUDUUDUDLLDRULRLDRRLUUURRDDUDRDRURRLRRLLDRUUURLLRLRURRRUDUDURUDRURDRDDDURDLUDDLDUDRULDRULURLUULLLURDRLDUDRDUDRLDDRUULLLULRLDUURUUDRDLLDRRDRLLRUUURLDRULUDDRDDLDRURURR
saved all inputs in a file name called "snake.txt"
ANSWER:-
======
q)input:raze read0 `:snake.txt
q)function:{ d1::1 2 3 4 5 6;
d2::1 3 2 5 4 6;
rotateDice::`U`D`L`R!((3 1 0 5 4 2);(2 1 5 0 4 3);(4 0 2 3 5 1);(1 5 2 3 0 4));
i::-1;
input:`$'x;
front_values::([] Ins:();Dice1:();Dice2:());{[face]d1::d1 rotateDice[face];d2::d2 rotateDice[face];`front_values insert(i::i+1;d1[0];d2[0])}each input;
:sum(exec Ins from front_values where Dice1 = Dice2)}
q)
q)
q)
q)function[input]
10704
q)
q)