D.J. Quavern

Ranch Hand
+ Follow
since Feb 19, 2019
D.J. likes ...
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
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt Green check

Recent posts by D.J. Quavern

Hello everyone!
After this discussion (graph theory post) I got Grokking algorithms, and trying to implement some classics. Starting with Dijkstra.
I attach a drawing of the graph, and the python code. Like you all know and I am trying to figure out, the code is supposed to go through all the nodes and find a way to go further "cheaper".

I get the below error:

Why do I get this error? Obviously the while loop should stop when the returned node is none?

If you wonder why everything is called "1", its because there is a second graph for testing purposes but I have an error with the first one .

3 hours ago
I'm nowhere near designing such complicated systems yet, so you'll have to read my baby steps  
2 days ago
Oups, I managed to miss your last post Stephan!
Sorry about that.

I will come back to it later, I just got the book grokking algorithms, can't recommend it warmly enough . Implemented a BFS search this morning and will try myself at implementing Dijkstra tomorrow morning. So I will be back!
2 days ago
Sorry that discussion went completely out of hand!

But now I have received Mannings bok Grokking alogorithms, it reads like a bedside story. I'll hopefully come back with more relevant questions in the future!

But yeah, since we are in MD: more alien made movies would help us to appreciate their culture and point of view on eventual earth invasion. Probably they are not even interested.
6 days ago
Hello Dear Medems and Siiiirs,

Can you help me out with a little bit of your shiny knowledge?

I am supposed to extract elements from a website, so I wrote, in an API.js file, the below function:

In an index.js file, I am trying to process the information I get from the json object:

At this stage I tried several ways to parse the array object.
In the console I get the array which I am supposed to ransom, but I am unable to make it work unfortunately!

Do you know what I am doing wrong?
Thank you!

I think we have a representation problem with alien. The only movies we get to see are made by scarred men that believe that everything coming outside of their frontiers is a threat. I request more aliens movies before I finalize my opinion!

(and about Dijkstra... I am almost with you on that one. Just need to understand how it "stores" the possible solutions!)
1 week ago
Thank you for all the answers!

I will not risk the traveling salesman right now, the difficulty level is way to high for where I am right now! I saw the dining philosophers in class, as an example!

A key point is that with Dijkstra, at step n you aren't committing to any one solution yet - you are handling *all* possible solutions, of length n.  Or of a particular maximum cost.  Well, not really *all* of the solutions, because you are weeding out the ones that waste time getting to the edge of your graph.  But you are keeping a set of all the best solutions that would reach the current edge of the search area.  Without committing to any one point on the edge, yet.  

What do you mean? Do the algorithm keep track of all the paths in an array and propose the cheapest one at the end (minus those that go in the walls)?
1 week ago
Thank you everyone, that was exactly what I was talking about: just by looking at the problem, you could determine it was a minimal spanning graph and see that the solution was N-1 directly. I had no idea what I was looking at, except a badly formulated Cold War movie. I am the proud winner of classical problems with Python and I hope it will help me at least to have an idea of the underlying theoretical world under programming problems. I had a look at the minimal spanning tree: so this is the one we have, but how do you deal with them when there are no weights on the branches? I also looked at Dijkstra algorithm: how can it find the most optimal route when it can't see the path n+2? I mean what if it choses the cheapest weight (2), but the next-one is extra salty (45)? Maybe it's not the point and it's a very stupid question though.

Yes! I am on holidays : I just have a web-development course -my questions also end up at the Ranch...-, but apart that, I am free. So I hang here and enjoy the company of nice people that give me golden advice and help     !

@Tim: Uh, NP-hard? Wiki has a funny definition : "the defining property of a class of problems that are, informally, "at least as hard as the hardest problems in NP"
I saw there was atraveling salesman, it is extra-hard.

1 week ago
Hello Ranchers!

I just did a problem that I apparently overestimated : Flying safely.

When I read the description, I figured it was some graph theory (albeit basic), so I draw numerous graphs with all kind of links between cities. I drafted a solution in which I checked whether a path had already been provided, and if so, included it in path collection. I put an edge case in case I had as many cities in pilots (as one is not needed and should be unemployed, poor soul).

But that solution did not went home. Instead, I just wrote that:

So my question(s):
What is the theory behind how many links you need between interconnected points?  
What if they have asked about the shortest route?

If somebody could throw some piece of advice or facts I should be aware of, I would be thankful. After all, if one can teach a dog polymorphism...
1 week ago
Thank you very much Ron.

I have still no clue why stuff work or don't, but it's really nice to get it rolling!
Dear Ron,
Thank you for your reply!

I did have error 304 (the page is not loading) for a while, but then resolved (itself, mostly! I am using live-server and it appears I have to save twice sometimes....). The javascript page appears to be loading now.

I tried to import in html, and export the function from the js file with :

but I have now:
exercise-5.js:33 Uncaught SyntaxError: Unexpected token export

(I also added the change you suggested:
Thank you so much! My second cow Yooohooooo!
1 week ago

Class assignment again:

I have an html page with different test-functions. One of those is to call a javascript function from a button.
The javascript file is in an js-folder, which is in an asset folder.
I get the error:
(index):55 Uncaught ReferenceError: fillForm is not defined
   at HTMLButtonElement.onclick ((index):55)

when I am trying to fill the oneInput form.
Does anyone knows why and care to explain?

That's the main HTML:

That's the javascript located in assets/js

Piet Souris wrote:hi DJ,

well, having such a lovin'and understanding family is a great boon!

Yeah one can say that !

Piet Souris wrote:
First of all: you might be forgiven to think that what we proposed, is like using a canon to shoot a mosquito. You could argue that, if there are no tails, the outcome will be decided by whether the heads are even or odd. If we have at leat one tail, we can expand that to any number of tails, and thus we can chop any number of heads accordingly. So, having one head and 51 ails, can you come up with a strategy that delivers you the number of moves as well?

Thank you, that actually clicked for me. I understood the point of doing modulo as long as I did not have the ideal solutions. Another problem is that I identified an ideal solution to break the loop as [0,1] instead of [0,2]. I got an infinite loop with test case [100,100].

Piet Souris wrote:
But let's try the OOP approach a little. Your drawing looks daunting and a bit chaotic, so I can imagine you lost track of where you were going. I said that a tree structure would be good for some difficulties, but I wanted you to try it anyway, because I think it is a great way to expand your experience.

How do you present the possible situations of heads and tails? There are several ways. A simple way would be to have a 2D array headtail[x][y], with value the moves to succes. A headtail[x][y] with value -1 or so, would indicate no solution. Or you could use an existing class that has two integer fields, likeJava's Point and Dimension, and use a dictionary<Point, Integer>, where the value indicates the number of moves to succes.

But what about a class that represents all this? For instance the class HeadTail (I use Javacode here, because my Python knowledge is a little bit very rusty):
Now, set up a Queue<HeadTail> (I always use a LinkedList for that, I'm not sure what python has for this) and a Set<HeadTail> setOfAllHeadTails (a HashSet/dictionary would be nice).
Put HeadTail(0, 0, 0) in the queue and in result, and there goes:
while the queue is not empty
   remove the head H
   get H's predecessors
   remove all predecessors already present in 'result'
   remove all predecessors that have more heads and/or tails than according to specs
   put the remaining predecessors back in the queue
It would be a bit tedious to create that Set for evey query that they will ask. As with HackerRank, can you edit the code so that you make this resultset static, i.e. so that you only need to create it once?

Last but by no means leasT;
see the 'determineSuccessors()' method in the HeadTail class. It says rhat when the number of Heads > 1 a successor would be HeadTail(head - 2, ...). Can you think of a situation where that is plain wrong?

There was a few technics that I was not aware of, so I could not implement the parts you left blank . I implemented something similar, and kept the "steps" principle, as it really clicked for me!

And how do I get you a cow Piet?  
1 week ago
Hello again!
My experiences have been very painful so far.
Can you please help me a bit more? I can't figure out how do I get to the right "optimal cases". I am really confused and my family is ignoring my grumbling ("three heads...one tail... fifty one tail... five heads...")
1 week ago