Created
November 29, 2012 01:09
-
-
Save krishnanraman/4166029 to your computer and use it in GitHub Desktop.
Oscar movember challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compute a cayley table for a finite abelian group given its zero | |
def zero(x:Int, group:Vector[Int]) = { | |
val n = group.size | |
val pos = group.indexOf(x) | |
val base = group.slice(pos, n) ++ group.slice(0, pos) | |
Vector.tabulate(n,n)((x,y)=> { | |
val row = base.slice(x,n)++base.slice(0,x) | |
row(y) | |
}) | |
} | |
// Add two numbers in a group given its cayley table | |
def plus(x:Int, y:Int, cayley:Vector[Vector[Int]]) = cayley(x-1)(y-1) | |
// prove all this shit works | |
scala> plus(1,1,zero(3,Vector(1,2,3,4))) | |
res2: Int = 3 | |
scala> plus(1,4,zero(3,Vector(1,2,3,4))) | |
res3: Int = 2 | |
scala> plus(1,2,zero(3,Vector(1,2,3,4))) | |
res4: Int = 4 | |
scala> plus(1,3,zero(3,Vector(1,2,3,4))) | |
res5: Int = 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment