Add files via upload

This commit is contained in:
kamoshi 2019-12-07 02:37:22 +01:00 committed by GitHub
parent 00160e54e5
commit a74ecc7bcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 2959 additions and 0 deletions

View file

@ -0,0 +1,77 @@
package day01;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Scanner;
public class Frequency {
private HashSet<Integer> pastValues = new HashSet<Integer>();
private int frequency = 0;
private boolean repeated;
public void setRepeated() {
this.repeated = true;
}
public boolean getRepeated() {
return this.repeated;
}
public void plusFrequency(int plus) {
this.frequency += plus;
}
public void minusFrequency(int minus) {
this.frequency -= minus;
}
public int getFrequency() {
return this.frequency;
}
public boolean compareHashSet(int number) {
return !pastValues.add(number);
}
public void parseFile(File file) {
try {
Scanner scanner = new Scanner(new BufferedReader(new FileReader(file)));
while(scanner.hasNext()) {
String s = scanner.next();
if (s.matches("(\\-)(\\d)+")) {
this.minusFrequency(Integer.parseInt(s.substring(1)));
} else {
this.plusFrequency(Integer.parseInt(s.substring(1)));
}
if (compareHashSet(this.getFrequency())) {
System.out.println("repeat: " + this.getFrequency());
this.setRepeated();
break;
}
}
scanner.close();
}
catch (Exception e) {
System.out.println(e.toString() + " : " + e.getStackTrace().toString());
}
}
public static void main(String[] args) {
File input = new File("src/day01/input.txt");
Frequency f = new Frequency();
while ( !f.getRepeated() ) {
f.parseFile(input);
System.out.println(f.getFrequency());
}
}
}

1000
2018/Java/day01/input.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,66 @@
package day02;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Checksum {
Map<Character,Integer> repeats = new HashMap<Character,Integer>();
int twos = 0;
int threes = 0;
public void parseFile(File file) {
try
{
Scanner scanner = new Scanner(new BufferedReader(new FileReader(file)));
while(scanner.hasNext()) {
String s = scanner.next();
for (int i = 0; i < s.length(); i++ ) {
char c = s.charAt(i);
if (repeats.containsKey(c)) {
int numberOfRepeats = repeats.get(c);
repeats.put(c, ++numberOfRepeats);
} else {
repeats.put(c, 1);
}
}
boolean twoC = false;
boolean threeC = false;
for (int num : repeats.values()) {
if (num == 2 && !twoC) {
twos++;
twoC = true;
} else if (num == 3 && !threeC) {
threes++;
threeC = true;
}
}
repeats.clear();
}
System.out.println(twos * threes);
scanner.close(); // close stream
}
catch (Exception e) {
System.out.println(e.toString() + " : " + e.getStackTrace().toString());
}
}
public static void main(String[] args) {
Checksum chsm = new Checksum();
File f = new File("src/day02/input.txt");
chsm.parseFile(f);
}
}

View file

@ -0,0 +1,54 @@
package day02;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
public class Match {
ArrayList<String> container = new ArrayList<>();
public String parseFile(File file) {
try
{
Scanner scanner = new Scanner(new BufferedReader(new FileReader(file)));
while(scanner.hasNext()) {
String s = scanner.next();
for (int i=0; i < container.size(); i++) { // Iteration through strings already found
String checked = container.get(i);
int discrepancy = 0; // differences found between strings
for (int j = 0; j < s.length(); j++) { // iteration through new string
if (!(s.charAt(j) == checked.charAt(j))) {
discrepancy++;
}
}
if (discrepancy == 1) {
System.out.println("FOUND STRINGS MATCH DELTA 1\n" + checked + "\n" + s);
return s;
}
}
container.add(s);
}
scanner.close(); // close stream
}
catch (Exception e) {
System.out.println(e.toString() + " : " + e.getStackTrace().toString());
}
return "NULL";
}
public static void main(String[] args) {
Match chsm = new Match();
File f = new File("src/day02/input.txt");
chsm.parseFile(f);
}
}

250
2018/Java/day02/input.txt Normal file
View file

@ -0,0 +1,250 @@
auxwcbzrmdvpsjfgkrthnkioqm
auxwcbzrmdvpsjfgbltonyijqe
auxwcbzrmdfpsefgklthnoioqe
auxwcbzrmdvpsjfgkluhnjisqe
auxwcbzrmdvesjfgdzthnyioqe
auxwcbzrmdvhsjfgklthnmijqe
auxwcbzridvpsjfgkltxeyioqe
ayxwcbzrgdvpsjfgklthiyioqe
ajxwcbzrmdvpsjfgklkhnyiode
auxwcbcrmdvpsjfqelthnyioqe
auxwcbzrmsvpsjsgklthnyiope
auxwcbzrmqvpsjzgklghnyioqe
auxwcbzrmdvpsjtqklthxyioqe
auxwcbzrmdopsjfdklthncioqe
auxwcbzrmdvpsjfgkltmhyfoqe
aixwcbzrmdvpsjfgllthdyeoqe
vuxicbzrmdepsjfgklthnyioqe
auxwcbbxmdkpsjfgklthnyioqe
auxwcbzrgdvpsofaklthnyioqe
auxycbzrmdvpsjfgklthnyuose
aujwcbzrmdvprjfgkltcnyioqe
auxwgbzrmdvpsjfgyzthnyioqe
auxwcbzrmavpsjfgkltsnyiome
auxwcbgrmdvpsjfgkdthnrioqe
kuxwcbzrmdvpsyfgklthnyioue
auxwcbzomdvpjdfgklthnyioqe
auxwcbzrmdppsjfgklthvyifqe
aunwubzrmdvpsjrgklthnyioqe
auxwcbzrmoipsjfgklbhnyioqe
auxwdbzrmdvpsjfgmlthnyioce
auxwcbzjmsvpsjfiklthnyioqe
auxwcbzrmwcpsjfcklthnyioqe
auxwcbzfmdvprjfhklthnyioqe
auxdcbzrgdvpsjfgklthnyxoqe
wuxwbbzrmdvpsjfgklthnyiote
auowcbjrmdvpsjfgklthnyfoqe
auxwsbzrmdvpsjfglltcnyioqe
quxwcbzrmdvpkjfgklthnyioqt
vuxwcbzrudvpsjfgklthnyioqi
puxwcbzrmdvgsjfgklthncioqe
luxdcbzrmdvpsjfgkothnyioqe
auxwcbzrmdvpsjfyklthfhioqe
auxwcbqrmdvpsjfgkldhnyiote
quxwcbzrmlvpsjfgklthnyioqi
auxwcbzgmdvpsjfoklthnyiuqe
auxwcbzrmdvpsbfgkltdjyioqe
auxwcbzsmdrpsjfgklthpyioqe
auxwcbzrmfvpsjfwklthnyiote
auxbkpzrmdvpsjfgklthnyioqe
auxwcbzrddvpsjfsklthnyroqe
abxwcbzrmdvpsjfgkltdnyivqe
awxwcbzrmvvpsjfgklthngioqe
auxwcbzrmkvgsjfgkltcnyioqe
auxwcbammdvpsjfgklthpyioqe
auxwcbhrmdvpsjfgtlthnuioqe
auxwcpzrmdvpbjogklthnyioqe
auxwcbzrmdvpslfgklbhkyioqe
auxwcbsrmdvpjjfgkldhnyioqe
auxwcbzrmdqpsjfgauthnyioqe
ydxwcbxrmdvpsjfgklthnyioqe
auxwcbzrmdvpejfgklthnyyofe
auxwchzrmxvpsjfgklthnyioqh
auxwcbzrtdvpsjfgklxhnzioqe
auxwcbyrmdvpsnfgklnhnyioqe
auxwcbzrcdvpsjugklihnyioqe
auxwcbzrddvpsjfgklhhnyiaqe
aumwtbzrmdvpsjfgklthnyitqe
auxucbzrmdvpsjfgklthwfioqe
auxwcbzrmdvpzmfgkllhnyioqe
auxwcbzrmdvpsjhgklthntiome
buxwzbzrmdvpszfgklthnyioqe
ouxwcbzsgdvpsjfgklthnyioqe
auxwcbzrmdvpsjfskltgnyioqz
auxwcbbrmdvpsjftklthnyioqu
quxocbzrmdvpsjfgklthfyioqe
acxwcbzrmdvpsjfgklfhnrioqe
auxwcbzrmdnpsjfrkjthnyioqe
wuxwybzrmdwpsjfgklthnyioqe
auxwgbxrmdvpsjfghlthnyioqe
atxwcbzrmdvnsjfgklthnyjoqe
acxwcbzmmdvpsjfbklthnyioqe
auxhcbzrmdvbsjbgklthnyioqe
auxwlbzrfdvpsjfgxlthnyioqe
auxwmbzrmdfpsjqgklthnyioqe
auxwcbzrmdvpsgfgklahnyigqe
auxwgbzrmdvpsjfgzldhnyioqe
auxwcbzrmdvpydfgklthnyiohe
auxwxbzrmdvpsjfsklchnyioqe
auxqcbzrmdvpsjfgqlthnyiwqe
auxwcozrmdvssbfgklthnyioqe
auxvcczrmdvpsufgklthnyioqe
auxwcbzrudvpsjfgklyhnyioxe
aulwcbzrmdvpsjqgknthnyioqe
auukcbzrmdvpsjfgklthtyioqe
auxwcszimdvpsjfgklthnyigqe
juxwcbzrbdvpsjfgklthnyboqe
auxwcbzrmdvpjofgklthnyioqj
auxwcbzrmdvpsjfgplfhnyione
auxwcbzrmdhpsjfgkltknyeoqe
luxwcqzrmdvpsjfgklthnbioqe
uuxwcbzrmdvpsjfgkithnyiiqe
auxwcbzrmdvpdjfgkrthnyeoqe
auuwcbnrmdvpsjfgklthnjioqe
auxwcnzrmdvpsjvgklthnyooqe
auxwcbzcmdvpsjfcklthnyiose
auxwcbzrldfpsjfgklthjyioqe
auxwcizrmdvpsjfjklthnymoqe
auxwcbtrmdvpsjfgtlphnyioqe
amxwcbzrmdvksjfgklthnyiove
auxwcbzrmdvpszfgkpthnyiuqe
auxwcbzrmdvxdjfgkltqnyioqe
auxwcbzrudvpsjfgklthnymiqe
auxwcbirmdvfsjfgklmhnyioqe
auwwcbzrndvprjfgklthnyioqe
auxwcbormdgpsjfgklbhnyioqe
auxwabzrmdupsjfgklthnyioqt
auxvcbzrmdvpsjfgkltrmyioqe
auxwcbzrmddpsjfsklthnyizqe
auxwcczrmuvpyjfgklthnyioqe
auxwcczrmdvpsnfgkpthnyioqe
auxkcbzrmdvpsjfhklihnyioqe
auxwcbzrmdvpsjfgklthnkijje
auxwcbzcmdvpsjpgkldhnyioqe
auxwcnzrudvpstfgklthnyioqe
xuxwcbzrgdvusjfgklthnyioqe
aaxwcbzrmdvpsjvgklthnyidqe
auxwcbztmdvpsjfgklthnyhqqe
auxwcbzrmfvpsjfgklthnyilfe
auxwcbzrmdvksjfgklthjyioqq
auxwcbzrmdzksjfgktthnyioqe
auxwcbzrmfvpszfgklohnyioqe
auxwckzamdvpsjfgklthnyioqs
auxwcmzrhdvpsjfaklthnyioqe
fuxwcbzrmdapsjfgklrhnyioqe
avxwxbzrmdvpsjfgklthniioqe
auxwubzrmevpsjfgkltpnyioqe
fuxwcbzrgdvpsjfgklhhnyioqe
duxwwbdrmdvpsjfgklthnyioqe
audwcbzrmdvpnjcgklthnyioqe
auxtcbzrmdvpsjmgklthnyyoqe
aucwcbwrmdepsjfgklthnyioqe
auxwcbzrudvpsjfpklthnyiose
auxwcbzridvpsjfsklthxyioqe
auxtcbzrmdvpscfgklyhnyioqe
auxwcbzrmdvppjfgklthnyivee
auxwdbzrmuvpskfgklthnyioqe
auxwubzrmdvosjfgklthnyiope
auxwcbzrmhnpsjfgklthnyimqe
auxwcbzrmdqpwjfgkltpnyioqe
auxwcbormdvpsjljklthnyioqe
auxwcbzrmdjpsjfgkltjpyioqe
auxwcbzrmdvpszfgklthkyizqe
auxwcbzighvpsjfgklthnyioqe
auxwcbzrmdlpsjfgcythnyioqe
auxwcbzumdvpsjflklthnyimqe
pdxwcbzrmdvpsjfgklthnyihqe
auxwcbzrsdvpsjfgklhhvyioqe
auxwcfzamdvpsjfgkmthnyioqe
aexwcdzrmdvpsjogklthnyioqe
auxxcbkrmavpsjfgklthnyioqe
auxwcbzredvssjfgklthryioqe
aupwqbzrmdvpsjfgklthnyioqc
auxwcbzrmdvpkcagklthnyioqe
auxwcbzrmdvwsbfgklthnlioqe
aunwcbzxmdvhsjfgklthnyioqe
auxwcbzrhddpsjfgklthnnioqe
ouxwcbzrmdvtsifgklthnyioqe
auxwcbzrmdqpsjfgklthnyfoqp
auxwrbzrhdvpsjfgolthnyioqe
auxwcbcqmdvpsjugklthnyioqe
auxwcbzrqdvpsjhgklthnjioqe
auxmcbzrmdvpsjfgmlthnyjoqe
auxwcbzrmdvpsjfgzlthnycoqv
auswcbzrmdvpsffgslthnyioqe
auxwcbzrfdvpsjfrmlthnyioqe
auxwcbzrmdvpsjngzlthnxioqe
auxwcbzrmdvpsjfuqlthnyiyqe
auxwzbzrrdvosjfgklthnyioqe
auxwcbzdmdvpsjfikxthnyioqe
guxwcbzrmdvpsjfgmlthnytoqe
auxwcbzrmdvpspfgkytenyioqe
auxvcbzrldvpsjfgklthnyhoqe
auxwcbzrmavpckfgklthnyioqe
autwcbzrmdvpsafgklthnyirqe
auxwcbzrxuvpsjfgklthmyioqe
auxwcbarmdppsjfgklthnywoqe
anxvcbzrmdvpsjfgklthnyijqe
auxwcbwrmdapsjngklthnyioqe
abxwcbzrmdvpsjugkltgnyioqe
auxwcbtrmdvpsjfgkltunyioue
aujwcbzrmovpsjfgklthryioqe
auxwcbzrydvpsjfgklthndikqe
auxwcbzrmdvpsjfgklmrnyioqo
auxwcbzrddvpsjfggithnyioqe
auxwcbzrmdvpfjfaklthlyioqe
fuxtcbzrmdvpsjfgklwhnyioqe
tuxwcbzrjdvpsjfgjlthnyioqe
auxwcbzrmdppsofgklthnyfoqe
auxvclzamdvpsjfgklthnyioqe
auxwcbzrmdvpsjfdklhhnzioqe
auxwcbzrmsvpsvdgklthnyioqe
arxfcbzrmdvpsvfgklthnyioqe
auxzcbzrmdvpsjfgklthnhioqj
auxwcbzrrdvpsjfgpltunyioqe
auxuibzrmdvpwjfgklthnyioqe
auxwcbzrwdqpsjfgklthnyooqe
aujwcbzrmdvpsjvgklthxyioqe
abxwcbzrmfvpsjfgklthnyxoqe
aurwcbzrmdvpshfgklthnyhoqe
auxwcbzjmdvpsjfgknthnycoqe
auxwcbzrmdvpsjfgklmhxwioqe
auxwcbzrmfvpsjfgklthnyiorq
auxwcbormdvpsjfgklwhnlioqe
auxwctzrmdvpsjfgklcknyioqe
awxwcbzrmdvpsjfgvlthnyiome
auxwcbzrmdvpsjfjklthnyixje
auxwcsxrmdvpsjfgkltsnyioqe
auxbmbzrmdvpsjfgklthnyioce
auxwcbzrmdvpsjfukzthnytoqe
aixwcbzrmdvpsjfgllthdyioqe
auxwcbzrmdypsjfgklthnlioqy
auxccbzrmdvpsjfgkltrnnioqe
auxwcznrmdvpsjfgklthnykoqe
auxwmqzrmdvpsjfgilthnyioqe
auxwcbzrmdvpdyfgolthnyioqe
auxwcbzrmdvpsjfgkmohnqioqe
auxwcfzrmzvpsjfoklthnyioqe
auxwjyzrmdvpsjfgulthnyioqe
auxwcgzredvpsjfgkxthnyioqe
wuxwcbtrmdvpsjfgklthnyiofe
auxwcbzrmdopsgfgklthncioqe
auxmcbzjmdvpsjfgklbhnyioqe
auxwlbzrmdvpsjffklthgyioqe
auxwcbzrmrvpsjfgqlthtyioqe
kuxwhbzrmdvpsjfgklthgyioqe
auxwcozrmdgpsjfgklthnydoqe
auxwdbzrmdvpdjfgklthgyioqe
auxwqbzrmdapsvfgklthnyioqe
auqwcbzridvjsjfgklthnyioqe
auxwckzrmdvpsjfoklthnyuoqe
auxwcbzvmdvpsjfgklghnyiome
auxtcbzrmdvpsjqgktthnyioqe
auxwcbzrmdvesjfgkljhnnioqe
auxwcbzrmpvpsqfgklthnqioqe
auxwcbzrmdcpsqfgklthnzioqe
yuxwcbzrmdvpsjggklthnlioqe
auxwcbzradvpsjftklthoyioqe
auxwcbzrmdvjujfgklmhnyioqe
auxwcbzrmdvpsrfgklpinyioqe
auxwobzrvqvpsjfgklthnyioqe

View file

@ -0,0 +1,90 @@
package day03;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author kam
*
* Solution to task 2
*
*/
public class Claim {
boolean overlapped;
int id;
int marginleft;
int margintop;
int width;
int height;
public Claim(int id, int marginleft, int margintop, int width, int height) {
this.id = id;
this.marginleft = marginleft;
this.margintop = margintop;
this.width = width;
this.height = height;
}
public void assignClaim(Claim[][] canvas) {
for (int i=0; i < width; i++) {
for (int j=0; j < height; j++) {
if (canvas[marginleft + i][margintop + j] == null) {
canvas[marginleft + i][margintop + j] = this;
} else {
canvas[marginleft + i][margintop + j].overlapped = true;
this.overlapped = true;
}
}
}
}
public static void main(String[] args) {
ArrayList<Claim> array = new ArrayList<>();
Claim[][] canvas = new Claim[1000][1000];
try
{
Scanner scanner = new Scanner(new BufferedReader(new FileReader(new File("src/day03/input.txt"))));
while(scanner.hasNextLine()) {
String s = scanner.nextLine();
int div1 = s.indexOf('@');
int div2 = s.indexOf(',');
int div3 = s.indexOf(':');
int div4 = s.indexOf('x');
int id = Integer.parseInt(s.substring(1, div1).replaceAll("\\s",""));
int coordx = Integer.parseInt(s.substring(div1+1, div2).replaceAll("\\s",""));
int coordy = Integer.parseInt(s.substring(div2+1, div3).replaceAll("\\s",""));
int height = Integer.parseInt(s.substring(div3+1, div4).replaceAll("\\s",""));
int length = Integer.parseInt(s.substring(div4+1).replaceAll("\\s",""));
Claim generatedClaim = new Claim(id, coordx, coordy, height, length);
generatedClaim.assignClaim(canvas);
array.add(generatedClaim);
}
scanner.close(); // close stream
}
catch (Exception e) {
System.out.println(e.toString() + " : " + e.getStackTrace().toString());
}
for(Claim claim : array) {
if (claim.overlapped == false) {
System.out.println("Not overlapped: " + claim.id);
}
}
}
}

View file

@ -0,0 +1,69 @@
package day03;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Scanner;
public class Overlap {
int[][] canvas = new int[1000][1000];
public String parseFile(File file) {
try
{
Scanner scanner = new Scanner(new BufferedReader(new FileReader(file)));
while(scanner.hasNextLine()) {
String s = scanner.nextLine();
int div1 = s.indexOf('@');
int div2 = s.indexOf(',');
int div3 = s.indexOf(':');
int div4 = s.indexOf('x');
int id = Integer.parseInt(s.substring(1, div1).replaceAll("\\s",""));
int coordx = Integer.parseInt(s.substring(div1+1, div2).replaceAll("\\s",""));
int coordy = Integer.parseInt(s.substring(div2+1, div3).replaceAll("\\s",""));
int height = Integer.parseInt(s.substring(div3+1, div4).replaceAll("\\s",""));
int length = Integer.parseInt(s.substring(div4+1).replaceAll("\\s",""));
System.out.println("" + id + "|" + coordx + "|" + coordy + "|" + height + "|" + length);
for (int i = 0; i < height; i++) {
for (int j = 0; j < length; j++) {
canvas[coordx + i][coordy + j]++;
}
}
}
scanner.close(); // close stream
int overlapped = 0;
for (int i = 0; i < canvas.length; i++) {
for (int j = 0; j < canvas[0].length; j++) {
if (canvas[i][j] > 1) {
overlapped++;
}
}
}
System.out.println(overlapped);
}
catch (Exception e) {
System.out.println(e.toString() + " : " + e.getStackTrace().toString());
}
return "NULL";
}
public static void main(String[] args) {
Overlap ovrlp = new Overlap();
File f = new File("src/day03/input.txt");
ovrlp.parseFile(f);
}
}

1353
2018/Java/day03/input.txt Normal file

File diff suppressed because it is too large Load diff