Skip to content

Commit

Permalink
first completed solver, very early
Browse files Browse the repository at this point in the history
  • Loading branch information
BAXYCode committed Apr 11, 2023
1 parent a56db4f commit 70cad41
Show file tree
Hide file tree
Showing 12 changed files with 555 additions and 224 deletions.
68 changes: 68 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.4"
70 changes: 0 additions & 70 deletions src/LinkedList.rs

This file was deleted.

31 changes: 31 additions & 0 deletions src/cells.rs
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]
}
}
22 changes: 11 additions & 11 deletions src/cursor.rs
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)}
}
68 changes: 68 additions & 0 deletions src/linked.rs
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 added src/main.exe
Binary file not shown.
Binary file added src/main.pdb
Binary file not shown.
31 changes: 30 additions & 1 deletion src/main.rs
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]);
// }
}
}

Loading

0 comments on commit 70cad41

Please sign in to comment.