Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!

since Feb 18, 2005

Cows and Likes

Cows

Total received

16

In last 30 days

0

Total given

0

Likes

Total received

75

Received in last 30 days

2

Total given

51

Given in last 30 days

0

Forums and Threads

Scavenger Hunt

Rancher Scavenger Hunt

Ranch Hand Scavenger Hunt

Greenhorn Scavenger Hunt

Nick Castillo wrote:Hey,

I am trying to print 300 random words, 8 characters long using a while statement but I dont think I currently have the knowledge to do it (I have an array of the alphabet so that may be useful). I would really appreciate any sort of help

thanks,

A couple things:

1. When you say "word" are you talking about any random string of eight letters, or do you need the results to be actual English (or other language) words?

2. This forum isn't a code shop. The folks here aren't just going to hand you completed code. However, we'd be more than happy to help you get over any hurdles you're facing in your own attempts at a solution. What have you got so far? What aspects are you struggling with?

3 weeks ago

D.J. Quavern wrote:Hello Ranchers,

I am doing a community project to teach programming. The club is for mums and their daughters, or any girl and woman, at beginner lebel.

I found Junilu's refactoring of my code quite inspiring, and realised I might teach fundamental concepts really wrongly!

So I wondered if some of you could share programmimg exercices that are at the same time really fun, engaging and done the right way, to ensure my pupils get solid basis?

We are at hello world and string concaténation right now so there is no urgency with TDD.

First off... my hat's off to you for taking on this project.

TDD or other development process isn't really an advanced concept to be taught only once people have reached some high level. Rather, it's a foundation for how to do the nuts and bolts of software development. Of course, writing tests requires you to be able to write real code with some level of expertise. That's fine - just make the test code part of what you need to program. For instance, if the first project is a Fibonacci number generator, don't teach just how to generate the numbers. Instead, show how to do the whole TDD process to write a well-tested program to generate Fibonacci numbers. ...if TDD is indeed the process you want to use.

Similarly, such ideas as using variable names that are recognizable from the problem domain (such as "rank" and "file" or at the very least "row" and "column" instead of "i" and "j") or keeping methods down to a reasonable size should be taught and indeed emphasized from the beginning - not retrofitted in later.

That's my take on it. Any other thoughts?

EDIT: That's what I get for taking so long to reply - someone else gets in there first. At least some of our thoughts overlap.

3 weeks ago

Liutauras Vilda wrote:To my understanding I got them right.

My contribution to a great thread:

Ranks are rows.

Files are columns.

Think of a "rank" as a military rank. All the individuals of a given rank are at the same height from the bottom.

Think of a "file" people walking in "single file". They are not side-by-side. I picture them in a line from near me to farther away from me, much like a column on a sheet of paper on my desk.

3 weeks ago

Mike Simmons wrote:

Tim Holloway wrote:Answering the original question. What a concept!

This may have been lost in the noise...

Mike Simmons wrote:For the original question, I can't imagine frequently needing to modify a polynomial like that. I'd probably just go with a double[] to represent a polynomial in most cases. The LinkedHashMap is good if the polynomial is sparsely filled though - i.e. relatively few few non-zero coefficients.

Ahh yes... I scanned the conversation but most of it was, I hate to admit, tl;dr. A double[] was indeed what I was getting at.

3 weeks ago

Revisiting the original question...

I agree with what I*think* Carey was implying - the answer depends on a few factors:

- Is there an absolute maximum and minimum exponent for the terms?

- What is the mix of operations you'll be performing? Will you be doing many (or even*any*) insertions, deletions or updates once a polynomial is created?

- What do you define as "better"? Easier to program? Faster to execute a thousand operations? Uses less memory?

For instance, if you're writing a class for a non-honors level high school class, the maximum exponent may be 6 and the minimum 0, at least for 95% of the cases. It may also be that once a polynomial is calculated (maybe by the multiplication method of the class), it is never modified. i.e. Instances of the class are value objects. In such a case, I would guess that using plain old arrays would be easier to program and faster to execute than if any of the more complex data structures were used.

Ana Yo wrote: Just a curious question: is the linked list representation of a polynomial better than the array based representation?

I agree with what I

- Is there an absolute maximum and minimum exponent for the terms?

- What is the mix of operations you'll be performing? Will you be doing many (or even

- What do you define as "better"? Easier to program? Faster to execute a thousand operations? Uses less memory?

For instance, if you're writing a class for a non-honors level high school class, the maximum exponent may be 6 and the minimum 0, at least for 95% of the cases. It may also be that once a polynomial is calculated (maybe by the multiplication method of the class), it is never modified. i.e. Instances of the class are value objects. In such a case, I would guess that using plain old arrays would be easier to program and faster to execute than if any of the more complex data structures were used.

3 weeks ago

fred rosenberger wrote:i'm probably going to ask the math teacher, too. I'm sure they hate parents like me.

It probably is a 100% contrived example meant to show the difference between (sin theta)^2 and sin (theta^2)...but itbugsme when I can't see why stuff doesn't work.

Fred, any update?

1 month ago

Campbell Ritchie wrote:Is she really supposed to evaluate

sinθ²? Notsin²θ? Sincesin(π ÷ 3) is √3 ÷ 2, it is really easy to work out its square: ¾.

Neither degrees nor radians have dimensions; does each even have a square at all?

What's the operator precedence? Does

1 month ago

I don't know if it's better form to reply to my own post with additional information or to edit the previous post, so...

More explicitly, "You bet," means, "I am so committed to doing exactly what you requested that you can make a bet with someone else that I will do it and you'll have a very good chance of winning the bet."

I don't feel that "You bet" makes a statement one way or the other about whether he had pre-existing plans. However, if he did have plans, he will feel free to follow through with them as requested.

Ryan McGuire wrote:In general, "You bet," means, "I will do exactly as you requested."

More explicitly, "You bet," means, "I am so committed to doing exactly what you requested that you can make a bet with someone else that I will do it and you'll have a very good chance of winning the bet."

I don't feel that "You bet" makes a statement one way or the other about whether he had pre-existing plans. However, if he did have plans, he will feel free to follow through with them as requested.

1 month ago

Linwood Hayes wrote:Last week, we planned a picnic with a few friends and families. I offered a ride/carpool to a friend saying "We can drive and if you want to go with us, let me know." Then I realized he was little hesitating, so I added "If you have other plan, feel free to go ahead with your plan..". He said "You bet." Can somebody tell me what does "you bet" mean here ? Does it mean he did have other plans or what ? You may ask why I didn't ask himself what it meant that time. Be honest, I just didn't want to make myself look dumb by letting people feel I couldn't grasp English..

In general, "You bet," means, "I will do exactly as you requested."

In this case, your friend is saying, "I will indeed feel free to go ahead with any plans that are already in place and not feel obligated to ride with you."

1 month ago

Thank you! What a pleasant surprise!

I've been in a few conversations with a couple of the other new Ranchers and I have to say I'm honored to be included in their company.

I've been in a few conversations with a couple of the other new Ranchers and I have to say I'm honored to be included in their company.

1 month ago

Carey Brown wrote:You are comparing the references to "ab" and "ab " (note the extra space).

The '+' operator has a higher precedence than the '==' operator.

Exactly. Line 9 is equivalent to...

...which, as Carey pointed out, is comparing "ab" to "ab<space>"

You probably want to change that to...

Similarly, line 11 is equivalent to...

...in which the == is comparing "true ab" to "ab".

2 months ago

A few things:

1. As Liutauras mentioned before, indentation!

2. Also on the subject of code formatting. Always use braces. For instance, I'd rewrite lines 21 and 22 as...

Yes, it's perfectly valid to leave the braces out. If you scoff at my suggestion, continue to omit braces in such cases and ever admit to getting bitten by something like...

... I will just point and laugh. Ok, maybe that's a bit harsh. I'll probably have some sympathy for you, but you see my point.

3. You might consider sorting the array at the beginning of binarySearchRecursive() if a==0 and z==arr.length-1.

[EDIT: In retrospect number 3 is goofy. Sorting an unsorted array has O(N log N) complexity in general, which is horrible compared to the expected O(log N) time complexity of a binary search. Even just*verifying *that the array is sorted is O(N) and requires you to look at every array element, also ruining the advantage of a binary search over a linear one. Forget I suggested it.]

1. As Liutauras mentioned before, indentation!

2. Also on the subject of code formatting. Always use braces. For instance, I'd rewrite lines 21 and 22 as...

Yes, it's perfectly valid to leave the braces out. If you scoff at my suggestion, continue to omit braces in such cases and ever admit to getting bitten by something like...

... I will just point and laugh. Ok, maybe that's a bit harsh. I'll probably have some sympathy for you, but you see my point.

3. You might consider sorting the array at the beginning of binarySearchRecursive() if a==0 and z==arr.length-1.

[EDIT: In retrospect number 3 is goofy. Sorting an unsorted array has O(N log N) complexity in general, which is horrible compared to the expected O(log N) time complexity of a binary search. Even just

2 months ago

Disclaimer: I know approximately zero Python.

That being said...

If node comes back from find_cheapest_node() as None, won't using None as the index/key into graph[] cause an error? Should that test be...

EDIT:

Now that I reread your post, I see you agree with me:

If the while loop should stop when node is None, then check node, not graph[node].

That being said...

If node comes back from find_cheapest_node() as None, won't using None as the index/key into graph[] cause an error? Should that test be...

EDIT:

Now that I reread your post, I see you agree with me:

Obviously the while loop should stop when the returned node is none?

If the while loop should stop when node is None, then check node, not graph[node].

2 months ago

Piet Souris wrote:hi DJ,

long time no see! You seem to be very busy, but that is a good thing.

I had to read that assignment twice, but I think I got it. You are given N cities (vertices) and M lines of input indicating where a pilot can fly to and from (edges). So, it is an undirected Graph with N vertices and M edges. And the question is what the shortest path is between any two cities. Correct me if I'm wrong. Now, first thing what comes to mind is Dijkstra's algorithm: Dijkstra.

So, have a read and see if you agree with me!

That's not how I read it. Given N vertices and M edges, I think it's asking for the minimum size of the subset of edges that connect all N verices (i.e. a spanning tree). That seems strange to me, since the minimum number of edges in a spanning tree of a graph with N vertices is always N-1. ...assuming the graph is indeed connected, which is guaranteed by the problem statement.

Let's look at the first test case given:

A fully connected triangle. The spy has to trust the pilot that travels between cities 1 and 2. Then he wants to get from city 1 to city 3. He can't do that flying with the one pilot he trusts so far, so he has to trust a second one, for a running total of 2 so far. Next he wants to fly from city 2 to city 3. At first it looks like he'll have to trust a third pilot to make that flight. But no... he could fly from 2 to 1 and then from 1 to 3 while flying only with pilots he already trusts. So the minimum number of pilots our spy has to trust to get from any city to any city is 2 - final answer.

I think the second example would have been more fun if it was more fully connected. i.e. instead of having the minimum of four required to connect all N=5 vertices, it should have had, say, seven or eight edges. That would have made it "juicier". Of course the answer

3 months ago

In the case of arguments 2, 2 and 4. Should you get both 2+2=4 and 2*2=4 or just the addition equation?

4 months ago