This file contains hidden or 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 java.io.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.io.InputStreamReader; | |
| import java.io.PrintWriter; | |
| import java.util.ArrayList; | |
| import java.util.StringTokenizer; | |
| public class Main { |
This file contains hidden or 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 java.io.IOException; | |
| import java.util.Scanner; | |
| // This codes solves the puzzle WORD1 + WORD2 = WORD3 | |
| // The simpler version (SEND MORE MONEY) will require less code. | |
| public class SendMoreMoney { | |
| public static void main(String[] args) throws IOException { |
This file contains hidden or 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_module(library(clpfd)). | |
| increase(L):- | |
| L ins 1..100, | |
| check_increasing(L), | |
| label(L). | |
| check_increasing([]). | |
| check_increasing([_]). |
This file contains hidden or 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_module(library(clpfd)). | |
| trains([[1,2,0,1], % from station, to station, departs at, arrives at | |
| [1,4,0,5], | |
| [2,3,4,5], | |
| [2,3,0,1], | |
| [3,4,5,6], | |
| [3,4,2,3], | |
| [3,4,8,9]]). |
This file contains hidden or 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_module(library(clpfd)). | |
| employees([ | |
| [1, 75, 0, 30, 25], | |
| [2, 83, 0, 45, 25], | |
| [3, 90, 1, 45, 50], | |
| [4, 45, 3, 75, 25], | |
| [5, 89, 0, 52, 50] | |
| ]). |
This file contains hidden or 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_module(library(clpfd)). | |
| enemy_pairs([[1,2], [4,6], [4,7], [4, 9],[9,11], [12, 14], [14,16]]). | |
| length_(Len, List):- length(List, Len). | |
| children(Grid):- | |
| length(Grid, 4), | |
| maplist(length_(4), Grid), | |
| maplist(domain, Grid), |
This file contains hidden or 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
| // Backtracking solution + tracing using helper global variables | |
| import java.io.IOException; | |
| import java.util.Scanner; | |
| public class Board1 { | |
| public static void main(String[] args) throws IOException { | |
| Scanner sc = new Scanner(System.in); | |
| int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(); |
This file contains hidden or 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_module(library(clpfd)). | |
| % patient(ID, Name, YearAdmitted, MonthAdmitted, | |
| % DayAdmitted, HourAdmitted, MinuteAdmitted, Status, Payment) | |
| patient(1, 'Bob Jones', 2014, 10, 1, 4, 55, 0, 2). | |
| patient(2, 'Sally Smith', 2014, 9, 29, 5, 15, 1, 0). | |
| patient(3, 'Ted Overton', 2014, 9, 30, 14, 15, 0, 0). | |
| patient(4, 'Arnold Abouja', 2014, 10, 1, 5, 0, 0, 0). | |
| patient(5, 'Seth Humbolt', 2014, 10, 1, 5, 10, 0, 0). |
This file contains hidden or 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_module(library(clpfd)). | |
| patterns([ | |
| pattern(2, 0, 1, 0), | |
| pattern(1, 2, 0, 0), | |
| pattern(1, 1, 1, 1), | |
| pattern(1, 0, 3, 0), | |
| pattern(0, 3, 0, 1), | |
| pattern(0, 2, 2, 0), | |
| pattern(0, 1, 3, 1), |
This file contains hidden or 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_module(library(clpfd)). | |
| % valid positions are in [-Saw_L, Saw_L]. | |
| % works for many variable weights and many variable positions. | |
| seesaw_balance(Saw_L, Weights, Positions):- | |
| length(Weights, N), length(Positions, N), NSaw_L is -Saw_L, | |
| Weights ins 0..500, Positions ins NSaw_L..Saw_L, | |
| angular_moment(Weights, Positions, 0), | |
| apart_positions(Positions), | |
| label(Positions), label(Weights). |
OlderNewer