Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any explanation on your Indicium solution? #1

Open
blakeex opened this issue Mar 15, 2021 · 1 comment
Open

Any explanation on your Indicium solution? #1

blakeex opened this issue Mar 15, 2021 · 1 comment

Comments

@blakeex
Copy link

blakeex commented Mar 15, 2021

Hi, sorry to bother you. I like your Indicium solution at the Qualification round as it is short & simple.

Is it possible for you to add more note on how you got to that solution?

I just want to understand how did you solve that problem.

I understand it had been awhile since you uploaded the solution.
Appreciate it if you could help. Thanks.

@theXYZT
Copy link
Owner

theXYZT commented Mar 15, 2021

Once you have found a valid diagonal for the matrix, you can always greedily fill up the rest of it successfully. That is what generate_latin_square() does. So, the main challenge is to find a valid diagonal.

If a valid Latin square is possible, then it is always possible to generate a diagonal of the form: [a, a, a, ..., a, a, a, b, c] where either a == b == c or a != b and a != c such that the trace constraint is satisfied. This is what get_diagonal() does.

This is the same solution provided by the Codejam team in the problem analysis: https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd27/0000000000209aa0#analysis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants