-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/jelmstrom/sevenlanguages_…
- Loading branch information
Showing
16 changed files
with
170 additions
and
15 deletions.
There are no files selected for viewing
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,18 @@ | ||
adjacent(1,2). | ||
adjacent(1,3). | ||
adjacent(1,4). | ||
adjacent(1,5). | ||
adjacent(2,3). | ||
adjacent(2,4). | ||
adjacent(3,4). | ||
adjacent(4,5). | ||
adjacent(2,1). | ||
adjacent(3,1). | ||
adjacent(4,1). | ||
adjacent(5,1). | ||
adjacent(3,2). | ||
adjacent(4,2). | ||
adjacent(4,3). | ||
adjacent(5,4). | ||
|
||
adjacent(2,3). |
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,10 @@ | ||
food_type(velveeta, cheese). | ||
food_type(ritz, cracker). | ||
food_type(spam, meat). | ||
food_type(sausage, meat). | ||
food_type(jolt, soda). | ||
food_type(twinkie, dessert). | ||
flavor(sweet, dessert). | ||
flavor(savory, meat). | ||
flavor(savory, cheese). | ||
flavor(sweet, soda). |
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,5 +1,8 @@ | ||
book(lotr,[tolkien]). | ||
book(hitchikers_guide, [adams]). | ||
book(patterns,[gamma, vlissides, helm, johnson]). | ||
%-- author([]). | ||
%-- author([Head|Tail]) :- book(_,Head), author(Tail). | ||
book(lotr,tolkien). | ||
book(hitchikers_guide, adams). | ||
book(patterns, johnson). | ||
book(patterns, helm). | ||
book(patterns, vlissides). | ||
book(patterns, gamma). | ||
|
||
author(Author, Book) :- book(Book,Author). |
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,15 @@ | ||
different(red, green). different(red, blue). | ||
different(green, red). different(green, blue). | ||
different(blue, red). different(blue, green). | ||
coloring(Alabama, Mississippi, Georgia, Tennessee, Florida) :- | ||
different(Mississippi, Tennessee), | ||
different(Mississippi, Alabama), | ||
different(Alabama, Tennessee), | ||
different(Alabama, Mississippi), | ||
different(Alabama, Georgia), | ||
different(Alabama, Florida), | ||
different(Georgia, Florida), | ||
different(Georgia, Tennessee). | ||
different(Canada, Tennessee). | ||
|
||
|
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,33 @@ | ||
valid_position((Row,Column)):- member(Row,[1,2,3,4,5,6,7,8]), member(Column,[1,2,3,4,5,6,7,8]). | ||
valid_positions([]). | ||
valid_positions([Queen|Tail]) :- valid_position(Queen),valid_positions(Tail). | ||
|
||
|
||
collect_rows([],[]). | ||
collect_rows([(Row,_)|Tail],[Row|RTail]) :- collect_rows(Tail, RTail). %-- recurse and stuff values in row | ||
unique_rows(Board) :- collect_rows(Board,Rows), fd_all_different(Rows). %-- collect and check rows | ||
|
||
|
||
collect_columns([],[]). | ||
collect_columns([(_,Col)|Tail],[Col|CTail]) :- collect_columns(Tail, CTail). %-- recurse and stuff values in row | ||
unique_columns(Board) :- collect_columns(Board,Cols), fd_all_different(Cols). %-- collect and check rows | ||
|
||
diagonal_one([],[]). | ||
diagonal_one([(Row,Col)|Tail], [Y|DTail]) :- Y is (Row-Col), diagonal_one(Tail,DTail). %-- subtracting row & Col is inspired (1,1 & 2,2 is on same diagonal (0)) | ||
|
||
diagonal_two([],[]). | ||
diagonal_two([(Row,Col)|Tail], [Y|DTail]) :- Y is (Row+Col), diagonal_two(Tail,DTail). %-- adding row & Col is inspired (1,2) and (2,1) is on same diagonal(3) | ||
|
||
unique_diagonals(Board) :- diagonal_one(Board, DiagonalOne), | ||
fd_all_different(DiagonalOne), | ||
diagonal_two(Board, DiagonalTwo), fd_all_different(DiagonalTwo). | ||
|
||
|
||
|
||
queens(Board) :- | ||
valid_positions(Board), | ||
unique_rows(Board), | ||
unique_columns(Board), | ||
unique_diagonals(Board). | ||
|
||
|
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,37 @@ | ||
four_sudoku(Puzzle, Solution) :- | ||
Solution = Puzzle, | ||
Puzzle = | ||
[S11,S12,S13,S14, | ||
S21,S22,S23,S24, | ||
S31,S32,S33,S34, | ||
S41,S42,S43,S44], | ||
fd_domain(Solution,1,4), | ||
|
||
Row1=[S11,S12,S13,S14], | ||
Row2=[S21,S22,S23,S24], | ||
Row3=[S31,S32,S33,S34], | ||
Row4=[S41,S42,S43,S44], | ||
|
||
Col1=[S11,S21,S31,S41], | ||
Col2=[S12,S22,S32,S42], | ||
Col3=[S13,S23,S33,S43], | ||
Col4=[S14,S24,S34,S44], | ||
|
||
Sq1=[S11,S12,S21,S22], | ||
Sq2=[S31,S32,S41,S42], | ||
Sq3=[S13,S14,S23,S24], | ||
Sq4=[S33,S34,S43,S44], | ||
|
||
fd_all_different(Row1), | ||
fd_all_different(Row2), | ||
fd_all_different(Row3), | ||
fd_all_different(Row4), | ||
fd_all_different(Col1), | ||
fd_all_different(Col2), | ||
fd_all_different(Col3), | ||
fd_all_different(Col4), | ||
fd_all_different(Sq1), | ||
fd_all_different(Sq2), | ||
fd_all_different(Sq3), | ||
fd_all_different(Sq4). | ||
|
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 @@ | ||
|
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,4 @@ | ||
|
||
concatenate([], List, List). | ||
concatenate([Head|Tail1], List, [Head|Tail2]) :- | ||
concatenate(Tail1, List, Tail2) |
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,4 @@ | ||
fib(0,0). | ||
fib(1,1). | ||
fib(N,FIB):- | ||
N>1,N1 is N-1, N2 is N -2, fib((N1),X) , fib(N2,Y), FIB is X+Y. |
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,3 @@ | ||
fib(0,0). | ||
fib(1,1). | ||
fib(N, Result):- First is Nth -1, Second is Nth-2, fib(First,FirstResult), fib(Second, SecondResult), Result is (FirstResult + SecondResult). |
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 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,4 @@ | ||
last([],[]). | ||
last([Head|[TailHead|TailTail]],Last):- | ||
last(TailTail,Last),TailHead. | ||
|
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,5 @@ | ||
count(0, []). | ||
count(Count, [Head|Tail]) :- count(TailCount, Tail), Count is TailCount + 1. | ||
sum(0, []). | ||
sum(Total, [Head|Tail]) :- sum(Sum, Tail), Total is Head + Sum. | ||
average(Average, List) :- sum(Sum, List), count(Count, List), Average is Sum/Count. |
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,12 @@ | ||
|
||
reverseA([],List, List). | ||
reverseA([Head|Tail],Temp,Ny):- | ||
reverseA(Tail,[Head, Temp],Ny). | ||
|
||
rev([], Rev, Rev). | ||
rev([Head|Tail],Temp,Rev) :- rev(Tail,[Head|Temp], Rev). | ||
|
||
|
||
reverseB([],[]). | ||
reverseB([Head|Tail],[List,Head]) :- | ||
reverseB(Tail,List). |
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,15 @@ | ||
sortera([],[]). | ||
sortera([A],[A]). | ||
sortera([A,B|TAIL],AB):- | ||
newList(A,B,C),sortera(TAIL,C) | ||
|
||
newList(A,B,C):- | ||
( A =< B | ||
-> C = [C, A,B] | ||
; C = [C, B,A] | ||
). | ||
newList(A,B,[]):- | ||
( A =< B | ||
-> C = [A,B] | ||
; C = [B,A] | ||
). |