generated from sigonasr2/CPlusPlusProjectTemplate
Done!
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
a89d5b6511
commit
af46e163d8
Binary file not shown.
141
input
Normal file
141
input
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 3
|
||||||
|
addx 2
|
||||||
|
addx 4
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx -37
|
||||||
|
addx 37
|
||||||
|
addx -34
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
addx -2
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 15
|
||||||
|
addx -8
|
||||||
|
addx -9
|
||||||
|
addx 21
|
||||||
|
addx -9
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
addx 3
|
||||||
|
addx -2
|
||||||
|
addx -38
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 37
|
||||||
|
addx -33
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 1
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx -36
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 6
|
||||||
|
addx 21
|
||||||
|
addx -17
|
||||||
|
addx 18
|
||||||
|
addx -8
|
||||||
|
addx -7
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx -8
|
||||||
|
addx 13
|
||||||
|
addx -2
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
addx -2
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx -38
|
||||||
|
addx 4
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 34
|
||||||
|
addx -29
|
||||||
|
addx -2
|
||||||
|
addx 10
|
||||||
|
addx -3
|
||||||
|
addx 2
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx -22
|
||||||
|
addx 2
|
||||||
|
addx 23
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx -18
|
||||||
|
addx 19
|
||||||
|
addx -38
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 4
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 8
|
||||||
|
addx -1
|
||||||
|
addx -30
|
||||||
|
addx 31
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx -35
|
||||||
|
noop
|
114
main.cpp
114
main.cpp
@ -4,86 +4,54 @@
|
|||||||
|
|
||||||
using namespace olc;
|
using namespace olc;
|
||||||
|
|
||||||
class Example : public olc::PixelGameEngine
|
void incrementClock(int&clockCycle,int®,int&sum){
|
||||||
{
|
if (clockCycle%40>=reg-1&&clockCycle%40<=reg+1){
|
||||||
public:
|
std::cout<<'#';
|
||||||
Example()
|
|
||||||
{
|
|
||||||
sAppName = "Example";
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
bool RayVsRect(const vf2d ray_origin, const vf2d ray_dir, const olc::utils::geom2d::rect<float> target, vf2d&contact_point, vf2d&contact_normal, float&t_hit_near){
|
|
||||||
|
|
||||||
contact_normal = { 0, 0 };
|
|
||||||
contact_point = { 0, 0 };
|
|
||||||
|
|
||||||
vf2d t_near = {(target.pos.x - ray_origin.x) / ray_dir.x, (target.pos.y - ray_origin.y) / ray_dir.y};
|
|
||||||
vf2d t_far = {(target.pos.x + target.size.x - ray_origin.x) / ray_dir.x, (target.pos.y + target.size.y - ray_origin.y) / ray_dir.y};
|
|
||||||
|
|
||||||
if (t_near.x > t_far.x) {float b; b = t_near.x; t_near.x = t_far.x; t_far.x = b;};
|
|
||||||
if (t_near.y > t_far.y) {float b; b = t_near.y; t_near.y = t_far.y; t_far.y = b;};
|
|
||||||
|
|
||||||
if (t_near.x > t_far.y || t_near.y > t_far.x) return false;
|
|
||||||
|
|
||||||
t_hit_near = fmax(t_near.x, t_near.y);
|
|
||||||
float t_hit_far = fmin(t_far.x, t_far.y);
|
|
||||||
|
|
||||||
if (t_hit_far < 0) return false;
|
|
||||||
|
|
||||||
contact_point.x = ray_origin.x + t_hit_near * ray_dir.x;
|
|
||||||
contact_point.y = ray_origin.y + t_hit_near * ray_dir.y;
|
|
||||||
|
|
||||||
if (t_near.x > t_near.y)
|
|
||||||
if ( 1.0f / ray_dir.x < 0)
|
|
||||||
contact_normal = { 1, 0 };
|
|
||||||
else
|
|
||||||
contact_normal = { -1, 0};
|
|
||||||
else
|
|
||||||
if ( t_near.x < t_near.y)
|
|
||||||
if ( 1.0f / ray_dir.y < 0)
|
|
||||||
contact_normal = { 0, 1 };
|
|
||||||
else
|
|
||||||
contact_normal = { 0, -1 };
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
vf2d originPoint={16,16};
|
|
||||||
bool OnUserCreate() override
|
|
||||||
{
|
|
||||||
// Called once at the start, so create things here
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OnUserUpdate(float fElapsedTime) override
|
|
||||||
{
|
|
||||||
vf2d velocity={(GetKey(D).bHeld-GetKey(A).bHeld)*20*fElapsedTime,(GetKey(S).bHeld-GetKey(W).bHeld)*20*fElapsedTime};
|
|
||||||
vf2d contact_point;
|
|
||||||
vf2d contact_normal;
|
|
||||||
float t_hit_near;
|
|
||||||
|
|
||||||
Clear(Pixel(64,64,255));
|
|
||||||
if (!olc::utils::geom2d::overlaps(olc::utils::geom2d::circle<float>{originPoint+velocity,5},olc::utils::geom2d::rect<float>{{32,32},{64,32}})) {
|
|
||||||
originPoint+=velocity;
|
|
||||||
DrawCircle(originPoint,5);
|
|
||||||
} else {
|
} else {
|
||||||
DrawCircle(originPoint,5,RED);
|
std::cout<<'.';
|
||||||
}
|
}
|
||||||
DrawLine(originPoint,GetMousePos());
|
clockCycle++;
|
||||||
|
if (clockCycle%40==0){
|
||||||
DrawRect({32,32},{64,32},RayVsRect(originPoint, GetMousePos()-originPoint, olc::utils::geom2d::rect<float>{{32,32},{64,32}},contact_point,contact_normal,t_hit_near)&&t_hit_near<1?YELLOW:WHITE);
|
std::cout<<std::endl;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Example demo;
|
std::ifstream file("input");
|
||||||
if (demo.Construct(128, 120, 8, 8))
|
int clockCycle=0;
|
||||||
demo.Start();
|
bool noop=true;
|
||||||
|
int reg=1;
|
||||||
|
int amtToAdd=0;
|
||||||
|
int sum=0;
|
||||||
|
int crt=0;
|
||||||
|
while (file.good()){
|
||||||
|
std::string line;
|
||||||
|
std::getline(file,line);
|
||||||
|
if (line.length()>0){
|
||||||
|
std::string command=line.substr(0,line.find(' '));
|
||||||
|
if (command=="noop"){
|
||||||
|
noop=true;
|
||||||
|
//std::cout<<"noop"<<std::endl;
|
||||||
|
} else {
|
||||||
|
int amt=std::atoi(line.substr(line.find(' ')+1,std::string::npos).c_str());
|
||||||
|
//std::cout<<amt<<std::endl;
|
||||||
|
amtToAdd=amt;
|
||||||
|
noop=false;
|
||||||
|
}
|
||||||
|
if (noop){
|
||||||
|
incrementClock(clockCycle,reg,sum);
|
||||||
|
} else {
|
||||||
|
for (int i=0;i<2;i++){
|
||||||
|
incrementClock(clockCycle,reg,sum);
|
||||||
|
}
|
||||||
|
reg+=amtToAdd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//std::cout<<line<<std::endl;
|
||||||
|
}
|
||||||
|
//std::cout<<"Sum: "<<sum<<std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
55
part1
Normal file
55
part1
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#define OLC_PGE_APPLICATION
|
||||||
|
#include "pixelGameEngine.h"
|
||||||
|
#include "olcutils.h"
|
||||||
|
|
||||||
|
using namespace olc;
|
||||||
|
|
||||||
|
void incrementClock(int&clockCycle,int®,int&sum){
|
||||||
|
clockCycle++;
|
||||||
|
if (clockCycle==20||
|
||||||
|
clockCycle==60||
|
||||||
|
clockCycle==100||
|
||||||
|
clockCycle==140||
|
||||||
|
clockCycle==180||
|
||||||
|
clockCycle==220){
|
||||||
|
sum+=clockCycle*reg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::ifstream file("input");
|
||||||
|
int clockCycle=0;
|
||||||
|
bool noop=true;
|
||||||
|
int reg=1;
|
||||||
|
int amtToAdd=0;
|
||||||
|
int sum=0;
|
||||||
|
while (file.good()){
|
||||||
|
std::string line;
|
||||||
|
std::getline(file,line);
|
||||||
|
if (line.length()>0){
|
||||||
|
std::string command=line.substr(0,line.find(' '));
|
||||||
|
if (command=="noop"){
|
||||||
|
noop=true;
|
||||||
|
//std::cout<<"noop"<<std::endl;
|
||||||
|
} else {
|
||||||
|
int amt=std::atoi(line.substr(line.find(' ')+1,std::string::npos).c_str());
|
||||||
|
//std::cout<<amt<<std::endl;
|
||||||
|
amtToAdd=amt;
|
||||||
|
noop=false;
|
||||||
|
}
|
||||||
|
if (noop){
|
||||||
|
incrementClock(clockCycle,reg,sum);
|
||||||
|
} else {
|
||||||
|
for (int i=0;i<2;i++){
|
||||||
|
incrementClock(clockCycle,reg,sum);
|
||||||
|
}
|
||||||
|
reg+=amtToAdd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout<<line<<std::endl;
|
||||||
|
}
|
||||||
|
std::cout<<"Sum: "<<sum<<std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
146
testinput
Normal file
146
testinput
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
addx 15
|
||||||
|
addx -11
|
||||||
|
addx 6
|
||||||
|
addx -3
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx -8
|
||||||
|
addx 13
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx -1
|
||||||
|
addx -35
|
||||||
|
addx 1
|
||||||
|
addx 24
|
||||||
|
addx -19
|
||||||
|
addx 1
|
||||||
|
addx 16
|
||||||
|
addx -11
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 21
|
||||||
|
addx -15
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -3
|
||||||
|
addx 9
|
||||||
|
addx 1
|
||||||
|
addx -3
|
||||||
|
addx 8
|
||||||
|
addx 1
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -36
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 6
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 7
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx -13
|
||||||
|
addx 13
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
addx -33
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 8
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 2
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 17
|
||||||
|
addx -9
|
||||||
|
addx 1
|
||||||
|
addx 1
|
||||||
|
addx -3
|
||||||
|
addx 11
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -13
|
||||||
|
addx -19
|
||||||
|
addx 1
|
||||||
|
addx 3
|
||||||
|
addx 26
|
||||||
|
addx -30
|
||||||
|
addx 12
|
||||||
|
addx -1
|
||||||
|
addx 3
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -9
|
||||||
|
addx 18
|
||||||
|
addx 1
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 9
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 2
|
||||||
|
addx -37
|
||||||
|
addx 1
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 15
|
||||||
|
addx -21
|
||||||
|
addx 22
|
||||||
|
addx -6
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 2
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx -10
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 20
|
||||||
|
addx 1
|
||||||
|
addx 2
|
||||||
|
addx 2
|
||||||
|
addx -6
|
||||||
|
addx -11
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
Loading…
x
Reference in New Issue
Block a user