Skip to content

Instantly share code, notes, and snippets.

View ignaciomosca's full-sized avatar
🎯
Focusing

Ignacio Mosca ignaciomosca

🎯
Focusing
View GitHub Profile
@ignaciomosca
ignaciomosca / mp3length.sh
Created January 3, 2020 11:40
How many minutes of music are in a folder
#!/bin/sh
if [ -z "$*" ]; then echo "Missing folder"; exit 1; fi
for d in $1; do
if [ -d "$d" ]; then
cd "$d"
exiftool -n -q -p '${Duration;our $sum;$_=ConvertDuration($sum+=$_)}' ./*.mp3| tail -n1
fi
done
pub fn solution<'a>(
board_stack: &mut VecDeque<(Board, Vec<ChessPiece>)>,
solutions: &'a mut HashSet<Board>,
tested_configurations: &mut HashSet<Board>,
) -> &'a HashSet<Board> {
while !board_stack.is_empty() {
let (board, pieces) = board_stack.pop_back().unwrap();
for row in 1..=board.m {
for col in 1..=board.n {
let new_piece = Piece {
func SamePices(used1,used2 []primitives.Attacks) {
u1:=append([]primitives.Attacks{},used1…)
u2:=append([]primitives.Attacks{},used2…)
for _,u := range [][]primitives.Attack{u1,u2} {
sort.Sort(u, func (i,j int) bool {
x,y:=u[i],u[j]
if x.Row()!=y.Row() { return x.Row()<y.Row() }
if x.Col()!=y.Col() { return x.Col()!=y.Col() }
return x.Name()<y.Name()
package main
import "fmt"
type ChessPiece struct {
row int
col int
piece rune
}
done::Board->Bool
done Board{usedPieces = up, numberOfPieces=n} = length up == n
findCandidate :: ChessPiece -> Board -> Set Board
findCandidate p b
= Data.Set.fromList $
[ newBoard
| rr <- [1 .. (m b)]
, cc <- [1 .. (n b)]
, let pp = createPiece (piece p) rr cc
, let newBoard = place b pp
, isSafe b pp]
data PieceType = Rook | Bishop | Knight | Queen | King deriving(Show, Eq, Ord)
data ChessPiece = Piece {row:: !Int, col:: !Int, piece:: PieceType} deriving(Eq, Ord)
data Board = Board{m:: !Int, n:: !Int, usedPieces:: Set ChessPiece , numberOfPieces:: !Int} deriving(Eq, Ord)
/***
* @param board ChessBoard
* @param pieces Chess Pieces selected by the user
* @param solutions valid solutions to the problem
* @param testedConfigurations Board configurations to which solutions were not found
* @return return a list of possible solutions to the problem in the form of a list of filled chess boards
*/
public static Set<Board> solution(Board board, List<Character> pieces, Set<Board> solutions, Set<Board> testedConfigurations) {
if (!pieces.isEmpty()) { // if pieces is empty I return the solutions
for (int i = 1; i < board.getM(); i++) {
public class Board {
private int M;
private int N;
private char[][] board;
private ArrayList<ChessPiece> usedPieces;
}
public class Bishop extends ChessPiece {
public boolean attacks(ChessPiece dest) {
return Math.abs(dest.getRow() - this.getRow()) == Math.abs(dest.getCol() - this.getCol());
}
@Override
public char piece() {
return 'B';
}