Problem 42936. Project Euler: Problem 11, Largest product in a grid
Solution Stats
Problem Comments
-
9 Comments
Since I can't tell from the test suite, do you wrap around the matrix when you are calculating the products? For example, when doing the products of four consecutive numbers in the up/down direction, do you do rows 1:4, 2:5, 3:6, 4:7...7:10 and stop there, or do you include the row combinations [8:10 1], [9:10 1:2] and [10 1:3]?
Just submitted my solution (slightly modified from the original Project Euler problem! :-), and the values do not wrap around in any direction.
I vaguely remember there was an earlier problem exactly the same as this one on Cody, and I solved that problem some time ago. But couldn't find the old problem....
All diagonals and reverse diagonals must be tested if you are wondering as I were once.
Today I learned that randi is not actually random on the Cody servers at least.
Also, screw off with this obfuscating the answers crap. It doesn't help anyone. Hacked your code. Got first place. Didn't actually do the problem.
The sums are 67369440, 1168976793600, and 212260240281600.
@Brandon randi is deterministic, and returns pseudorandom numbers rather than true random numbers. Additionally, the default seed with which the PRNG is initialized is the same across MATLAB sessions (see doc rng); this is on purpose and for a reason, namely reproducibility. If this is unhelpful in a given application, you can use rng shuffle.
I agree that the obfuscation of the correct answers is not really helpful.
The md5.update() seems to be broken. I ran the following code in the scratch pad.
------------------------------------------
md5.update(typecast(uint64(PE11(magic(10),4)),'uint8'))
assert(isequal(sprintf('%02X',typecast(md5.digest,'uint8')),...
'9260342934CE67F6A3E74F7EF9001460'))
------------------------------------------------
Then the output is as follows:
Unable to resolve the name 'md5.update'.
@Dong-hyun: there was a problem with the test suite hiding code from the solve page. There was setup code that was being suppressed from view, but was being run before each of the tests. Accordingly, the problem was still solvable, but could not be tested via the Scratch Pad.
I have copied the necessary setup code into each test case, so it should work for you now.
Note that the "rng default" line is needed for the first test case (as is included there) but not for the other two test cases (and is, therefore, not included there).
And, to clarify my comment regarding the Scratch Pad, the test cases need to be present in the Scratch Pad in the same order, due to the reliance upon seeding the random-number generation. I would recommend copying in all three in order before testing your solution.
Solution Comments
Show commentsProblem Recent Solvers94
Suggested Problems
-
567 Solvers
-
88 Solvers
-
Remove element(s) from cell array
1534 Solvers
-
1217 Solvers
-
6413 Solvers
More from this Author2
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!