fred rosenberger

lowercase baba
+ Follow
since Oct 02, 2003
fred likes ...
Chrome Java Linux
Forum Moderator
fred rosenberger currently moderates these forums:
St. Louis
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by fred rosenberger

i tend to think of variable names as label stickers you can put on a box.  if the label has not been attached to a box, then it's null...there is nothing to look in.

If the label is on the box, then it is not null, but the box can still be empty.

So a String reference can be null...which means no String has been created, or the String object may have been created, bu the string itself has 0-length.
6 hours ago
This actually gets kind of're stepping through the array, looking at each element, but at the same time, you're re-arranging the elements...i've not thought through this too deep, but here are some of my thoughts...

1) you need a way to step through each element in a given array.
2) you need to determine if the "current element" is one that needs to move
3) you need a way to move an element from some arbitrary position to the first position in the array, and then "slide" all the other down, up to the position of the original element.

notice how each of these are completely independent of all the other items.  It doesn't matter how i find the position of an element...i just need to pass that in to whatever does #3.  So each of these to me imply a separate method. 

So, if i were doing this, I'd start with #3.  Write a method that takes and array, and a position in the array, that does all this moving around.  Once you know that method works (which you'd know by writing some temp code that sends it an array and a position), then you can write one of the other methods.
1 day ago
the problem isn't incredibly clear...are you supposed to move each integer as you find it to the front, which would reverse them, or are you supposed to find all of them, and move them en mass?  in other words...if you start with this:

{ 1, 3, 3, 4, 5, 8, 0 }

when you find 4, do you move it, giving this:

{ 4, 1, 3, 3, 5, 8, 0 }

then you find 8, so you do this:

{ 8, 4 1, 3, 3, 5, 0 }  and then 0, so you get this:

{ 0, 8, 4 1, 3, 3, 5 }


Should you find 4, 8, and 0, and move them all, giving you this:

( 4, 8, 0, 1, 3, 3, 5}

I would approach these two in different ways. 
1 day ago
I would say yes, you have.  The other party did not consent to the transaction.  i'll check with my legal expert/lawyer - my wife - and see what she says.
1 week ago

Campbell Ritchie wrote:But what happens if they are offered cash and refuse it?

I think for any transaction to take place, both parties must agree that what is being exchanged has equal value - or each side must think they are getting the better end of the deal.

So if i offer you cash and you say no, then either I make another offer, or the transaction doesn't take place.
1 week ago
The U.S. Dept. of Treasury says:
"There is, however, no Federal statute mandating that a private business, a person or an organization must accept currency or coins as for payment for goods and/or services. Private businesses are free to develop their own policies on whether or not to accept cash unless there is a State law which says otherwise."

The Federal Reserve says:
"There is, however, no Federal statute mandating that a private business, a person, or an organization must accept currency or coins as payment for goods or services. "

So businesses DO have the right to refuse cash. 
1 week ago
in a string literal like that, the backslash is how you escape a special character.  For example, "\n" is a newline, "\t" is a tab. 

So how do you print a backslash?  You use the escape character - a backslash.  "\\" will print a single backslash.
1 week ago
Does it have to be a single regex?  I've often found breaking it into multiple pieces works better - easier to code, easier to debug, and easier to update in 3 years when the requirements change.

So, you can first get rid of any string that does not contain "nova scotia".
then, get rid of anything that starts with "^bank"
Then, get rid of anything that ends with "bank$"
3 weeks ago
also, you could start with a simpler problem...for example, given two string, can you determine if the first contains the second at all?
3 weeks ago
well...what happened when you compiled and ran it?  That should give you a hint if anything is wrong or not...
3 weeks ago
if the interviewer had said "it's taking too long to get product from our warehouse to our stores - what would you do to improve it?" would you start by saying "i'd buy faster trucks"?

probably not.

The first thing you need to do is figure out WHERE THE BOTTLENECK is.  Maybe it takes them a week to load a truck because they only have one guy packing it up.  Maybe they have only hired Sherpas to physically carry each item on foot from Cleveland to Tulsa, and it just takes a long time to walk that far.

Maybe the shipping company they hired doesn't actually operate in Tulsa, so the packages get routed to Tampa, then Tacoma, then Denver, and THEN Tulsa.

My point is...unless you know WHERE the slowness is, trying to speed things up is pointless.  there are too many places where the problem COULD be that you're not gonna find by just guessing.
3 weeks ago
I would say start by talking to your aunt on what exactly the program should do. programming is really 90% thinking, and only 10% typing.  you should have a firm plan of what you are trying to achieve before you write a single line of code.

start small.  Maybe just start with a pump inventory system.  Maybe something to keep track of the make, model, and serial number. Maybe a purchase date and price.  Be able to add and remove pumps (hmm...starting to sound like you need a database). 

Once you have something like that working, maybe add in the ability to keep track of what is available, and what has been rented.

Next, maybe add in a customer database.  And then you can link the customer to a pump they have rented...

Write small, simple pieces you can test the HECK out of.  Compile and retest about 20 times more often than you think you need to.  If I ever write more than 3 lines of code without compiling and testing, I feel ashamed.

Ask questions. 

Go slow.

Favor code that is easy to understand over code that you think will run fast.  You will spend more time debugging than you will ever save by using micro-optimizations.

There are probably a million more things, but that's a start for you to chew on.
4 weeks ago

Carey Brown wrote:

Gnanagowthaman sankar wrote:maxMirror([1, 2, 1, 4]) → 3  How 3 elements here 121 or 214 or 412 is not in sequence but how 3 elements

1, 2, 1 backwards is 1, 2, 1 and the array has that. It just happens to be the same sub-array.

what am i missing then?
1,2,1,4 backwards is 4,1,2,1, so why not 4?
1 month ago
Where is this question from?  It looks wrong to me. I can't see how you would get "3" from the second array. I can see "2" as a valid answer.

Having said that, the best way to approach this is to break the problem down into discrete parts, and focus on each of those. For example, off the top of my head, I can see three things I'd work towards coding as separate methods:

1) Given an array, find the longest group of contiguous elements in an array.
2) Given an array, reverse it,
2) Given two arrays, A and B, check to see if the elements of array B are in Array A.

Even as typed those out, I saw a few problems with just having those three would actually NOT find the longest mirror section...but it is certainly a start.  that's exactly WHY I write out such steps...As i do it, it forces me to think about the problem an reconsider my assumptions.  See if you can figure out why the above won't work, and what changes might need to be made. Don't start coding until you've worked through all this logic.
1 month ago

S Fox wrote:He will get an NPE if he does what I think you are suggesting fred, then he might be able to read the stack trace to see exactly where his algorithm is broken. Right now he has the worst kind of error, a logic error.

All i am suggesting is that the OP think through every decision.  I gave one example of a decision made that was most likely NOT thought through - it's pretty common to initialize all variables to 0 or "" or whatever. There are probably other, similar not-thought-through-decisions made with other variables in the code.
1 month ago