Recent submissions

Comment · 8 years ago
Don't forget that you are not a fruit fly.
Comment · 8 years ago
I see that you prefer not to use recurrency in Python. That decision is correct since python is not optimized for recurrency but it also can make the code more complex. See https://realpython.com/python-thinking-recursively/

On the other hand, using iterators in python is nice. You didn't use iterators to compute the sum of cubes, many problems can be solved in one line using iterators. https://www.datacamp.com/community/tutorials/python-iterator...

Perhaps your code should try to go from the easy cases to the complex cases in pattern matching.

As a hobby programmer I program without stress, if I was to make a living by programming I think I shouldn't enjoy so much.

I think you should read norvig post: http://norvig.com/21-days.html, also to learn to program in python: https://github.com/norvig/pytudes

I believe that in a year or two you could be prepared to judge your progress

Comment · 8 years ago
Caveat emperator, I am reading the first pages of the article you link to. In page 1519 they say 1-alpha is the desired significance level. This is wrong, perhaps they mean that alpha is the significance level and 1-alpha is the desired confidence level. In step 3 they say: Preferred test statistics are the ones that can control Type I errors. But that is wrong, Type I error is a parameter you fix so it is not related to the test statistic. Later giving examples of uniform most powerful statistics they require data following a normal distribution, but in web data the distribution can be a mixture of normals whose means depend of the hour. So perhaps the examples are not realistic in the web setting. To be continued.
Comment · 8 years ago
In one of your comments you say you have improved a lot in two months or so, so perhaps you need a little more practice and I think you could improve a lot more (less time for solving puzzles and writing better code). Anyway, I have tried to solve some of the puzzles. Perhaps other people in this thread can give more valuable information about your coding style. I wish you the best.

Sum of cubes:

  sum(i**3 for i in range(n+1))
findMedianSortedArrays using Haskell:

  let  m a [] n = a !! n
       m [] a n = a !! n
       m (x:_) (y:_) 0 = if x<=y then x else y
       m (x:xs) (y:ys) n = if x<=y then m xs (y:ys) (n-1) 
                         else m (x:xs) ys (n-1)

  let m1 a b = if odd n1 then m a b n12 
               else (m a b n12 + m a b (n12-1))/2 
               where n1 = length a + length b; n12 = div n1 2

  let findMedianSortedArrays = m1
 I haven't checked the code.
Comment · 8 years ago
This is what I tried, recursion taking care of puting the simplest cases first. I haven't checked the solution. I think this kind of problem is like a state machine. In each call of the recursion the length of the pattern or the lengh of the string should decrease, so finally one get to the easy cases of length in (0,1,2).

This kind of problems are designed to test you can define a grammar and apply recursion. Another problem with the same flavor could be to evaluate string expressions like "3+25" using a grammar. My one-hour solution (not checked). But I think I have done similar problems.

         def pat(s,p):
    ...:     if s == "":
    ...:         if len(p)>1 and p[1] in "?*":
    ...:             return pat(s,p[2:])
    ...:     if p == "": return s == p
    ...:     if len(p) == 1:
    ...:         if p == "*": return True
    ...:         return s == p
    ...:     if len(p) == 2:
    ...:         if p[1] == "?":
    ...:             return s == p[0] or s==""
    ...:         if p[1] == "*":
    ...:             if s[0] != p[0]: return False
    ...:             if s == p[0]: return True
    ...:             return pat(s[1:],p)
    ...:     if p[1] != "?" and p[1] != "*":
    ...:         return s[0] == p[0] and pat(s[1:],p[1:])
    ...:     if p[1] == "?":
    ...:         if (s[0] != p[0]):
    ...:              return pat(s,p[2:]))
    ...:         if (s[0] == p[0]):
    ...:             return pat(s[1:],p[2:]) or pat(s,p[2:])
    ...:     if p[1] =="*":
    ...:         if (s[0] != p[0]): return pat(s,p[2:])
    ...:         return pat(s[1:],p) or pat(s,p[2:])
    ...:
    ...:
Comment · 8 years ago
I should like to see some of the problems that take you 2-5 hours to solve. Show your solution, and text about the way you tackle the problem.

Perhaps you need a mentor, someone that can give you some tips about your coding abilities and what you should do to improve.

If you need more than 10 minutes to sum the cubes of numbers from 1 to n in python, then I think you have a problem as a programmer.

Can you point to a leetcode problem that takes you 2-5 hours to solve?

Edited: Two weeks ago you submitted a similar post and in the comments you give this example:

>> To give a concrete example of some of the above, just this morning I tried to code the brute force solution following problem: Give two sorted arrays return the median. I spent over an hour trying to implement the brute force solution involving linearly going through each array and couldn’t code it in Python.

As a hobby programmer, my ten minutes approach:

  def median(a,b):
    ...:     ab = len(a)+len(b)
    ...:     pos = ab/2
    ...:     ia = 0
    ...:     ib = 0
    ...:     for ic in range(pos):
    ...:         if a[ia] <= b[ib]:
    ...:             x = a[ia]
    ...:             ia = ia + 1
    ...:         else:
    ...:             x = b[ib]
    ...:             ib = ib + 1
    ...:     if ab % 2 == 1 :
    ...:        return x
    ...:     else:
    ...:        return (x + max(a[ia],b[ib]))/2
    ...:

 But it is not correct

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton