Jump to content
Sign in to follow this  
Pyro Sauce

Codingbat Java logic 2 - makeBricks

Recommended Posts

Can someone please explain to me why this is wrong?
[CODE]public boolean makeBricks(int small, int big, int goal) {
int inch = big*5;
if(goal >= inch) return(goal-inch <= small);
else return(small >= goal || (goal-small)%5 == 0);
}[/CODE]
the problem can be found at [url]http://codingbat.com/prob/p183562[/url]

Share this post


Link to post
Share on other sites
i have a feeling you're just reading the question wrong and it's pure coincidence that it passes all of the visible tests.

aussi, my go
[code]public boolean makeBricks(int small, int big, int goal) {
if (small + (big * 5) >= goal)
return goal % 5 <= small;
return false;
}[/code]

Share this post


Link to post
Share on other sites
[code]

public boolean makeBricks(int small, int big, int goal) {
return small + (big * 5) < goal ? false : (goal % 5) <= small;
}

[/code]

Would be sufficient. First, you need to check for is if you have enough length using all of the bricks. If that's true, then you need to check if you have enough small bricks left after using enough big ones.

Once you get through a good chunk of the codingbat problems, I recommend checking out project Euler. It's an even better programming/math problem site that allows you to use whatever language or tools you wish. Edited by Trey

Share this post


Link to post
Share on other sites
[quote name='Trey'][code]

public boolean makeBricks(int small, int big, int goal) {
return small + (big * 5) < goal ? false : (goal % 5) <= small;
}

[/code]

Would be sufficient. First, you need to check for is if you have enough length using all of the bricks. If that's true, then you need to check if you have enough small bricks left after using enough big ones.

Once you get through a good chunk of the codingbat problems, I recommend checking out project Euler. It's an even better programming/math problem site that allows you to use whatever language or tools you wish.[/QUOTE]

Trey, first of all, your my freakin' hero :P
and second, I'm curious... how did you come to know all that you do about programming? I've taken a couple classes so far but I still know very little about computer science/ programming over all, and every time I try to learn from wikipedia or something I find that I just confuse myself. I'm probably just getting too far ahead of myself but I really want to know more and there's no higher classes I can take on this until I go off to college.

Share this post


Link to post
Share on other sites
[quote name='Pyro Sauce']Trey, first of all, your my freakin' hero :P
and second, I'm curious... how did you come to know all that you do about programming? I've taken a couple classes so far but I still know very little about computer science/ programming over all, and every time I try to learn from wikipedia or something I find that I just confuse myself. I'm probably just getting too far ahead of myself but I really want to know more and there's no higher classes I can take on this until I go off to college.[/QUOTE]

I'm a huge nerd when it comes to math and computer science, so I've been heavy into it for a while now. Just keep learning. Master a language or topic, and then move on to the next. If you're ever comfortable with how much you know, then you're doing something wrong. Anything you could ever want to know is available online somewhere.

Something that will really further your understanding of algorithms and such would be learning to program in C. It forces you to think about things that Java and other languages with lots of shiny features and a huge API would hide from you or do for you. Learning C will get you involved in understanding the basics of memory layout, pointers and their awesome power, writing data structures and algorithms that are usually provided for you in higher-level languages, etc.

Problem solving wont come with learning programming languages btw. Developing problem solving and critical thinking abilities is highly important. Sites like codingbat and project Euler are great ways of doing so. You may also want to get involved in any local programming competitions. I did a few at colleges around me and I participated in an international one twice; it was an awesome experience.

Good luck! If you need anything let me know.

Share this post


Link to post
Share on other sites
learning C is a great idea Edited by _s1gma

Share this post


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
Sign in to follow this  

×