4

Your code is horrible: You don't check for end-of-file, which will lead to endless loops You don't check for failure of malloc or realloc You call realloc way too often, which makes the code slow for large lines of input You cast the result of malloc You use the outdated style of function definition from the 1980s The variable string is not a string but ...


3

Good things I like the functional approach taken with this code, and that some ecmascript-6 features like arrow functions are used. Suggestions const vs let It would be wise to default to using const for any variable that doesn't need to be re-assigned. If you later determine a value should be re-assigned then switch it to using let. This helps prevent ...


2

Strategies It would have been good to summarize the key points and strategies of the different implementations. Mostly for yourself, to clarify your thinking and solidify your understanding. Secondly for reviewers :-) Let me take a jab at that now. Solution 1 while there are lists to merge find the minimum head and merge it update the list with the ...


2

Note, I don't think about performance, only about kotlin. Iluminate branch in your when, you check if the rightIndex >= string.length+1. this means in the next branches the size is maximal string.length. Substring is exclusive, so it allows str.length. this means the second and third branches are identical. Use Set It would make more sense to me to ...


2

Why are you reimplementing length O_o? dft_resolve_nested :: Double -> Int -> [((Double, Double), Double)] -> [(Double, Double)] dft_resolve_nested _ _ [] = [] dft_resolve_nested k n (((x, y), t) : xs) = do let angle = 2.0 * pi * t * k / fromIntegral n let sumreal = x * cos angle + y * sin angle let sumimag = - x * sin angle + y * cos angle ...


2

Code does not handle end-of-file or rare input error well as there is no attempt to detect EOF. Perhaps something like // char keystroke=' '; int keystroke=' '; while((keystroke=getc(stdin))!='\n' && keystroke!= EOF) { string[0][size++]=keystroke; string[0]=(char*)realloc(string[0],size+1); } if (keystroke == EOF && size == 0) { ...


1

I wouldn't give this a name. It is equal to foldMap pure and feels to me like it might be refactored away with more context.


1

Just have the time to take a quick view on your code, but one of the first thing you have to learn to do (before using design pattern and such things), is to refactor your code. By simply scrolling, we can see df_additional[col] more than ten times. For all the places where you just need to read this value, use a local variable to store it. If you need to ...


1

This code does in fact print the expected result of dog runs, so I'm going to go ahead and give it a quick review. First: your mixed method does not use the self parameter, so it could be a @staticmethod. Figuring out which of your object's methods actually depend on the object state makes it easier to figure out which methods might affect each other. ...


1

The simplest thing that comes into my mind is have a hashmap to cache sum of all the elements from position i to the end for L = [1, 2, 3, 4, 5] the map would look like Index | sum till end 0 | 15 1 | 14 2 | 12 3 | 9 4 | 5 once you have this you can do something like this public int sum(int i, int j) { return map.get(i) - map.get(...


Only top voted, non community-wiki answers of a minimum length are eligible