Fuck off Jow Forums you brainlet. OP said 3 times or more IN A ROW.
Lincoln Walker
r e c u r s i o n
Brody Bailey
>t. has never been in an interview
Jaxson Jones
loop through list, based on the current index look at the hardcoded elements in the i+1/i+2 index and update the list if it meets the condition since deletion is O(n) this isnt that bad
theres nothing wrong with the naive approach
Dylan Fisher
def o(m): if len(m) == 0: return []
n = []
last = m[1] count = 1
for i in m[1:]: if i == last: count += 1 else: n.append((last, count)) last = i count = 1 n.append((last, count))
p = [] for v, c in n: if c >= 3: continue p += [v] * c return p
Daniel Wright
niggerlicious but werks
def faggot(ls) head = nil i = 0 ret = []
while !ls.empty? head = ls.pop
if head == ret.last i += 1 else i = 0 end
if i == 3 2.times { ret.pop } i = 0 else ret
Nolan Torres
oh this also fails now that i look at it i'll just kms
Gabriel Campbell
>updating data ISHYGDDT
Julian Gomez
# xs is the input list kill = set() for i in range(len(xs) - 2): a,b,c = xs[i:i+3] if a == b == c: kill.add(a) print([x for x in xs if x not in kill])
Requires all elements of xs to be hashable. OP is a little vague, but I took it to mean that you should remove all instances of x if x,x,x appears anywhere in the list. So [1,1,1,2,1] goes to [2], not [2,1].
Nolan Evans
certain tools for certain jobs, if ur one of those autists who think le arrays are not supposed to be dynamic!!11one!1 then baka
Luis Ramirez
If you delete elements from an array while iterating through it you don't belong on this board.
Bentley Sanchez
>last = m[1] Should be m[0], right? >for i in m[1:]: Bit confusing to make i the element value instead of the element index, but it works I guess
Brandon Sanders
No data should be mutable, you filthy fuck.
Oliver Ward
Like just loop through it backwards lmao
Jaxson King
DELETE_REPS = 3
def gaychallenge(lst): for i, k in enumerate(lst): j = i mark = 0 while j < len(lst) and lst[j] == k: mark += 1 j += 1 if mark >= DELETE_REPS: for _ in range(i, j): del lst[i]
Done in Python. In-place. Includes test. Set DELETE_REPS to change amount of reps to delete at.
Owen Cruz
Yeah that should be m[0]. My bad.
Angel Taylor
lmao doesnt know the difference between array and arraylist
haha epic funCtioNaL haskell master xD
Nathan Lee
lmao uses java
Wyatt Bailey
Did you write this specifically to trigger ? I'm not even him and I find that amount of mutating-while-iterating a little concerning
Justin Morales
ebin post, Python master!!! XD
Thomas Bailey
>array and arraylist Get out filthy javatrash
Anthony Morgan
:) ahh yes the tears of purists who cant figure out to use the tool for the job
MOM! cancel my meetings someone on Jow Forums actually thinks HASKELL isn't the perfect language for EVERY JOB
Isaac Davis
Nah don't worry it works, let's ship it
James Clark
>using worse tools is appropriate for some jobs
I guess if the job is doing something poorly, then you're right. Different tools for different things.
Landon James
OP here
Sorry you're wrong there buddy, I actually mean to remove the X in a row and keep the others.
Example:
[1, 1, 1, 2, 1] -> [2, 1]
Otherwise it would be a trivial problem not worth posting here.
Brody Russell
acc = [] cur = [] for x in xs: if len(cur) == 0 or x == cur[0]: cur.append(x) else: if len(cur) < 3: acc.extend(cur) cur = [] if len(cur) < 3: acc.extend(cur) print(acc)
>Otherwise it would be a trivial problem not worth posting here. You've got some weird standards there, my dude
this could definitely be cleaned up a bit, but here you go OP proc filterRepeats(nums: seq[int], val, cnt: int): iterator: int = return iterator: int = if nums.len == 0: if cnt < 3: for i in 1..cnt: yield val elif nums[0] == val: let f = filterRepeats(nums[1..nums.high], nums[0], cnt + 1) for i in f(): yield i else: if cnt < 3: for i in 1..cnt: yield val let f = filterRepeats(nums[1..nums.high], nums[0], 1) for i in f(): yield i
Jeremiah Murphy
I wrote something in haskell, but it's ugly. It looked good when I removed "only 3", but adding the "3 or more" part made it repeat too much.
remove_triple :: Eq a => [a] -> [a] remove_triple [] = [] remove_triple (x:y:z:zz:xs) | x == y && y == z && z == zz = remove_triple (y : z : zz : xs) | x == y && y == z = remove_triple (zz : xs) | otherwise = x : remove_triple (y : z : zz : xs) remove_triple (x:y:z:xs) | x == y && y == z = remove_triple xs | otherwise = x : remove_triple (y : z : xs) remove_triple z = z
Benjamin Thomas
my solution: import Data.List removedups x = concat [if (length i) >= 3 then [] else i | i
Juan Sanders
nice!
Angel Gray
What happens if it repeats 5 times in a row?
But anyways, what do you guys think about skipping every other element, say you got [a,a,b,b,b] you check a, then check b since it change you continue from b, check the 3rd b and since it matches you check the one you skipped, if it matches you remove them if they don't you don't.
Technically this could save some comparisons, but you would have to store the current index and manage that, also you would have to have indexed lists in the first place, but I think that's a given.
remove_triple still works if it repeats 5 times in a row. if it detects 4 or more repeats, it only takes off the first one and recurses.
John Kelly
shitty half drunk python def count(lst): cur_el = None cur_el_len = 0 res = [] for x in lst: if x == cur_el: cur_el_len += 1 else: if cur_el_len > 0: res.append([cur_el] * cur_el_len) cur_el_len = 1 cur_el = x
if cur_el_len > 0: res.append([cur_el] * cur_el_len)
return res
def solve(lst): return [el for lst in count(lst) if len(lst) < 3 for el in lst]
doYourOwnHomework [] = [] doHomework (x:xs) | trips 0 x xs = doHomework $ next xs | otherwise = x : doHomework xs where trips n a (y:ys) | n == 2 = true | y /= a = false | otherwise = trips (n + 1) a ys next (b:c:d) | b == c = next (c:d) | otherwise = (c:d)
I’m on a phone and this is probably nowhere near the most elegant solution, but whatever man it probably works (also fuck you for putting a string in a list of ints)
Jaxson Jackson
public class NewClass { public static ArrayList sortList(int[] theList){ int[] newList = new int[theList.length]; ArrayList shortList = new ArrayList(); newList[0] = theList[0]; newList[1] = theList[1]; for (int i = 2; i < theList.length; i++) { if (!(theList[i] == newList[i-1] && theList[i] == newList[i-2])){ shortList.add(theList[i]); } } return shortList;
}
public static void main(String[] args){ int[] a = {1,1,1,1,3,4,5,5,3}; ArrayList myArrayList = sortList(a); for (Object o : myArrayList) { System.out.println(o); } } }
doesn't work for lists with 3 elements or less and just prints the elements in an ArrayList lmao im a trash programmer rn
Ethan Bell
forgot to put edge cases on the baby functions, you get the idea though
Jack Taylor
public static ArrayList findRepeats(ArrayList fin, int[] list, int prev, int count) { if (list.length > 0) { if (prev == list[0] && prev != -1) { count++; if (count >= 3 && !fin.contains(prev)) fin.add(prev); } else { count = 1; } findRepeats(fin, Arrays.copyOfRange(list, 1, list.length), list[0], count); } return fin; }
public static void main(String[] args) { int[] a = {1, 1, 1, 1, 3, 4, 5, 5, 5, 3}; ArrayList myArrayList = findRepeats(new ArrayList(), a, -1, 1); log(Arrays.toString(myArrayList.toArray())); } fixed it up to use recursion
Brandon Williams
So (1 1 2 2 3 3 3 2 1) should become (1 1 2 2 2 1) and not ()? Alright OP, whatever you say. -module(homework). -export([do/1]).
It's not tail recursive but I couldn't be bothered to make it tail recursive so go fuck yourself. It's a meme question with no real specific requirements and I'm pretty sure OP is a faggot. But some autists are still going to come to me complaining that it's "not performant" or some shit. Go fuck yourself.
Julian Torres
uhm
Brandon Walker
prolog challenge([], []) :- !. challenge([X], [X]) :- !. challenge([X|[Y|[]]], [X|[Y|[]]]) :- !. challenge([X|[Y|R]], [X|S]) :- \+ X is Y, challenge([Y|R], S), !. challenge([X|[X|[Y|R]]], [X|[X|S]]) :- \+ X is Y, challenge([Y|R], S), !. challenge([X|L], S) :- scroll(X, L, R), challenge(R, S).
scroll(X, [Y|L], [Y|L]) :- \+ X is Y. scroll(X, [X|L], M) :- scroll(X, L, M).
Jeremiah Miller
rm3
Oliver Perez
Are you allowed to create a new list, or do the entries with 3 or more occurrences have to be ejected from the list?
Ian Roberts
either way works but you're a faggot if you mutate data
Alexander Rivera
fn a_faggots_homework(list: &Vec) -> Vec where T: std::cmp::PartialEq + std::clone::Clone { list.iter().enumerate().filter( |(i, val)| { let it = list.iter().enumerate() .skip_while(|(j, e)| j + 2 < *i || e != val) .take_while(|(_, e)| e == val); it.count() < 3 } ).map(|(_, val)| val).cloned().collect() }