# Tag Info

153

Your Pokemon class (declaration) class Pokemon { public: std::string type; double weight, height; std::string Gender; int evoLevel; bool finalEvo; int dexNum; std::string name; Pokemon(std::string name2, std::string type2, double weight2, double height2, std::string Gender2, int evoLevel2, bool finalEvo2, int dexNum2); ...

144

Note: At some point, this review drifted into the realm of assembler and GMP. An actual review is at the end of this post, whereas the first section discusses the runtime-problems concerning pow, wrong data types and arbitrary large integers. No life time for run time Would there be any way (on my current machine) to get this to run in my lifetime? ...

107

I think you are looking for _.keyBy (or _.indexBy in older versions) _.keyBy(data, 'rel');

104

Let's look at the code. from random import randrange import time Your imports are very minimal! Good. # Snow animation # Snow is simply the # symbol here. Half of the snow moves at 1 char # per frame, while the other half moves at 0.5 chars per frame. The # program ends when all the snow reaches the bottom of the screen. # The viewing area is 80x25. It ...

79

That's not a bad program, despite the number of suggestions I'm about to make. I do recognize you're a learner, and a young learner at that. There are several levels at which we can analyze this program. One is checking the current implementation. Another is considering whether it is portable. We can question whether the interface is good — should ...

77

bool isPrime = true; for (int j = 2; j < i / 2; j++) { if (i%j != 0) continue; isPrime = false; break; } if (!isPrime) continue; This is one of the most primitive and least efficient ways to calculate whether or not a value is prime. First and foremost, we deserve a method which encapsulates this logic and can be called repeatedly: bool ...

76

Well let's start with this: for (a = 1; a < 100000; a++) { for (b = 1; b < 300000; b++) { for (c = 1; c < 500000; c++) { let's ignore d for now. What do you do here? You check 1, 1, 1, then 1, 1, 2, then 1, 1, 3, ... up to 1, 1, 499999. Then you start over at 1, 2, 1. But you already checked 1, 1, 2, so why are you checking 1, 2, 1? ...

74

You really need to remove some of your global variables. As an example I'd change all your browns to use a list instead. brown = [0, 0] As you do a lot of logic over brown, cyan, pink, etc, I'd make a dictionary. Dictionary's are like lists, they have a few more features that I'd use and are basically lists but can have 'any' key. And so I'd use: places =...

70

I like how you have declared the Fizz and Buzz 'constants'. It makes the code more readable. The comments are useful too, though, for consistency, the second comment should be changed from: BTW Froot will run 1 through 100 to BTW Froot runs 1 through 100 The idea of generating Froot from Frootz is also good, because it reduces the computations later in ...

59

Cool animation! Let's get some linting out of the way. As per PEP 8, you should use 4 spaces of indentation consistently, and function names should be snake_case. Scalability The main weakness of your design is scalability. If you extend the loop to run indefinitely, then you will eventually run into performance issues. One problem is that the drops ...

55

Don't. Repeat. Yourself. That's an essential principle. You repeat the "do you want XY" cycle over and over manually. That's not only error prone, but also hard to maintain. For example, let's say you want to ask the customer how many items they want. Then you would have to add or change your input handling for every single item. Maybe you want to use ...

53

This is sophisticated for a first attempt, but today would be a great day to break yourself of bad habits. Your code is full of them. Start with: format your code using standard formatting conventions. We understand code more easily if it is vertical, and your code is horizontal. Let's go through this line by line. static void Main(string[] args) { ...

53

I'd like to see if this is a reasonable solution, or is just plain terrible. I wouldn't say it is "terrible" - mostly because it works and doesn't appear to be very inefficient. However, there are some improvements that can be made. use strict equality comparison - i.e. === when comparing values. That way it won't need to convert the types. ...

51

Congratulations on your first large project. I'm not sure whether this review has grown a little bit overboard, as it is now both a review as well as a mini tutorial. Either way: What the char? Charmander-char Char cha Charmander Char. Char? Charmander! Is it confusing in general? Char! I mean, yes. Mostly due to the names of your functions. As ...

50

I really can't believe I'm reviewing lolcode right now... The specification does allow for variables to be any case, but all existing documentation uses lower case for variables. So, lowercase variables would be more idiomatic, but I'd go with camelCase for readability. Frootloopz is creative and idiomatic, but Froot is meaningless beyond its relation to ...

49

Concept Obligatory XKCD comic, before I begin: Enforcing password strength by requiring human-unfriendly characters is no longer considered good practice. Nevertheless, I'll review the code as you have written it. "Obvious" simplifications Any code with the pattern if bool_expr: return True; else: return False should be written simply as return ...

47

This is a pretty reasonable start on a simple interpreter. Edward's suggestions are all good; a few additional suggestions: interpret("+++++++++++++[->.... Please break up that long line. C allows you to break up literal strings "like " "this." void goToLoopEnd(char** ip) { ... void goToLoopStart(char** ip) { ... If you wrote these instead as char *...

45

Is this FizzBuzz Swift-y? Kinda, but it could be a lot better. Here's what I would do to fix it: Extrapolate this code into a method, then call the method from the for loop. func fizzbuzz(i: Int) -> String { // ... } There is a handy Swift feature called "Tuples". Tuples are groupings of values. We can use them to represent our results from the ...

44

I see some things that you might want to use to improve your code. Use an early bailout If the passed number x is less than 9, the routine can immediately return 0. Eliminate multiples of 2 Since 9 and 2 have no common factors, you can speed up the operation (on average) by shifting the incoming x to the right until the least significant bit is non-zero. ...

42

Revised Solution As per Pau Fracés comment above, here is the complete solution. The solution given by John Anderson would index all objects by the key. However, this would not create a key-value pair map. To complete the solution of generating a full hash map, the values must be mapped to the key. Using the mapValues function, the values can be extracted ...

42

Arithmetic Project Euler questions are meant to educate you about both mathematics and programming. It would be a good idea to understand what these triangular, pentagonal, and hexagonal numbers actually are, rather than blindly applying the given formulas. One performance improvement would be to find a way to generate successive elements of each sequence ...

41

Notice how the square of a number 15 or greater exceeds 200? What you can do, is set the interval from 1 to 14. There is no advantage in evaluating the same combination over and over again. Realize that the most efficient way is to structure your for loops such that $$a \leq b \leq c \leq d$$ In your attempt, you are iterating 38,416 times! By ...

40

One thing you should note is that the fourth iteration is useless. Once you fixed the first 3 variables, you need to find the value for the fourth one that equals to 200 minus the sum of squares of the first 3. You don't have to go through all the possible numbers to check if one of them squared is equal to N, you can simply take the square root of N and ...

39

It is good practice in Haskell to separate the functional code from the IO. In this case, you could (and therefore should) define a lolcat :: String -> String function. Be sure to put a type declaration on all functions — you didn't write one for your main. Defining variables a, b, c, and d is overkill. I would write this as a composition of functions. ...

38

Why do most people (on the internet) recommend using recursion because it's simpler and easier to write the program? Logically I thought that we should write it in a way that is fast and simple. This is a perceptive question. I wrote an article about exactly this topic in 2004, which you can read here: https://docs.microsoft.com/en-us/archive/blogs/...

36

Welcome to CodeReview. It's never too early to develop good coding habits, and reviewing your code is about the best way to do so. First, congratulations on writing a clean, straightforward program. While you do have some issues (below), they're not major, and your program seems appropriate for its level. Now, for the issues ;-) Use whitespace Python ...

35

Brainfuck Multiplication Elaborating a bit more about 200_success' multiplication, and the "shorter, less readable version, using similar ideas, but with more cell reuse": The ASCII values of what you want to write is, as 200_success mentioned: 72 101 108 108 111 44 32 87 111 114 108 100 33 So these are the numbers we want to generate. Let's start by ...

35

In general, it is bad practice to perform string substitutions in multiple passes, feeding the output back of one substitution into another round of substitutions. (Here is an example of how multiple-pass substitutions can lead to incorrect results.) In this case, it happens to be safe, since none of the outputs overlap with any of the patterns, but I ...

35

You don't get drops of snow! Clearly it should be for flake in flurry:

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