(defun homework (c str) (let ((next "") (found nil)) (loop for x in (reverse (loop for i across str collect i)) do (if (and (equal c x) (not found)) (setf found t) (setf next (concatenate 'string next (string x))))) (reverse next)))
(format t "~A~%" (homework #\c "science")) [\code]
James Harris
(defun rem (char string) (remove char string :from-end t :count 1))
Robert Campbell
These are all inefficient. Shame on you
Oliver Harris
actually these are all pretty efficient so fuck you instead
Jeremiah Gonzalez
def rem(char, string): s = list(string) for i in range(len(s)-1, -1, -1): if s[i] == char: s.pop(i) break # you didn't specify a return, but as strings are immutable it is necessary return "".join(s)
t. brainlet here, forgot a 1 as the second parameter to replace, sorry
Joseph White
module SomeFaggotsHomework where
rem :: Char -> String -> String rem c s = take i s ++ drop (i + 1) s where i = index c s 0 0 index _ [] _ last = last index c (s:ss) pos last | c == s = index c ss (pos + 1) pos | otherwise = index c ss (pos + 1) last
theres probably a much more efficient way to do this but i'm not that good at haskell
Blake Powell
#include
public static void(){ do print("Hello xd c me c u c everyone u cuck."); remove the last instance of 'c'; } end
thanks it works, but if I don't input an integer it gives me an error instead of taking to the print command I want it to now.
i'd like it to be an integer between 1 and 10, BUT if you input text or an integer that's not within those parameters to give a different print instead of an error
also how do i make repeat code? like, making something run a specific line again instead of me having to restart?
Xavier Clark
If you call int() with a non integer you will get a ValueError, that is why you are getting an error.
You can catch the error with a try/except block and then print something to the user.
num = input("Input a number: ") try: num = int(num) except ValueError: print("This is not a number") else: if not 1
Sebastian Thomas
public String removeC(char a, String s){ String x = ""; for(int j = 0; j
Blake Campbell
Also, it's a good idea not to have integers strewn through code. MAX = 10 MIN = 1 SUCCESS = 7
num = input("Input a number: ") try: num = int(num) except ValueError: print("This is not a number") else: if not MIN
Michael Walker
>calling C++ a 'real language' >not using C
fuck off
Grayson Fisher
yeah man that's perfect, i really shouldn't be trying to go that deep since i literally just started but i did the EXACT same as the guy in the video and it didn't work which ticked me off
Landon Barnes
[Code] Def rem(char,string): (a,b,c) = string.rpartition(char) Return a + c [/code]
kotlin master race fun rem(c: Char, s: String) = s.removeAt(s.indexOfLast { it == c })
Alexander Long
i can do this in TI Basic, can I join anonymouse now plx?
Ian King
Holy shit, everyone is massively overcomplicating this.
def rem(c, instr): last_idx = instr.rfind(c) # Ignore next two lines if it's safe to assume the input always contains c if (last_idx == -1): return instr return instr[:last_idx] + instr[last_idx+1:]
5 lines, 3 if the precondition check isn't needed. The only objects allocated past the initial arguments are one integer, two intermediate strings, and the result string.
Too long and horribly inefficient. An explicit loop will be slower than a behind-the-scenes C function. Not to mention list(string) means a string is getting allocated for every list element.
Inefficient. Allocates two new strings plus an array, then the final string.
Bad, there's no need to reverse a list just to do right-indexing.
Same problems as #1.
Good and works in any language with a sane regex system. Whether it's the best performance depends on the language.
See others.
See me after class. Worst of the bunch. Every time the string gets appended in the loop, a new string object is allocated.
t. pajeet What the fuck is this even supposed to be? >s[-x].remove() OOP in loo
Actually most java pajeets are smart enough to not make basic mistakes like string concatenation in a loop, even if it's only because their IDE tells them to stop fucking doing it.
Nathan Martin
I did it, what do I win? >>> def rem(c, s): i = s.rfind(c) return s[:i] + s[i+1:] if i != -1 else s