Update benchmarks.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use aiken/int
|
||||
use aiken/list
|
||||
use aiken/collection/list
|
||||
use aiken/primitive/int
|
||||
|
||||
// ------------------------------------------------------------------ Benchmarks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use aiken/list
|
||||
use aiken/collection/list
|
||||
use benchmarks/knights/heuristic.{descendants, start_tour, tour_finished}
|
||||
use benchmarks/knights/queue.{Queue}
|
||||
use benchmarks/knights/types.{ChessSet, Solution}
|
||||
@@ -10,11 +10,11 @@ test bench_knights_100_4x4() {
|
||||
}
|
||||
|
||||
test bench_knights_100_6x6() {
|
||||
run_knights(100, 6) == solution_100_6x6()
|
||||
run_knights(100, 6) == solution_100_6x6
|
||||
}
|
||||
|
||||
test bench_knights_100_8x8() {
|
||||
run_knights(100, 8) == solution_100_8x8()
|
||||
run_knights(100, 8) == solution_100_8x8
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- Setup
|
||||
@@ -30,7 +30,7 @@ fn depth_search(
|
||||
done: fn(a) -> Bool,
|
||||
) -> Queue<a> {
|
||||
if depth == 0 || queue.is_empty(xs) {
|
||||
queue.new()
|
||||
queue.empty
|
||||
} else if done(queue.head(xs)) {
|
||||
depth_search(depth - 1, queue.remove_front(xs), grow, done)
|
||||
|> queue.append_front(queue.head(xs))
|
||||
@@ -41,7 +41,7 @@ fn depth_search(
|
||||
}
|
||||
|
||||
fn root(size: Int) -> Queue<(Int, ChessSet)> {
|
||||
queue.append_all_front(queue.new(), mk_starts(size))
|
||||
queue.append_all_front(queue.empty, mk_starts(size))
|
||||
}
|
||||
|
||||
fn mk_starts(size: Int) -> List<(Int, ChessSet)> {
|
||||
@@ -79,7 +79,7 @@ fn done(item: (Int, ChessSet)) -> Bool {
|
||||
|
||||
// ------------------------------------------------------------------ Fixtures
|
||||
|
||||
fn solution_100_6x6() -> Solution {
|
||||
const solution_100_6x6: Solution =
|
||||
[
|
||||
(
|
||||
0,
|
||||
@@ -266,9 +266,9 @@ fn solution_100_6x6() -> Solution {
|
||||
},
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
fn solution_100_8x8() -> Solution {
|
||||
|
||||
const solution_100_8x8: Solution =
|
||||
[
|
||||
(
|
||||
0,
|
||||
@@ -493,4 +493,3 @@ fn solution_100_8x8() -> Solution {
|
||||
},
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use aiken/list
|
||||
use aiken/collection/list
|
||||
use benchmarks/knights/types.{ChessSet, Tile}
|
||||
|
||||
pub fn create_board(size: Int, init_square: Tile) -> ChessSet {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use aiken/builtin
|
||||
use aiken/int
|
||||
use aiken/list
|
||||
use aiken/collection/list
|
||||
use aiken/primitive/int
|
||||
use benchmarks/knights/chess_set.{
|
||||
add_piece, create_board, delete_first, first_piece, is_square_free, last_piece,
|
||||
}
|
||||
@@ -18,9 +18,8 @@ type Direction {
|
||||
RD
|
||||
}
|
||||
|
||||
fn direction_list() {
|
||||
const direction_list =
|
||||
[UL, UR, DL, DR, LU, LD, RU, RD]
|
||||
}
|
||||
|
||||
fn move(direction: Direction, tile: Tile) -> Tile {
|
||||
let (x, y) = tile
|
||||
@@ -130,7 +129,7 @@ fn move_knight(board: ChessSet, direction: Direction) -> ChessSet {
|
||||
}
|
||||
|
||||
fn possible_moves(board: ChessSet) -> List<Direction> {
|
||||
direction_list() |> list.filter(can_move(board, _))
|
||||
direction_list |> list.filter(can_move(board, _))
|
||||
}
|
||||
|
||||
fn compare_chess_set(a: (Int, ChessSet), b: (Int, ChessSet)) -> Ordering {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use aiken/list
|
||||
use aiken/collection/list
|
||||
|
||||
pub opaque type Queue<a> {
|
||||
inner: List<a>,
|
||||
}
|
||||
|
||||
pub fn new() -> Queue<a> {
|
||||
[] |> Queue
|
||||
}
|
||||
pub const empty: Queue<a> = [] |> Queue
|
||||
|
||||
pub fn to_list(self: Queue<a>) -> List<a> {
|
||||
self.inner
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use aiken/list
|
||||
use aiken/collection/list
|
||||
|
||||
pub fn quicksort(xs: List<a>, compare: fn(a, a) -> Ordering) -> List<a> {
|
||||
when xs is {
|
||||
|
||||
Reference in New Issue
Block a user