Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 627 posts ]  Go to page Previous  1 ... 38, 39, 40, 41, 42, 43, 44 ... 63  Next
Author Message
 Post Posted: June 18th, 2017, 10:21 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Bit hung over today but trying to get at least some coding in there
Fixed a bug with the scoring in simon says,

Recursion practice

Problem 1, from the book
Spoiler:
You're working at a company. The salary your first year is 15k a month (swedish book guys :p)
After that, every year you get a 4% increase on your salary + another 400 sek.
Write a function that calculates the salary after x number years. The function should be recursive and only take the number of years as argument.


My solution
Code:
int Increase(int years)
{
   if (years == 1)
   {
      return 15000;
   }
   return Increase(years - 1) * 1.04 + 400;
}

Problem 2

https://community.topcoder.com/stat?c=p ... nt&pm=6011

my function

Code:
int NumTrucks(int numCrates, int loadSize)
{
   int pile1 = numCrates / 2;
   int pile2 = numCrates - pile1;
   if (numCrates <= loadSize)
   {
      return 1;
   }
   else if (pile2 <= loadSize)
   {
      return 2;
   }
   else if (pile1 <= loadSize)
   {
      return NumTrucks(pile2, loadSize) + 1;
   }
   return NumTrucks(pile1, loadSize) + NumTrucks(pile2, loadSize);
}


I really am bad at this... this second one took me quite a bit of time before I made it work.

@Chili
Thanks chili :) I guess I'm pretty stubborn/persistent or whatever which might be good.
13 is pretty good :D I managed to get to 18 ones before my brain exploded

@Zedtho
I'm not sure what you mean Zed.
I divide by 6 since I want to find out the odds. The value returned will be less than 1 (0.0154) 1.54% so I can't use integers.
The function is dumb and just for practice so it's only supposed to be called with 6 as parameter (one for each side of a dice)
the reason 0 returns 1 is that when I reach number 1 on the dice, I want to return 1 / 6
The function call in that return statement will now have 0 as argument so it will return 1 which means 1 will return 1 * 1/6 which is the same thing as 1/6.

I could however change it like this
if (n <= 1.0f)
{
return 1.0f / 6;
}

which would give the same result.

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 19th, 2017, 12:35 am 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Want to try and make a xonix clone. But can't really figure out how to go about it...
Any tips? Should I have all the tools needed for this at this point?

Image

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 19th, 2017, 3:25 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
Should be doable with the stuff shown so far in the tutorials. I would represent territory as basically a surface (array of pixels). Then drawing is just copying the pixels to the screen surface (sprite blt operation).

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: June 19th, 2017, 12:17 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
chili wrote:
Should be doable with the stuff shown so far in the tutorials. I would represent territory as basically a surface (array of pixels). Then drawing is just copying the pixels to the screen surface (sprite blt operation).


Not 100% how it'll work with the "collapse" after you cut off an area.
But wanna give it a try. However I'm having issues with keyboard. Event is private, so it's inaccessible. Changed it to public for now, not sure if this is fine

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 19th, 2017, 1:27 pm 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
Wait, how is event private?? That can't be right, unless I fucked something over in the last patch. :P Can you give me a link or show me the code where it is private?

Edit:

Nevermind, I just checked the repo. Fuck me, how did that happen :P

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: June 19th, 2017, 1:34 pm 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
Fixed now, thanks for the head up bro.

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: June 19th, 2017, 2:10 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Haha great :D I thought I was going insane. Even opened up space balls to check how I managed to pull it off for that project and noticed event was public in there.

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 19th, 2017, 10:26 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Study update:

Watched this video and tried to create xonix based on it.
https://www.youtube.com/watch?v=_5W5sYjDBnA

Here's the result
https://github.com/Yumtard/xonix

I did not enjoy his coding. I don't know if it's just me but a lot of it seemed so unclear. And I would've liked more classes.
Not sure how much I actually learned trying to just follow him, I think at least a little since I had to analyze the code at some points to try and understand how it worked. Like the recursive drop function.

Might give it a try to make the code "nicer" maybe adding classes somehow and change from ints to enums to represent different tiles etc.
And also try and make it more of a game (win conditions and adding a new enemy each level)

I also signed up for a site which has different stuff like algorithm challenges. Solved a few of them but didn't like how it was determined wether I was correct or not, it was too easy to pass.
For example they wanted me to make a function that takes an array of 5 ints and then couts the biggest possible sum when adding for of those numbers and the smallest possible sum when adding 4 of those numbers.
the sample input said 1,2,3,4,5
sample output said: 14, 10

So just for lolz I wrote nothing but: cout << 14 << " " << 10;
this matched the expected output and I cleared the challenge lol

If anyone knows any good sites with code challenges for practice let me know

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 20th, 2017, 4:03 am 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Phew, restructuring this code is proving pretty difficult :p

Feels a bit nicer now though, at least in my eyes.
Let me know if it seems ok.
Branch "shipitholaballa"
https://github.com/Yumtard/xonix

Will finish the game tomorrow... or later today or whatever #uptil6am

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 20th, 2017, 4:52 am 
User avatar

Joined: February 14th, 2017, 7:32 pm
Posts: 170
Typing it in to google gave me this
http://www.cprogramming.com/challenge.html
https://www.quora.com/What-is-the-best- ... +-problems


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 627 posts ]  Go to page Previous  1 ... 38, 39, 40, 41, 42, 43, 44 ... 63  Next

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron