Skip to content

Conversation

@jpg-130
Copy link
Contributor

@jpg-130 jpg-130 commented Jun 29, 2019

calculating factorial using memoization added

Copy link
Contributor

@shahabmohammadi shahabmohammadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good , the code working correctly and i think could explain the idea of developer very easy.

@cclauss
Copy link
Member

cclauss commented Jul 13, 2019

Could you please add a doctest or two?

@jpg-130
Copy link
Contributor Author

jpg-130 commented Jul 14, 2019

It is showing that the travis-ci build failed, however, it works well on the local machine. What changes should I incorporate?

@cclauss
Copy link
Member

cclauss commented Jul 14, 2019

https://travis-ci.org/TheAlgorithms/Python/builds/558476077#L705
Think like a compiler would. Is the variable spelled correctly? Is it in scope?

@cclauss
Copy link
Member

cclauss commented Jul 14, 2019

Need another hint?

@jpg-130
Copy link
Contributor Author

jpg-130 commented Jul 14, 2019

@cclauss I'll try. Thanks!

if __name__ == "__main__":
import doctest
result=[-1]*10
result[0]=result[1]=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hint: Move lines 33 and 34 inside the factorial() function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok but if I do that the values are recomputed every time the function is called i.e. I don't want to recompute 3! if 7! is already computed.

Copy link
Member

@cclauss cclauss Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Then put those two lines at the top of the file at global scope before the function and the main()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank You!

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@cclauss cclauss merged commit f195d92 into TheAlgorithms:master Jul 17, 2019
@jpg-130 jpg-130 deleted the factorial branch July 17, 2019 07:06
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* adding factorial

* adding doctest

* Update factorial.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants