-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
555 additions
and
224 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::ops; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct Cell(pub usize); | ||
|
||
pub const CERO: Cell = Cell(0); | ||
|
||
impl ops::Index<Cell> for Vec<Cell> { | ||
type Output = Cell; | ||
|
||
fn index(&self, cell: Cell) -> &Cell { | ||
&self[cell.0] | ||
} | ||
} | ||
impl ops::IndexMut<Cell> for Vec<Cell> { | ||
fn index_mut(&mut self, cell: Cell) -> &mut Cell { | ||
&mut self[cell.0] | ||
} | ||
} | ||
impl ops::Index<Cell> for Vec<usize> { | ||
type Output = usize; | ||
fn index(&self, index: Cell) -> &usize { | ||
&self[index.0] | ||
} | ||
} | ||
|
||
impl ops::IndexMut<Cell> for Vec<usize> { | ||
fn index_mut(&mut self, index: Cell) -> &mut usize { | ||
&mut self[index.0] | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
mod LinkedList; | ||
mod cells; | ||
use crate::linked::Linked; | ||
use crate::cells::Cell; | ||
|
||
struct Cursor{ | ||
head: Cell, | ||
current: Cell} | ||
pub(crate) struct Cursor{ | ||
pub(crate) head: Cell, | ||
pub(crate) current: Cell} | ||
impl Cursor { | ||
|
||
//Takes in a reference to a list and uses the cursor's internals to | ||
//navigate said list. If the cursor's new curr node is the same as | ||
//the node it started with, None is returned. | ||
fn next(&self, &list: LinkedList) -> Option<Cell>{ | ||
pub(crate) fn next(&mut self, list: &Linked) -> Option<Cell>{ | ||
|
||
self.current = list[self.current].next; | ||
|
||
if assert_eq!(self.current,self.head ){ | ||
if self.current == self.head{ | ||
return None;} | ||
Some(self.current); | ||
Some(self.current) | ||
} | ||
fn prev(&self, &list:LinkedList) -> Option<Cell>{ | ||
pub(crate)fn prev(&mut self, list:&Linked) -> Option<Cell>{ | ||
|
||
self.current = list[self.current].prev; | ||
|
||
if assert_eq!(self.current, self.head){ | ||
if self.current == self.head{ | ||
return None;} | ||
Some(self.current);} | ||
Some(self.current)} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::ops; | ||
use crate::cells::Cell; | ||
use crate::cursor::Cursor; | ||
|
||
|
||
pub(crate) struct Linked{ | ||
pub(crate) links: Vec<Link> | ||
} | ||
|
||
|
||
pub struct Link{ | ||
pub(crate) prev: Cell, | ||
pub(crate) next: Cell} | ||
|
||
impl ops::Index<Cell> for Linked{ | ||
|
||
type Output = Link; | ||
fn index(&self, a: Cell) -> &Link{ | ||
&self.links[a.0]} | ||
|
||
|
||
}impl ops::IndexMut<Cell> for Linked{ | ||
fn index_mut(&mut self, a:Cell) -> &mut Link{ | ||
&mut self.links[a.0]}} | ||
|
||
|
||
impl Linked { | ||
|
||
pub(crate) fn new_with_cap(cap: usize) -> Linked{ | ||
Linked{links: Vec::with_capacity(cap)} | ||
} | ||
|
||
pub(crate) fn new_cell(&mut self) -> Cell{ | ||
let cell = Cell(self.links.len()); | ||
self.links.push(Link{prev:cell, next:cell}); | ||
cell} | ||
|
||
pub(crate) fn insert(&mut self, a:Cell,b:Cell){ | ||
|
||
let c = self[a].next; | ||
|
||
self[a].next = b; | ||
self[b].next = c; | ||
self[c].prev = b; | ||
self[b].prev = a; } | ||
|
||
|
||
pub(crate) fn remove(&mut self, b:Cell){ | ||
|
||
let a = self[b].prev; | ||
let c = self[b].next; | ||
|
||
self[c].prev = self[b].prev; | ||
self[a].next = self[b].next;} | ||
|
||
pub(crate) fn add_back(&mut self, b:Cell){ | ||
|
||
let a = self[b].prev; | ||
let c = self[b].next; | ||
|
||
self[c].prev = b; | ||
self[a].next = b;} | ||
|
||
pub(crate) fn cursor(&self, c: Cell) -> Cursor{ | ||
Cursor {head: c, current:c}} | ||
} | ||
|
||
|
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,30 @@ | ||
unimplemented!(); | ||
|
||
#![recursion_limit = "1000000"] | ||
#![feature(int_roundings)] | ||
use rand::{thread_rng,Rng}; | ||
use std::{io, collections}; | ||
mod cursor; | ||
mod linked; | ||
mod cells; | ||
mod matrix; | ||
mod sudoku; | ||
use crate::sudoku::Sudoku; | ||
use std::env; | ||
|
||
fn main(){ | ||
env::set_var("RUST_BACKTRACE", "1"); | ||
let mut input = String::new(); | ||
io::stdin().read_line(&mut input).expect("give valid sudoku"); | ||
let split :Vec<&str> = input.split_whitespace().collect(); | ||
let mut sudoku_problem = Sudoku::new(split[0],split[1].parse::<usize>().unwrap(),split[2].parse::<usize>().unwrap()); | ||
let res = sudoku_problem.time_to_solve(Sudoku::solver); | ||
if let Some(res) = res{ | ||
println!("found {} solutions to the problem",sudoku_problem.solutions); | ||
let index = thread_rng().gen_range(1..res.len()); | ||
//for x in 0..sudoku_problem.solutions{ | ||
//if x >10{break;} | ||
println!("{:?}",res[index]); | ||
// } | ||
} | ||
} | ||
|
Oops, something went wrong.