Skip to content

Instantly share code, notes, and snippets.

@JeremyLWright
Created March 27, 2016 23:38
Show Gist options
  • Save JeremyLWright/fef85ffc0e5b33cf4798 to your computer and use it in GitHub Desktop.
Save JeremyLWright/fef85ffc0e5b33cf4798 to your computer and use it in GitHub Desktop.
Problem compiling 2.9.1 scala program
/**
* Created by Jeremy on 3/27/2016.
*/
import collection.mutable.ListBuffer
class Rotor(var rotorMap: List[(Char, Char)], val notch: Char){
def this(alphabet: String, beginPos: Int, notch: Char) = this(
Rotor.rotate((Alphabets.realAlphabet zip alphabet).toList, beginPos), notch)
def this(alphabet: String, beginPos: Int) = this(alphabet, beginPos, 'Z')
def showing = rotorMap.head._1
def isAtNotch = rotorMap.head._1 == notch
def mirror = new Rotor(rotorMap.map(x => (x._2, x._1)), notch)
def translate(windowPos: Int): Int = {
rotorMap.indexWhere(t => t._1 == rotorMap(windowPos)._2)
}
def rotate : Unit = {
rotorMap = Rotor.rotate(rotorMap, 1)
}
object Rotor {
def rotate(l: List[(Char, Char)], nr: Int): List[(Char, Char)] = {
val b: ListBuffer[(Char, Char)] = ListBuffer.empty
b.appendAll(l.drop(nr))
b.appendAll(l.take(nr))
b.toList
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment