11

Two comments: There isn't any reason to keep a list of all the fib numbers. You only need the last two numbers to compute the next one. A number with 1000 digits satisfies 1e1000 <= f < 1e1001. It might be faster to compare f to the numbers rather than to convert it to a string and get its length. def fib_of_length(n): """returns index of the ...


11

This isn't a full review but something I found very interesting about this problem: I would have thought that keeping a list of every Fibonacci number would get expensive over larger numbers but that doesn't seem to be the case with my testing. Instead it seems the bottleneck is the line: len(str(fibs[-1])) < n: I ran the function for n = 10,000 and it ...


8

It's possible to calculate the nth Fibonacci number directly thanks to Binet's formula. Due to floating point errors, the formula doesn't give correct values if n is too large, but it works fine in order to calculate the number of digits. from math import log10, floor, ceil def fibonacci_digits(n): if n < 2: return 1 ϕ = (1 + 5**0.5) / ...


8

Project Euler has quite a few problems on the Fibonacci numbers. Other things also repeatedly crop up, like prime numbers, triangular numbers, and so on. In fact, quite a few problems build on earlier, easier, problems. Because of this it is worth it to start designing your functions for reusability. Put these functions into modules, so you can reuse them ...


3

Wow! What a project! I had tons of fun working on this! There are a lot of things to like about your code. Instead of going over the general improvements I made, I'm going to explain each part that I changed and why I changed it. Note: I did not touch the threading * and other hunger behavior because I am not confident enough with my ability to improve ...


2

The code looks quite good in general. Without a deeper look at the problem, there are twothree things that can easily be improved: Building the look-up table You use letter_scores = {letter: ord(letter) - 64 for letter in string.ascii_uppercase} which makes use of the ASCII encoding to determine the value of each letter. The following could be considered ...


2

The standardlibrary module math already contains a factorial function. On my machine it is about 20 times faster than your function using n = 100. It also does not suffer from stack size limitations as yours does (try computing fact(3000)). Alternatively you could learn about memoizing, which will help you in many Project Euler problems. Here it would be ...


2

First this is probably C++ rather than C, the C programming language does not support function overloading (blink as an example). Magic Numbers In programming a Magic Number is a numeric constant in code that doesn't identify what is is. Magic numbers make the code harder to understand, debug and maintain. When magic numbers are used as a basis for ...


2

You wrote several for loops without any spaces. Please don't do that, as it makes the code harder to read. Instead of for(;*colors;colors++) { blink(*colors); } you might prefer while (*colors) { blink(*colors++); } Moving loop() to the bottom of the file would save you some forward declarations. Your Serial.print() statements might ...


2

You’re building up a huge list of permutations in order to get to exactly one permutation. This is needlessly using time (computing all permutations that come before it) and memory (storing all those permutations in a list. If you have 9 objects, you can have 9! = 3,628,800 permutations. So with the 10 digits, 0 through 9, the first 362,880 permutations ...


2

itertools.islice() Looks pretty good, but generating a list of all the permutations can take a lot of memory. Use itertools.islice() to skip over the first 999,999 permutations that you don't want. The indexing parameters to islice are just like for range(start, stop, step) def lexicographic(n, digits): """Assumes digits a string. returns the nth ...


2

I think the most important things to which you should pay attention are: Avoid code duplication. Every time you find yourself writing the same or similar code even twice, think about using loops (hint: your load method) or extracting the code into a function (hint: dead method). The two most evident out of many existing reasons to avoid code duplication: ...


2

Good job separating concerns Your tetris game-board model, piece and UI code is nicely separated in classes, so each one has its own responibility. Well done! Don't use magic values, use Enum public Piece(int f) This switches on a magic value of f. Piece is a excellent candidate for Enum! public enum Piece { L, J, T, Z, I, ... } Enum works as class ...


1

Rubocop Report Rubocop was able to solve minor layout issues regarding the use of white spaces. One note-worthy change it proposed is: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. days_aggregate.each do | key, task | parts = key.split("-") parts = key.split('-') A bigger ...


1

Your comprehensions are hard to understand, as you have two on one line. I recomend you spread them over multiple lines to increase readability. There is no benifit to using a dictionary comprehension, and only makes me think you're abusing comprehensions. Just use a normal for loop and use yield. You don't need to pass n, you can find the limit by using ...


1

Concept Current security research recommends eliminating character composition requirements. It's more important to blacklist common weak passwords. Also, passphrases are a good alternative to passwords. For the purposes of this code review, though, I'll play along with your original premise. Style PEP 8, the official Python style guide, recommends ...


1

In your code you often use the expressions len(m) and len(m[0]). The code would become clearer if you defined proper names for these expressions, like: func (m Matrix) Rows() int { return len(m) } func (m Matrix) Cols() int { return len(m[0]) } This way, you can write zeros := matrix.Zeros(m.Rows(), m.Cols()), which make the code operate in mathematical ...


1

Getting it running Currently the code that's posted does not run - it fails with a SyntaxError. This part can be easily overcome by changing the single quotes here print( "\nWelcome to URL Generator v3.0 VERSION UPDATE: 31/08/2018 \n-------------------------------- -------------------------- ...


1

Problems The use of _length in your classes is problematic, because that value is shared between all instances of the same class, which means it will refere to the wrong value when you have multiple non-empty lists of the same type. One of the big problems with linked lists in general is the loss of this length information if you do not package the list (...


1

Review You should take advantage of the bi-directional nature of a doubly linked list. It's a pitty to let it use navigation of a normal linked list just for the sake of enabling inheritance. And why should a normal linked list be able to branch between normal and doubly mode? This is a code smell. A practical way to create a doubly linked list, is to ...


1

Structure and flow Add levels of abstraction Your overall program structure is hard to read. You have a bunch of different functions calling each other in a loop/chain, which means you have to look at all of the code just to understand the basic sequence of events. One way to fix this problem is to add a main() function that defines the core sequence of ...


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