QUICK Jow Forums

QUICK Jow Forums

GIVEN AN ARBITRARY ARRAY OF INTEGERS, SORT IT SO THAT ALL THE NINES ARE AT THE END OF THE LIST OR THIS BIRD WILL STAB YOU

e.g.
[1,9,7,4,9,3,2,6,9]
to
[1, 7, 4, 3, 2, 6, 9, 9, 9]

Attached: 34A6DBE700000578-3611571-A_crow_snatched_a_knife_from_the_scene_of_a_shooting_in_Canada_a-m-37_14642 (634x635, 181K)

Other urls found in this thread:

gkoberger.github.io/stacksort/
pastebin.com/LDDhWrKs
pastebin.com/mx91wuT1
pastebin.com/fckkPJWZ
twitter.com/SFWRedditVideos

im not doing your homework for you, faggot.

Attached: 1467151892792.jpg (300x300, 10K)

You will drop out your course is over and will have nothing to show for it but debt

Because you can't

Waiting for the Haskell one liner chad to appear

Array.prototype.sleepSort = function(callback) {
const res = [];
for (let n of this)
setTimeout(() => {
res.push(n);
if (this.length === res.length)
callback(res);
}, n + 1);
return res;
};

[1,9,7,4,9,3,2,6,9].sleepSort(console.log);

arr.filter(item => item !== 9).concat(arr.filter(item => item === 9)

Is it a custom now to post homework questions in this format?

Use stacksort: gkoberger.github.io/stacksort/

arr.sort()

Or write a sort algo from Wikipedia

This exact format has been happening since I started coming here at least, like 2011

Claymore?

To produce results as described in OP, the following Ruby function should do it:

def nine_sort ary
nine_count = 0
next_array = []

ary.each do |e|
if e == 9 then nine_count += 1
else next_array.push e
end
end
nine_count.times { next_array.push 9 }
next_array
end


That won't work. OP doesn't want to actually sort the array, he just wants to push all the 9s to the back.

{(x where x9), (sum x=9)#9}

I'm sure there's a less verbose way to do this

def sort_nines(lst: List[int]):
res = [x for x in lst if x != 9]
res.extent((len(lst)-len(res)) * [9])
return res

Stabby Bird is a time-honoured Jow Forums tradition, newfag

I feel like there's some clever way to do this shorter in python

sorted(lst)

LINQ is fun! FUN!~
public IEnumerable NineSort(IEnumerable list)
{
return list.Where( x => x != 9).ToList().Append(list.Where( x => x == 9).ToList());
}

doesn't work in two different ways, first off he said integers and 9 isn't the biggest integer, and then also it implied the rest of the list was unchanged

>all this meme functional solutions for a simple problem

[x for x in a if x!=9] + [x for x in a if x == 9]


:^)

thats most programming discussion on Jow Forums

Eh, the functional solutions just allow the problem to be solved in less lines.

Show me an iterative or object oriented solution that is faster to write AND easier to understand.

Protip: you can't

(assuming a is the list here)

void sort(int[] array) {
int j=array.length-1;
for (int i=0;ii){
j--;
}
int tmp = array[i] ;
array[i] =array[j];
array[j] =tmp;
j--;
}
}
}

OOPsies getting mogged by a simple array problem

sorted(lst, key=(9).__eq__)

YOU GET FUCKING STABBED

This trick question isn't a "sorting" problem at all.
(def xs [1 9 7 4 9 3 2 6 9])
(concat (remove #{9} xs) (filter #{9} xs))

Is a Clojure one-liner okay?

Attached: fem.jpg (455x652, 29K)

OP here

The bird has informed me that anyone who thinks this list just needs to be sorted is a Pajeet who can't read or code

Haskell is too verbose family

Could be even shorter in K

I wrote it on my phone so pls no hate, also it's O(n).

uncurry () . partition (/= 9)

Stab me bird, I deserve freedom from this nightmare.

[x for x in arr if x != 9] + [x for x in arr if x == 9]

Attached: 1553895263984.jpg (779x899, 161K)

def nine(xs):
if xs == []:
return([])
if xs[:1] == 9:
return(nine(xs[1:]) + [9])
else:
return(xs[:1] + nine(xs[1:]))

forgot pic

Attached: 1531705448958.png (595x842, 245K)

>first off he said integers and 9 isn't the biggest integer
Don't overengineer simple problems.

>and then also it implied the rest of the list was unchanged
Is it?

based retard

dil8

2nd if should be elif

Marginally shorter Q:

{(x&:[x9]),(+/[x=9])#9}


Where is your God now

And you can't be bothered to use code tags on your phone?

Can you explain how this works?

end = $(filter-out $1,$2) $(filter $1,$2)

.PHONY: all
all: ; $(info $(call end,9,1 9 7 4 9 3 2 6 9))

im bleeding

import numpy
def ops_homework(x):
return np.concatenate([x[x!=9], x[x==9]], axis = 0)

*import numpy as np

thanks

in haskell you can partially apply operators so (/= 9) is the same as \x -> x /= 9
partition has type (a -> Bool) -> ([a], [a])
so what it does is split the list in two with the given predicate and then put the two parts into a tuple (left when the predicate is true, right when it's false)
you can use operators as normal functions with by putting parens around them hence we pass the () (which is append for lists) to uncurry,
uncurry takes a normal function (normal as in lambdas) and returns that same function but applicable on a tuple instead, it's type is (a -> b -> c) -> ((a, b) -> c)
so now we have to partially applied functions:
partition (/= 9) :: [a] -> ([a], [a])
uncurry () :: ([a], [a]) -> [a]

and we simply chain them with
(.) :: (b -> c) -> (a -> b) -> a -> c

so we now have a function
uncurry () . partition (/= 9) :: [a] -> [a]

which does what OPasked for

Attached: 1530910692910.png (850x1279, 918K)

> his language doesnt have stable_partition
vector vi { 1, 9, 7, 2, 9, 3 };
stable_partition(vi.begin(), vi.end(), equal_to{9});

Phoneposting, so might have mistakes.

>recursion limit reached

std::fill(std::remove(vi.begin(), vi.end(), 9), vi.end(), 9);

Great explanation. Thanks.

> remove + fill the same elements
I guess it can be done by std::remove_if alone

int* ninesort(int* arr,int size){
int last = size-1;
for (int i = size-1; i >= 0; i--)
{
if(arr[i] == 9){
arr[i] = arr[last];
arr[last] = 9;
last--;
}
}
return arr;
}

>inb4 doesn't keep the original order

Please rate my solution in C

pastebin.com/LDDhWrKs

Jamal, just do what other niggers do, fail hard, then complain on Jewbook, "dat dem whytee, dey be oppressin' me!!! wit edukayshun exsams an' sheeeeeeit.

n = lambda x: sorted(x,key=(lambda x:x==9))

Attached: .jpg (526x508, 31K)

it's shit

see

I wish we could see how some of these actually run on big lists and see how the speeds compare, I know some like mine here can't actually even handle large enough lists

Updated it, had some useless variables. If anyone has a better C solution I'd love to see it :)

pastebin.com/mx91wuT1

Nice.

Attached: Untitled.png (398x334, 7K)

version 2

Attached: Untitled2.png (445x292, 6K)

Why's that? I'd love some helpful criticism. What is a better way to approach the problem?

you use 2 loops, right?
can you do it in 1 loop?

you shouldn't traverse it twice.

Do your own homework faggot

version 3: 1 loop without LINQ magic

Attached: Untitled3.png (535x615, 16K)

Arrays.sort(new int[] {1,9,7,4,9,3,2,6,9});

Java

python
def main(lst):
c,ret = 0,[]
for i in lst:
if i != 9:
ret.append(i)
else:
c += 1

for i in range(c):
ret.append(9)

return ret

if __name__ == '__main__':
lst = [1,9,7,4,9,3,2,6,9]
print (main(lst))

import ninesort

retard
read the problem again

sasuga javatard

quicksort with a custom comparator that makes everything equal but less than 9 for in place constant space
or just clone the array and put nines on back and everything else in front for linear time but extra space

i think you'll find you're the retard, he only says nines at the end, the order of non-nine numbers is irrelevant

you're sorting the whole array retard

[1,9,7,4,9,3,2,6,9] => [1, 7, 4, 3, 2, 6, 9, 9, 9]

how's the 2nd array sorted fagget

do you see the example given by OP?
e.g.
[1,9,7,4,9,3,2,6,9]
to
[1, 7, 4, 3, 2, 6, 9, 9, 9]

Attached: r_235815_f6MZA.jpg (799x449, 30K)

samefagging hard

Attached: flycatcher.png (756x900, 59K)

not him but to be fair it doesn't specify that the second one is a uniquely correct solution
the bigger problem is the fact that integers go past 9

>m-muh samefag
coping retard

see the time of those 2 posts you quoted:
06/24/19(Mon)23:48:27 No.71573510
06/24/19(Mon)23:48:30 No.71573511
3 seconds? samefagging?
see your post in my screenshot

Attached: not_samefagging.png (510x590, 61K)

Yes.

Now, sort it so that all the nines are at the beginning of the list.

def sort_nines(arg_list=tab):
tmp = []
nines = 0
for i in arg_list:
if i==9: nines+=1
else: tmp.append(i)
return tmp+[9]*nines

dirty way

all these codes, and you still ask more?
i'm getting tired of this.
here's version 4 for you.

Attached: Untitled4.png (202x123, 2K)

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BlockArguments #-}

import Data.List

ninesLast = sortBy $ curry \case
(9, _) -> GT
(_, 9) -> LT
(l, r) -> compare l r

oh, I misunderstood the requirements
since sort is a stable sort you can simply do this
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BlockArguments #-}

import Data.List

ninesLast = sortBy $ curry \case
(9, _) -> GT
(_, 9) -> LT
(_, _) -> EQ

I realize now that I'm a dummy lol, thank you guys

pastebin.com/fckkPJWZ

practice makes perfect
i recommend spoj.com to improve your skill
your code are judged by correctness, speed and efficiency in memory consumption.

Attached: 000.jpg (715x1000, 205K)

(let
((p '(1 9 7 4 9 3 2 6 9)))
(loop for i in p
when (= i 9) collect i into n
when (not (= i 9)) collect i into s
finally (return (append s n))))

What the fuck is this highlighting.