This file contains hidden or 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
package ridx | |
import algebra.ring.Field | |
import spire.algebra.{NRoot, Order, Trig} | |
import spire.math.Real | |
object RiddlerClassic20200131 { | |
class Solver[A](implicit val f: Field[A], t: Trig[A], nr: NRoot[A], ord: Order[A]) { | |
import spire.syntax.field._ |
This file contains hidden or 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
import scala.collection.immutable.DefaultMap | |
import scala.collection.Iterator | |
object Bas20190216 { | |
val colors = new BoardMap(Vector( | |
"PBWWBBBRPWGWGWWRBPWP" // 0 | |
,"BGBBBBWPRWWPWBWWPBBP" // 1 | |
,"GPWPGWBBPPBBGBPPWPRB" // 2 | |
,"PGGGGBGBWPWPWPGWGGBW" // 3 |
This file contains hidden or 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
package ridx | |
import scala.collection.mutable.ArrayBuffer | |
/** | |
* Solves riddler classic at https://fivethirtyeight.com/features/525600-minutes-of-math/ | |
*/ | |
object Adv20190210 { | |
This file contains hidden or 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
import scala.collection.mutable.ArrayBuffer | |
import spire.math.Rational | |
import spire.syntax.literals._ | |
/** | |
* Solution to riddler express at | |
* https://fivethirtyeight.com/features/525600-minutes-of-math | |
*/ | |
object Bas20190210 { | |
This file contains hidden or 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
object RiddlerExpress20190113 extends App { | |
// Finds the solution to Riddler Express: | |
// https://fivethirtyeight.com/features/in-space-no-one-can-hear-your-3d-printer-die/ | |
// N.B. - Preferring clarity over efficiency | |
// The input number exactly as given: | |
val input ="530,131,801,762,787,739,802,889,792,754,109,70_,139,358,547,710,066,257,652," + | |
"050,346,294,484,433,323,974,747,960,297,803,292,989,236,183,040,000,000,000" |
This file contains hidden or 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
# Count the number of steps requied for the classical (unoptimized) | |
# version of the euclidean algorithm to terminate. | |
def f(x,y): | |
if x == 0 or y == 0: | |
return 0 | |
z = 1 | |
while x != y: | |
z += 1 | |
if x > y: | |
x -= y |
This file contains hidden or 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
# Calculate solution for riddler express: https://fivethirtyeight.com/features/can-you-win-tic-tac-toe-blindfolded/ | |
# We represent the state of a game using a list of length 9, where each entry corresponds | |
# to a position on the board. If a position is open, the corresponding entry is 0. Otherwise | |
# it is the ordinal number of the move that filled the position. | |
def p(i,j): | |
"""Get the linear index for cell (i,j)""" | |
return i * 3 + j |