Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCS contraction addition in dynamic programming #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

priyda
Copy link
Contributor

@priyda priyda commented Jan 7, 2023

The contract has two functions:

The lcs function takes two strings and the lengths of the strings as input and returns the length of the LCS of the strings. The view keyword specifies that this function does not modify the state of the contract, so it does not need to be executed on the blockchain.

The max function is a helper function that takes two unsigned integers and returns the maximum of the two. The private keyword specifies that this function can only be called from within the contract.

The lcs function first checks if the result for the input strings is already stored in the cache mapping. If it is, the function returns the cached result. If the result is not in the cache, the function calculates the result using the standard recursive definition of the LCS problem and stores the result in the cache before returning it.

The contract has two functions:

The lcs function takes two strings and the lengths of the strings as input and returns the length of the LCS of the strings. The view keyword specifies that this function does not modify the state of the contract, so it does not need to be executed on the blockchain.

The max function is a helper function that takes two unsigned integers and returns the maximum of the two. The private keyword specifies that this function can only be called from within the contract.

The lcs function first checks if the result for the input strings is already stored in the cache mapping. If it is, the function returns the cached result. If the result is not in the cache, the function calculates the result using the standard recursive definition of the LCS problem and stores the result in the cache before returning it.
@priyda priyda requested a review from mkubdev as a code owner January 7, 2023 03:58
Copy link
Member

@mkubdev mkubdev left a comment

Choose a reason for hiding this comment

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

LGTM, the foundry test is missing but let's add it later.

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.

2 participants