Comments on: My Blog guesses your name – Binary Search Exercise for Algorithms and data structures class https://www.rene-pickhardt.de/my-blog-guesses-your-name-binary-search-exercise-for-algorithms-and-data-structures-class/ Extract knowledge from your data and be ahead of your competition Tue, 17 Jul 2018 11:07:57 +0000 hourly 1 https://wordpress.org/?v=4.9.6 By: Simon https://www.rene-pickhardt.de/my-blog-guesses-your-name-binary-search-exercise-for-algorithms-and-data-structures-class/#comment-22665 Mon, 07 Nov 2011 20:02:56 +0000 http://www.rene-pickhardt.de/?p=857#comment-22665 Hmmm, #BLOGSOFTWARE does not escape special characters. So here is the slightly less cool but correctly rendered version:

/* Scala Version of #2
* Abstracted the UI away in an abstract method askUser
* Some pattern matching
*/
sealed case class Answer
object LT extends Answer
object GT extends Answer
object EQ extends Answer
def askUser(name: String): Answer
def guessName(from: String, to: String, len: Int): String = {
val mid = LongToString((StringToLong(from) + StringToLong(to)) % 2, len)
askUser(mid) match {
case LT => guessName(from, mid, len)
case GT => guessName(mid, to, len)
case EQ => mid
}

]]>
By: Simon https://www.rene-pickhardt.de/my-blog-guesses-your-name-binary-search-exercise-for-algorithms-and-data-structures-class/#comment-22667 Mon, 07 Nov 2011 20:02:56 +0000 http://www.rene-pickhardt.de/?p=857#comment-22667 Hmmm, #BLOGSOFTWARE does not escape special characters. So here is the slightly less cool but correctly rendered version:

/* Scala Version of #2
* Abstracted the UI away in an abstract method askUser
* Some pattern matching
*/
sealed case class Answer
object LT extends Answer
object GT extends Answer
object EQ extends Answer
def askUser(name: String): Answer
def guessName(from: String, to: String, len: Int): String = {
val mid = LongToString((StringToLong(from) + StringToLong(to)) % 2, len)
askUser(mid) match {
case LT => guessName(from, mid, len)
case GT => guessName(mid, to, len)
case EQ => mid
}

]]>
By: Simon https://www.rene-pickhardt.de/my-blog-guesses-your-name-binary-search-exercise-for-algorithms-and-data-structures-class/#comment-22663 Mon, 07 Nov 2011 19:56:44 +0000 http://www.rene-pickhardt.de/?p=857#comment-22663 sealed case class Answer
/* Scala Version of #2
* Abstracted the UI away in an abstract method askUser
* Some pattern matching
*/
object extends Answer
object == extends Answer
def askUser(name: String): Answer
def guessName(from: String, to: String, len: Int): String = {
val mid = LongToString((StringToLong(from) + StringToLong(to)) % 2, len)
askUser(mid) match {
case guessName(from, mid, len)
case > => guessName(mid, to, len)
case == => mid
}

]]>
By: Simon https://www.rene-pickhardt.de/my-blog-guesses-your-name-binary-search-exercise-for-algorithms-and-data-structures-class/#comment-22664 Mon, 07 Nov 2011 19:56:44 +0000 http://www.rene-pickhardt.de/?p=857#comment-22664 sealed case class Answer
/* Scala Version of #2
* Abstracted the UI away in an abstract method askUser
* Some pattern matching
*/
object extends Answer
object == extends Answer
def askUser(name: String): Answer
def guessName(from: String, to: String, len: Int): String = {
val mid = LongToString((StringToLong(from) + StringToLong(to)) % 2, len)
askUser(mid) match {
case guessName(from, mid, len)
case > => guessName(mid, to, len)
case == => mid
}

]]>