If 'n' is the quantity of elements to be sorted there's
no way you can write an algorithm with complexity O(n) for the worst
case not knowing something special about the data.
For example, Quicksort will give you O(n*(log(n)) on average case (O(n^2) in the worst case).
You gotta be much more specific than that if you really need an O(n) code.
There's probably assumptions you didn't mention about the data if O(n) it's really what you're looking for.
PS: Looks like a joke as stated..
----------------------------------------
> Date: Fri, 24 May 2013 01:04:51 -0700
> Subject: help how to sort a list in order of 'n' in python without using inbuilt functions??
> From: lokesh...@gmail.com
> To: pytho...@python.org
>
> i need to write a code which can sort the list in order of 'n' without use builtin functions
> can anyone help me how to do?
That's trivial!
# l is a list of numbers: 0,1,2
def order_n(l):
r = []
count = [0]*3
count[2] = len(l)
for i in range(len(l)):
count[1] += abs((l[i]>0)-1)
r.insert(count[l[i]], l[i])
return r
'count' is a list I've defined to count the quantity of the elements in the argument, not the method.
I don't think it needs any explanations, but if you have any doubts just ask. ;)
Good luck!
lol I forgot to include this monkey patch! ;)
def length(l):
x=0
y=l[:]
while y:
x+=1
y.pop()
return x
def absolute(x):
return x if x>0 else -x
def reach(x):
y=[]
z=0
while z<x:
y.append(z)
z+=1
return y
----------------------------------------
> Date: Sat, 25 May 2013 18:47:24 +1000
> Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions??
> From: ros...@gmail.com
> To: pytho...@python.org
>
I'm glad he didn't ask for a Pseudo-RNG without built-ins! ;)
----------------------------------------
> Date: Sat, 25 May 2013 19:14:57 +1000
> Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions??
> From: ros...@gmail.com
> To: pytho...@python.org
>
> On Sat, May 25, 2013 at 7:10 PM, Carlos Nepomuceno
> <carlosne...@outlook.com> wrote:
>> ----------------------------------------
>>> Date: Sat, 25 May 2013 19:01:09 +1000
>>> Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions??
>>> From: ros...@gmail.com
>>> To: pytho...@python.org
>> [...]
>>> Very good. You are now in a position to get past the limitations of a
>>> restricted-environment eval/exec. Avoiding builtins is actually a fun
>>> skill to hone.
>>>
>>> ChrisA
>>
>>
>> I'm glad he didn't ask for a Pseudo-RNG without built-ins! ;)
>
> def random_number():
> return 7
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
Try flipping a coin. I flipped one a couple of times and got the seventh face once.
Indeed! It's a joke Mark! lol
;)
lol It worked fine on my d8! lol
def f(x):
return x+1
or you can just go:
f(roll_d6())
;)
It depends if the result (any operation) is in the required range.
For example: "int(random.random()+1)" it's not random at all!
But "int(random.random()*1000)" my look random if it fits your needs.
;)
> ya steven i had done the similar logic but thats not satisfying my professor
> he had given the following constrains
> 1. No in-built functions should be used
> 2. we are expecting a O(n) solution
> 3. Don't use count method
PS: If you find something faster please let me know!