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
use lovecraft::{ | |
solve, | |
parse_grid, | |
}; | |
use std::env; | |
fn main() { | |
let args: Vec<String> = env::args().collect(); | |
let grid_desc = &args[1]; |
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
pub fn parse_grid(grid_desc :&str) -> Grid { | |
let mut grid: Grid = [[false;4];4]; | |
grid_desc.chars().collect::<Vec<char>>().chunks(4). | |
enumerate().for_each(|(a,cs)| { | |
cs.iter().enumerate().for_each(|(b,c)| { | |
if *c == '1' { | |
grid[a][b]=true; | |
} | |
}) | |
}); |
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
fn try_all(grid: &Grid, | |
seen: &mut HashMap<Grid,Vec<Pos>>, | |
todo: &mut VecDeque<Grid> | |
) -> Option<Vec<Pos>> { | |
let path= match seen.get(grid){ | |
Some(p) => p.clone(), | |
None => panic!("no path to grid!") | |
}; | |
for a in 0..4 { | |
for b in 0..4 { |
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
use std::collections::HashMap; | |
use std::collections::VecDeque; | |
pub fn solve(grid: Grid) -> Vec<Pos> { | |
if is_solved(grid){ | |
return vec!(); | |
} | |
let mut ret = None; | |
let mut seen=HashMap::new(); |
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
fn swap(grid: &Grid, pos: Pos) -> Grid { | |
let mut grid = grid.clone(); | |
for a in 0..4 { | |
grid[pos.0][a] = !grid[pos.0][a]; | |
} | |
for a in 0..4 { | |
grid[a][pos.1] = !grid[a][pos.1]; | |
} | |
grid[pos.0][pos.1] = !grid[pos.0][pos.1]; | |
grid |
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
pub type Grid = [[bool;4];4]; | |
pub type Pos = (usize,usize); | |
fn is_solved(grid: Grid) -> bool { | |
grid.iter().all(|r| r.iter().all(|c| *c)) | |
} |
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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
nums := []int{2, 3, 4} | |
funcs := make([]func(), 0) | |
for _, i := range nums { |
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
import ( | |
"fmt" | |
"errors" | |
) | |
func main() { | |
var err error | |
var doIt = true | |
if doIt { | |
ret, err := mayError() |
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
{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, MultiParamTypeClasses #-} | |
module Gen where | |
import GenProg | |
import Data.Generics | |
import Control.Monad | |
import Control.Monad.Random | |
import Logic |
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
import Data.Generics(Data,Typeable) | |
import Prelude(Show,Read,Eq) | |
data Bit=T | F | |
deriving (Show,Read,Eq,Data,Typeable) | |
nand :: (Bit, Bit) -> Bit | |
nand (T,T)=F | |
nand _=T |
NewerOlder