LCS contraction addition in dynamic programming#81
Open
priyda wants to merge 1 commit intoTheAlgorithms:mainfrom
Open
LCS contraction addition in dynamic programming#81priyda wants to merge 1 commit intoTheAlgorithms:mainfrom
priyda wants to merge 1 commit intoTheAlgorithms:mainfrom
Conversation
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.
mkubdev
approved these changes
Jan 25, 2023
Member
mkubdev
left a comment
There was a problem hiding this comment.
LGTM, the foundry test is missing but let's add it later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.