You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
Dart
64 lines
1.8 KiB
Dart
import 'package:aoc2020/aocbase.dart';
|
|
import 'package:aoc2020/model/comp.dart';
|
|
import 'package:aoc2020/model/readdata.dart';
|
|
|
|
class AOC20201208 extends AOCBase {
|
|
@override
|
|
Future<void> a({bool test}) async {
|
|
var filename = (test ?? false) ? classStringTest : classString;
|
|
var mylist = await ReadData.readFileString(filename);
|
|
Comp().reset();
|
|
var index = 0;
|
|
var notDone = true;
|
|
while (notDone && index < mylist.length) {
|
|
index = Comp().pc;
|
|
notDone = Comp().execute(mylist[index]);
|
|
}
|
|
answerA = Comp().acc;
|
|
}
|
|
|
|
@override
|
|
Future<void> b({bool test}) async {
|
|
var jmpList = <int>[];
|
|
var nopList = <int>[];
|
|
var filename = (test ?? false) ? classStringTest : classString;
|
|
var mylist = await ReadData.readFileString(filename);
|
|
for (var index = 0; index < mylist.length; index++) {
|
|
var parse = mylist[index].split(' ');
|
|
if (parse[0] == 'jmp') jmpList.add(index);
|
|
if (parse[0] == 'nop') nopList.add(index);
|
|
}
|
|
for (var cnt = 0; cnt < jmpList.length; cnt++) {
|
|
// print(' ');
|
|
Comp().reset();
|
|
var index = 0;
|
|
Comp().swapJmp(jmpList[cnt]);
|
|
var notDone = true;
|
|
while (notDone && index < mylist.length) {
|
|
index = Comp().pc;
|
|
if (index < mylist.length) notDone = Comp().execute(mylist[index]);
|
|
}
|
|
if (notDone) {
|
|
answerB = Comp().acc;
|
|
break;
|
|
}
|
|
}
|
|
if (answerB == null) {
|
|
for (var cnt = 0; cnt < nopList.length; cnt++) {
|
|
// print(' ');
|
|
Comp().reset();
|
|
var index = 0;
|
|
Comp().swapNop(nopList[cnt]);
|
|
var notDone = true;
|
|
while (notDone && index < mylist.length) {
|
|
index = Comp().pc;
|
|
if (index < mylist.length) notDone = Comp().execute(mylist[index]);
|
|
}
|
|
if (notDone) {
|
|
answerB = Comp().acc;
|
|
break;
|
|
}
|
|
}}
|
|
}
|
|
}
|