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
// Creating a different solution with exactly the same code but a different | |
// ordering in my queue, so one can easily add solutions with better | |
// heuristic functions | |
def bestSolution(ordering: Ordering[(State, List[Move])]) = | |
aStarSearch(PriorityQueue((initialState, List[Move]()))(ordering), Set()) | |
lazy val bestSolutionManhatan: Option[List[Move]] = | |
bestSolution(manhatanOrdering) | |
lazy val bestSolutionMisplaced: Option[List[Move]] = |
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
@tailrec | |
final def breathFirstSearch(queue: List[(State, List[Move])], explored: Set[State], sol: List[(State, List[Move])]): List[(State, List[Move])] = | |
queue match { | |
case Nil => sol | |
case (state, history) :: xs => | |
if (!explored(state)) { | |
breathFirstSearch(xs ++ Move.availableStates(state, moves, history, explored), explored + state, (state, history) :: sol) | |
} else { | |
breathFirstSearch(xs, explored, sol) | |
} |
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
#include <iostream> | |
#include <bitset> | |
using namespace std; | |
bool fastHasIncomingArrows(bool graph[20][20], int size, bitset<100> usedNodes, int node) | |
{ | |
bool found = false; | |
for(int j = 0; !found && j < size; j++) | |
{ | |
if(!usedNodes.test(j)) |
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
val s = Right(1) | |
val l = Left("Error") | |
val seq: Seq[(Int, Either[String, Int])] = Seq((2, s), (3, l)) | |
for { | |
(id, Right(res)) <- seq | |
} yield (id, res) | |
for { |
OlderNewer