Hello All, First post here
I'm looking for help trying to code a damm algorithm using Rust.
Implementations in other languages
matrix = (
(0, 3, 1, 7, 5, 9, 8, 6, 4, 2),
(7, 0, 9, 2, 1, 5, 4, 8, 6, 3),
(4, 2, 0, 6, 8, 7, 1, 3, 5, 9),
(1, 7, 5, 0, 9, 8, 3, 4, 2, 6),
(6, 1, 2, 3, 0, 4, 5, 9, 7, 8),
(3, 6, 7, 4, 2, 0, 9, 5, 8, 1),
(5, 8, 6, 9, 7, 2, 0, 1, 3, 4),
(8, 9, 4, 5, 3, 6, 2, 0, 1, 7),
(9, 4, 3, 8, 6, 1, 7, 2, 0, 5),
(2, 5, 8, 1, 4, 3, 6, 7, 9, 0))
def checkdigit(input):
row = 0
for eachdigit in input:
row = matrix[row][int(eachdigit)]
return row
for number in inputrange:
output = checkdigit(str(number))
print str(number)+str(output)
My trouble starts with selecting elements from inside a defined 10x10 matrix.
I tried using rust by example 2.2 tuples Now I understand that by changing the value 0 to 1
println!("long tuple first value: {}", long_tuple.0);
to
println!("long tuple first value: {}", long_tuple.1);
The first element of the second tuple is selected.
But how can the second element of the first tuple or the second element of the second tuple be selected. I have not been able to find resources on tuple indexing explained well.
Thanks to anyone who reads this