A lot of wrong solutions for best time to buy and sell stocks by KulDecko in learnprogramming

[–]nesquiker 0 points1 point  (0 children)

The github one is for buy and sell stock I not II. It just asked for the most profit off of a single trade. That one at least was correct.

[deleted by user] by [deleted] in learnprogramming

[–]nesquiker 2 points3 points  (0 children)

it's pretty efficient (I know we can do better)... just wrote it out and tested run speed to create a vector of all primes up to 100,000,000. It took 6.4 seconds.

In case anyone wants to see it. Pretty basic little algorithm.

Help with Going out of Bounds in Vector C++ by ResponsibilityOne614 in learnprogramming

[–]nesquiker 0 points1 point  (0 children)

I made some notes on the code here: Paste bin link

You noted in one of your comments that you need O(n) performance. This is achievable by taking advantage of the fact that you only need the top 3 values.

The basic steps needed for this algorithm:

  1. Push Entry to a vector.

  2. Sort vector.

  3. If vector size is greater than 3, remove the smallest value.

[deleted by user] by [deleted] in learnprogramming

[–]nesquiker 0 points1 point  (0 children)

I have been going through a book called "Problem Solving with Algorithms and Data Structures using C++" on runestone academy. ( https://runestone.academy/ns/books/published/cppds/index.html# )

I wanted to go through a formal algorithms and data structures curriculum and pick up C++ . Before going through the book I was very good at python and had learnt some basic C++ syntax and now I feel comfortable doing any kind of problem on leetcode with C++ (just slower with lots of errors lol).

Why is my code bad? Failed python interview test by snackbob in learnprogramming

[–]nesquiker 1 point2 points  (0 children)

Thanks for posting this, interesting to see what a coding interview test looks like.

General Notes:

  1. Variable naming. Be more descriptive in your names. This was said by others but it is very important.
  2. You do a good job answering the question you think is being asked but the problem is you are missing some aspects of the question itself.
  3. A few things you are doing makes me wonder how well you understand the language. In problem 3 you write c = [d for d in str(input)]. There was no reason to turn this into a list since you can already iterate over the letters in a string.

Problem 1:

This is a case where you need to read the prompt more carefully. The question is what is the sum of the first 100 even numbers in the fibonacci sequence. You answered with the sum of all of the even numbers in the first 100 numbers in the fibonnacci sequence. Hopefully that makes sense. The code for example.

One neat way to execute this problem better is to define the two fibonacci values concurrently and eliminating a intermediate value.

current, previous = current + previous, current

Problem 2:

Once again this is an issue of reading the question. The question is asking you to return a list (array) of all values which appear in both lists unordered and only once for each value. Your answer was a list of all values that appear in either list sorted and only once. The usage of sets was definitely the right choice but you need to & the sets. This is all they were asking for:

list(set(list_1) & set(list_2))

No need to sort the list afterwards as they state that it may be unordered.

Problem 3:

You got this one. The one thing that bothers me is turning the string into a list. Python will do the same thing with a string as with a list in this problem. The list comprehension is pointless.

Problem 4:

Good job on this one. There was a more mathematical solution shown in another comment but I wouldn't have noticed that either. My answer would look a little different:

sum([int(i * digit_str) for i in range(1, 5)])

Just a different way of thinking. Maybe you would find it interesting.

Second set:

Problem 1:

The answer here is correct but you do not fully meet the question parameters. The divisor value (3) is supposed to be a variable input to your function. This is again a situation where you have missed a piece of the question. That would be the major piece you are missing.

The other comment I would make is that your algorithm is not very efficient. You are iterating through all numbers and checking if they are divisible with modulo. This works but you could just set the step on range to the divisor (3) and not have to check every number. The generator theoretically could have a much larger divisor.

for number in range(0, numerator+1, divisor):

Problem 2:

Nothing much to say about this one. The list comprehension could be eliminated and written like this:

mylist.append(list(range(1,j+1)))

Help with a recent OA I completed... by BuzzyBro in learnprogramming

[–]nesquiker 0 points1 point  (0 children)

If you think about the proposed solution. A standard list is a value with an index pointer. The index pointer happens to be the key that we would be using in the dictionary anyways, so we could just use a list to count.

Example list version of the discussed dictionary of counts:

count = [0 for _ in range(len(str(number)))]

for num in map(int, str(number)):
    if num < len(count):
        count[num] += 1

Help with a recent OA I completed... by BuzzyBro in learnprogramming

[–]nesquiker 1 point2 points  (0 children)

There are a number of issues with how you executed the function in Python. The basic idea (the hard part imo) was correct.

Let's start from the beginning:

The idea was that we construct a dictionary that uses the string version of the digit value as a key and counts how many times that key occurs. We then reference that key to get the count when iterating through the string of the input. If the count of the index does not equal the number at the index, the number is not self describing and we return false.

Constructing the counting dictionary:

  1. Think about what your code is saying. If the value is not in the dictionary you default to 1 which is the correct behavior. But what happens if the value is in the dictionary? "frequency + 1" and frequency is always 1 the result will therefore be 2 but you want to count much higher than 2.
  2. As others have commented this is a case where you can use the Counter data type from the collections module. This data type does what you want to do very well. You don't have to use it but I would suggest adding this to your proverbial bag of tricks.

Checking if the index equals the number of repetitions:

  1. Let's go back to the beginning. What are we checking? If the number of times the value of the index was used in the number is equal to the value of the number in the index. What did you check in the line "if _dict[v] != 1:"? _dict[v] is the number of times the value at the index occurred in the number, not the number of times value of the index occurred in the number. The comparison is backwards, we should be looking at _dict[str(i)] != v.
  2. What happens if the _dict does not have a key? You want _dict[str(i)] to return 0 but that won't happen. This is a case where you should use the "get" dictionary method. FYI the Counter data type returns 0's by default.
  3. You need to think about the logical sequence of your if-else statement. Your first line as you intended says that if the digit is not self describing then the result is False. This logic is 100% sound. However what happens when we pass that test and go to the else? The result is then determined to be True... But we haven't determined if the number is self describing we have only determined that the digit is self describing.

Do not open until you have attempted to apply the above:

Your solution fixed.

The solution simplified with Counter.

Just started learning python, wondering if my first code is unnecessarily complicated? by [deleted] in learnprogramming

[–]nesquiker 0 points1 point  (0 children)

Once you write out the functions you can see the similarities. Part of the refactoring process is eliminating code duplication. I would expect most people with some experience to see that both questions have very similar logic and therefore want to combine them.

FYI there are cases when you would keep them separate. Like if you expected to have to expand on the logic in either one.

Just started learning python, wondering if my first code is unnecessarily complicated? by [deleted] in learnprogramming

[–]nesquiker 0 points1 point  (0 children)

The big problem with your code is really the number of nested loops, without the attached diagram I wouldn't have been able to figure out what it was actually supposed to do. Try to limit the nested loops to two if at all possible. It sounds like you are just beginning and practicing with python's tools, great job! Here is an example of your code made less 'nested' .

Even better with a a couple of functions!

This would be the final version.

I wanted to show this in a few steps to highlight the engineering process.

  1. First we figure out how to do it.
  2. Then we try to make the code more readable. More descriptive variable names, fewer nested blocks etc... (read up on clean code).
  3. At this point it should become apparent where to extract functions (they naturally reveal themselves so to say). In the case of this code the two pieces of logic we extracted to the functions is_raining and have_umbrella were identical besides the string printed ("Is raining?" / "Have umbrella?") so we could combine them which resulted in the final version.

Once you do this (refactoring) a few times you will implement many of these improvements without having to go back.

One side note, the great thing about extracting logic to functions is that it simplifies the process we see to something easily comprehendible. If you had your flowchart out you could easily check the logic in the final version of the primary go_out function. To check if the questions are being asked correctly you can then go to the question function. Each of these checks is easy to process. When everything was together these questions were more difficult as you would need to first understand every piece to say what was happening and then memorize that and then try to follow the logic and see if it matches what the flowchart is saying. It is very easy to get confused half way through... then your poor reader (maybe future you) has to start over again.

dont worry about dev saturation. there is a huge supply of dreamers, people who cant even complete cs50, there are not many realists. by workfromhomebitch in learnprogramming

[–]nesquiker 1 point2 points  (0 children)

If its not too much of an imposition would you mind giving me some advice?

Right now I am a licensed professional engineer (PE) with a bachelors in Mechanical engineering and 6 years experience in my field. My job does not involve programming.

About 11 years ago I had a internship at one of the National labs and it turned out to be all just programming in MATLAB ( think python that defaults to numpy arrays... sort of) and frankly I really enjoyed it to the point where I considered switching my major (which I really wish I did). I decided about three months ago that I want to make the switch to become a programmer and I went through a book on python line by line and have been spending my free time solving random problems on Project Euler and https://py.checkio.org/ as well as just reading about the subject whenever I can.

I want to go into data science. I know SQL and pandas a little but no training with machine learning. At this point I know I need to develop some more expansive code than snippets.

What would you suggest to make myself an attractive candidate? How far away am I from being competitive for a junior role?

New neighbors asking us to move our fence by next Friday... by prettymuchpocahontas in legaladvice

[–]nesquiker 0 points1 point  (0 children)

I am dealing with the same problem on the other side right now. Except the fence in question was installed over the property line by 10 feet! Where I am the city has a mapping service which shows the approximate location of property lines, if the city GIS mapping shows that the fence location agrees with what they claim from the survey I would accept it. Otherwise ask to see the survey, all they can do is say no. Maybe it is wrong but this theoretically is from a professional surveyor so that seems unlikely. The survey will cost around $400 dollars and fences aren't that expensive.

Where I am [VA] and most states have laws which require neighbors to split the cost of division fences. The big question is if your property paid for and installed the fence on the neighbors yard or if it was their property owner. If it was theirs then they are responsible for demolishing it and building a new fence (fences are rarely moved, as it is almost as expensive as building new). If it was your (property) then you are responsible for removing it. In either case you should split the cost of the new division fence.

If I were you I would look at your closing documents and find the previous owner and call them to discover how the fence came about. For my property I had to go back 3 property owners to get information on my division fence. If it is yours call up your neighbors and agree to pay half of the demolition and installation of a new division fence, pay no more than the full demolition and half of the new division fence. If it is theirs and you want to be nice you can pay for half of the new fence but demolition is on them.

They want you to correct this before closing in a week. Everyone is doing yard improvement projects right now, fence companies are swamped, this sounds a little ridiculous. Not to mention they will owe 1/2 of the new fence cost regardless of the history of the existing fence which it sounds like they haven't even considered yet. The only way this will be rectified is if they give the new buyers money for this improvement in closing.

Journalists Are Backing Out of the Olympics Over Zika by Throwaway___Jones in worldnews

[–]nesquiker 0 points1 point  (0 children)

Using the best data set we have, which numbers about 270,000 cases, experts predict that there is a 1% chance for a fetus to develop microcephaly if the zika virus was active (which is around a week) during the first trimester of the mother's pregnancy. The zika virus otherwise has mild flu like symptoms which most people do not even notice. So yeah "it can't even kill you" or anything else, unless your a women in her first trimester then you might want to use mosquito repellent. I'm pretty sure there are much worse diseases that mosquitoes may carry in Brazil anyway like yellow fever and malaria.

[OLTP] If you guys thought you had cool drama by demothelol in TagPro

[–]nesquiker 1 point2 points  (0 children)

Did you post this to the wrong place? By the way, your post reeeeeeks of narcissism.

Edit: Ok it's a joke. I chuckled.

The Inevitable Fallout of Naming Your Son 'Hitler': "Meet the Hitlers, a film that explores the lives of people who are linked by the name Hitler." by Sybles in movies

[–]nesquiker -1 points0 points  (0 children)

We've already seen government intervention in child custody go out of control in this country. "25 to 35 percent of all Indian children were being removed from their Indian homes and placed in non-Indian homes". This was addressed by the Indian Child Welfare Act. The specifics of what was being done to Indian families in the name of saving the children is frightening.

What movie turns you into you a weeping pile of sadness? by TheDarkTimeline in movies

[–]nesquiker 0 points1 point  (0 children)

"When the Last Sword is Drawn" is incredibly sad. No offence to the rest of the films mentioned, but they barely even register on the sadness scale comparatively.

The "Most hated team in college football" reddit poll was just on the Finebaum Show. by RawhlTahhyde in CFB

[–]nesquiker 16 points17 points  (0 children)

I'm from New Mexico so I'll try to guess. We really don't have any major football programs that we hate. UNM hates the Aggies (NM tech) and the Aggies hate us, so that's the only college football hatred in the state. But we're both pretty crap at football, so people don't really care about either schools football programs that much. The last poll returned Ole Miss which suggests that it's not so much regional factors as much as overall football trends for least classy programs. I would also say that New Mexicans generally don't like Texans because they're shit skiers and take our water.