Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

37 changes: 37 additions & 0 deletions src/Domino.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public class Domino {

private int upsideValue;
private int downsideValue;

public Domino(int upsideValue, int downsideValue) {
this.upsideValue = upsideValue;
this.downsideValue = downsideValue;
}

public boolean has(int value) {
return upsideValue == value || downsideValue == value;
}

public boolean canBeNextTo(Domino other) {
return this.upsideValue == other.upsideValue
|| this.upsideValue == other.downsideValue
|| this.downsideValue == other.upsideValue
|| this.downsideValue == other.downsideValue;
}

public int getUpsideValue() {
return upsideValue;
}

public void setUpsideValue(int upsideValue) {
this.upsideValue = upsideValue;
}

public int getDownsideValue() {
return downsideValue;
}

public void setDownsideValue(int downsideValue) {
this.downsideValue = downsideValue;
}
}
53 changes: 53 additions & 0 deletions src/H15.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.util.Arrays;

public class H15 extends HelpCommands {

public static int ex45pg114(Node<Integer> lst, Node<Integer> p, Node<Integer> q) {
if (lst == q) {
return lst.getValue();
}
if (p == null || lst == p) {
return lst.getValue() + ex45pg114(lst.getNext(), null, q);
}
return ex45pg114(lst.getNext(), p, q);
}

public static int ex46pg114(Node<Integer> lst1, Node<Integer> lst2) {
if (lst1 == null && lst2 == null) {
return 0;
}
if (lst1 == null) {
return 1 + ex46pg114(null, lst2.getNext());
}
if (lst2 == null) {
return 1 + ex46pg114(lst1.getNext(), null);
}
return ex46pg114(lst1.getNext(), lst2.getNext());
}

public static int ex48pg115(Domino[] dominoBricks, Domino domino) {
int counter = 0;
for (Domino dominoBrick : dominoBricks) {
counter += domino.canBeNextTo(dominoBrick) ? 1 : 0;
}
return counter;
}

public static int ex52pg116(Node<int[]> node){
int unevenLotteries = 0;
while (node != null) {
if (Arrays.stream(node.getValue()).max().getAsInt() - Arrays.stream(node.getValue()).min().getAsInt() <= 20) {
unevenLotteries++;
}
node = node.getNext();
}
return unevenLotteries;
}

public static void main(String[] args) {
Node<Integer> exp = buildNodes(1, 2, 3, 4, 5, 6);
Node<Integer> exp2 = buildNodes(1, 2, 3, 4, 5, 6, 7, 8);
System.out.println(ex46pg114(exp, exp2));
}

}
14 changes: 14 additions & 0 deletions src/HelpCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,18 @@ public static Node<Integer> reverseNode(Node<Integer> fst) {
return prev;
}

public static <T> T valueAt(Node<T> node, int index) {
for (int i = 0; i < index; i++) {
node = node.getNext();
}
return node.getValue();
}

public static <T> Node<T> nodeAt(Node<T> node, int index) {
for (int i = 0; i < index; i++) {
node = node.getNext();
}
return node;
}

}
Binary file added src/pg105.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/pg107.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.