Jump to content

Advent Of Code - 25 challenges for December

madknight3

Grab the code from the web?

You have to use bitwise operators &,|,~,<<,>> there's no reason to be converting to and from binary.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

You have to use bitwise operators &,|,~,<<,>> there's no reason to be converting to and from binary.

jesus, what do they do? :DD never encountered with them.

Second thing, there are a lot of letters with no value (most of them) how do i deal with them?

Third. can you check if i do day 8 correct?

int escape=0;string darth = input[i];for(int j=0; j<darth.length(); j++)        {            if(darth[j]=='\\' && darth[j+1]=='\\' && darth[j+2]!='\\')// checking for \\                {escape++;                //cout<<darth<<endl;                }            else if(darth[j]=='\"' && darth[j-1]=='\\' && j!= darth.leangth()-2)// checking for /"                {escape++;                //cout<<darth<<endl;                }          else if(darth[j]=='\\' && darth[j+1]=='x'                    && /*1ST check for abcdef*/            ((darth[j+2]=='a' || darth[j+2]=='b' || darth[j+2]=='c'            || darth[j+2]=='d' || darth[j+2]=='e' || darth[j+2]=='f') ||/*BRUTE FORCE*/(darth[j+2]=='0' ||darth[j+2]=='1'            ||darth[j+2]=='2' ||darth[j+2]=='3' ||darth[j+2]=='4' || darth[j+2]=='5'|| darth[j+2]=='6'            || darth[j+2]=='7' || darth[j+2]=='8' || darth[j+2]=='9')) &&            /* 2ND CHECK*/            ((darth[j+3]=='a' || darth[j+3]=='b'            ||darth[j+3]=='c' || darth[j+3]=='d' || darth[j+3]=='e' || darth[j+3]=='f') ||/*BRUTE FORCE*/(darth[j+3]=='0' ||            darth[j+3]=='1' ||darth[j+3]=='2' ||darth[j+3]=='3' ||darth[j+3]=='4' || darth[j+3]=='5'|| darth[j+3]=='6'            || darth[j+3]=='7' || darth[j+3]=='8' || darth[j+3]=='9')))// cheking for \x**               {                escape=escape + 3;               //cout<<darth<<endl;               }        }        //cout<<escape<<" ";        //cout<<escape<<endl;        sum=sum + (darth.length() - 2 - escape); // -2 for " at the begging and " at the end

my answer is too high

sorry for brute force :D

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

You have to use bitwise operators &,|,~,<<,>> there's no reason to be converting to and from binary.

If you were doing it by hand of course it would be very useful and when first leaning the operators, very helpful.

Link to comment
Share on other sites

Link to post
Share on other sites

jesus, what do they do? :DD never encountered with them.

http://www.learncpp.com/cpp-tutorial/38-bitwise-operators/

Second thing, there are a lot of letters with no value (most of them) how do i deal with them?

They get their values from the output of other wires and gates.

Third. can you check if i do day 8 correct?

Don't know if it's the only problem but hex codes can contain numbers as well, not just a-f. However this is another problem I'd suggest just using another language. In Python all the work can be done for you in the single line

codecs.getdecoder("unicode_escape")(line[1:-1])[0]

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

http://www.learncpp.com/cpp-tutorial/38-bitwise-operators/

They get their values from the output of other wires and gates.

Don't know if it's the only problem but hex codes can contain numbers as well, not just a-f. However this is another problem I'd suggest just using another language. In Python all the work can be done for you in the single line

codecs.getdecoder("unicode_escape")(line[1:-1])[0]

My current answer is 1327 (updated my code). i've spent like 2-3 hours searching for mistakes...

could you check the answer so that i would know when my mistakes are gone? http://pastebin.com/GbX9eGS6

cause i have to wait for 10 min. to input my answer now.

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

My current answer is 1327 (updated my code). i've spent like 2-3 hours searching for mistakes...

could you check the answer so that i would know when my mistakes are gone? http://pastebin.com/GbX9eGS6

cause i have to wait for 10 min. to input my answer now.

I get

1333 for your input so you're pretty close.

When checking for an escaped backslash, why are you looking for 3 slashes?

Edit: also when you find an escape sequence you need to move to the end of that sequence or you may end up double counting things.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

I get

1333

for your input so you're pretty close.

When checking for an escaped backslash, why are you looking for 3 slashes?

Edit: also when you find an escape sequence you need to move to the end of that sequence or you may end up double counting things.

by doing :

i get 1332 :D

for(int i=0; i<charlenght-1; i++)if(darth[j]=='\\' && darth[j+1]=='\\' && darth[j+2]!='x')// checking for "\\"else if(darth[j]=='\"' && darth[j-1]=='\\' && darth[j-2]!='\\')// checking for " \" "

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

http://pastebin.com/K9v6dK8i

 

Day 9.

 

so as i understand i have to travel to :

Faerun, Norrath, Tristram, AlphaCentauri, Arbre, Snowdin and Tambi ?

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

And Straylight

but Straylight can only be the End of the trip?

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

No, it can be anywhere.

but there is no route from starlight only TO it

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

I cheated so hard... didn't code anything, just used a text editor and did math in my head for the first one.

 

Might actually do something some time, but eh..

Thy hath sinneth, and in thy life thou hast fallen to an unholy, unspeakable level of humanity. Thou hast given into your basest needs. And suffered many years under thine Satan-box. However, if thine be willing, as thy hast show yourself to be, thy can ascendeth into thy glorious fold of the glorious church. Go well, my brother, may your temps be low and your frames high. ~ MrDynamicMan

Link to comment
Share on other sites

Link to post
Share on other sites

but there is no route from starlight only TO it

The order doesn't matter, the distance is the same going either way.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

The order doesn't matter, the distance is the same going either way.

Oh

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

I cheated so hard... didn't code anything, just used a text editor and did math in my head for the first one.

 

Might actually do something some time, but eh..

 

I'm not sure if that's cheating or making it harder lol

 

I expect most people with a bit of coding expereince can code and run the problem faster than it would take them to do it in their head

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not sure if that's cheating or making it harder lol

 

I expect most people with a bit of coding expereince can code and run the problem faster than it would take them to do it in their head

I literally pasted the whole thing in there and used the 'find' function for ( and ) separately. Then I did the math for the numbers of each.

Thy hath sinneth, and in thy life thou hast fallen to an unholy, unspeakable level of humanity. Thou hast given into your basest needs. And suffered many years under thine Satan-box. However, if thine be willing, as thy hast show yourself to be, thy can ascendeth into thy glorious fold of the glorious church. Go well, my brother, may your temps be low and your frames high. ~ MrDynamicMan

Link to comment
Share on other sites

Link to post
Share on other sites

I literally pasted the whole thing in there and used the 'find' function for ( and ) separately. Then I did the math for the numbers of each.

 

I see, I thought you counted everything out yourself. That's certainly more efficient lol

Link to comment
Share on other sites

Link to post
Share on other sites

Ok guys , I've decided I should probably use a language I'm not as familiar with for these challenges. After all , they should be challenging , ey? Ah , who am I kidding. They got difficult enough down the road. Still , I've solved them in my trusy C++.

 

So...I'm doing it with...

Brainfuck!

Ok no , that is probably a really bad idea.

Chef?

No.

 

Ok , I'll stop with the jokes. I'll start doing these in Python. Let's see how it turns out. I know how it works , I've just never really used it.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Ok guys , I've decided I should probably use a language I'm not as familiar with for these challenges. After all , they should be challenging , ey? Ah , who am I kidding. They got difficult enough down the road. Still , I've solved them in my trusy C++.

 

So...I'm doing it with...

Brainfuck!

Ok no , that is probably a really bad idea.

Chef?

No.

 

Ok , I'll stop with the jokes. I'll start doing these in Python. Let's see how it turns out. I know how it works , I've just never really used it.

 

I decided to do the same thing. As I work in a .NET company, my main languages currently are C# and VB.NET so I wanted to use something a bit different for these challenges. While I'm rusty with Python and Java, I probably could have managed with them just fine so I wanted to take a different route. I decided on Haskell since it takes me out of my comfort area and I was already in the midst of learning it when these challenges started anyway. If not Haskell, I probably would have went with F# or Rust as they are next on my list to play around with.

Link to comment
Share on other sites

Link to post
Share on other sites

Day 12.
How the heck i can get those numbers? (c++)

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Day 12.

How the heck i can get those numbers? (c++)

 

For part 1 you can simply go through the string character by character looking for numbers. As you find your numbers you convert them to integers and add them up.

 

Keep in mind that numbers together need to be combined.

[1,2,3] is 1 + 2 + 3 = 6[123, 456] is 123 + 456 = 579, not 1 + 2 + 3 + 4 + 5 + 6
Link to comment
Share on other sites

Link to post
Share on other sites

 

For part 1 you can simply go through the string character by character looking for numbers. As you find your numbers you convert them to integers and add them up.

 

Keep in mind that numbers together need to be combined.

[1,2,3] is 1 + 2 + 3 = 6[123, 456] is 123 + 456 = 579, not 1 + 2 + 3 + 4 + 5 + 6

i'm not sure about the second part of the example, that's why i ask

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
Share on other sites

Link to post
Share on other sites

i'm not sure about the second part of the example, that's why i ask

 

Here's one way to do it.

Once you find the first digit, you start constructing your number as a string (or array or whatever). You keep constructing the number until you read in a non-digit character. Once you find a non-digit, you have the full number and can convert it to an integer. Example

So if you have[1,"red", 234]You start looking char by char.First is '[' which isn't a number so you ignore it.Next is '1' so you start your number with "1"Next is ',' which isn't a number so you ignore it and you stop your previous numberThis leaves you with just "1" that you can convert and add to your sum.Then you keep checking and ignoring letters until you get to '2'So you start your next number with "2"Next is '3' which is a number so you add it to "2". Now you have "23".Next is '4' which is a number so you add it to "23". Now you have "234".Next is ']' which isn't a number so you ignore it and stop the previous number.Which leaves you with "234" that you can convert and sum.

Link to comment
Share on other sites

Link to post
Share on other sites

Anyone been able to keep up with the problems? I've only managed to get both parts done on 12 problems and just the first part done on 2 more (26 stars total). I'm going to try and keep going with them though.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×