-
Notifications
You must be signed in to change notification settings - Fork 75
feat: added palindrome checker #212
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| target | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| scarb 2.11.3 (15764158b 2025-03-13) | ||
| cairo: 2.11.2 (https://crates.io/crates/cairo-lang-compiler/2.11.2) | ||
| sierra: 1.7.0 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Code generated by scarb DO NOT EDIT. | ||
| version = 1 | ||
|
|
||
| [[package]] | ||
| name = "palindrome" | ||
| version = "0.1.0" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "palindrome" | ||
| version = "0.1.0" | ||
| edition = "2024_07" | ||
|
|
||
| # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
|
|
||
| [dependencies] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Visit https://foundry-rs.github.io/starknet-foundry/appendix/snfoundry-toml.html | ||
| # and https://foundry-rs.github.io/starknet-foundry/projects/configuration.html for more information | ||
|
|
||
| # [sncast.default] # Define a profile name | ||
| # url = "https://free-rpc.nethermind.io/sepolia-juno/v0_7" # Url of the RPC provider | ||
| # accounts-file = "../account-file" # Path to the file with the account data | ||
| # account = "mainuser" # Account from `accounts_file` or default account file that will be used for the transactions | ||
| # keystore = "~/keystore" # Path to the keystore file | ||
| # wait-params = { timeout = 300, retry-interval = 10 } # Wait for submitted transaction parameters | ||
| # block-explorer = "StarkScan" # Block explorer service used to display links to transaction details | ||
| # show-explorer-links = true # Print links pointing to pages with transaction details in the chosen block explorer |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| mod palindrome_checker; |
38 changes: 38 additions & 0 deletions
38
examples/cairo/scripts/palindrome/src/palindrome_checker.cairo
danielcdz marked this conversation as resolved.
Show resolved
Hide resolved
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| fn palindrome_checker(word: ByteArray) -> bool { | ||
|
|
||
| let mut i:u32 = word.len(); | ||
| let mut u:u32 = 0; | ||
| let mut flag:bool = false; | ||
|
|
||
| while i > 0 { | ||
|
|
||
| i -= 1; | ||
|
|
||
| if word.at(u).unwrap() != word.at(i).unwrap() { | ||
| flag = false; | ||
| break; | ||
| }else{ | ||
| flag = true; | ||
| u += 1; | ||
| } | ||
| } | ||
|
|
||
| flag | ||
| } | ||
|
|
||
| fn main(){ | ||
|
|
||
| println!("Palindromes \n"); | ||
| let pal_word_1 = "anna"; | ||
| let pal_word_2 = "dewed"; | ||
| println!("The word {} is palindrome - [{}]",pal_word_1, palindrome_checker(pal_word_1)); | ||
| println!("The word {} is palindrome - [{}]",pal_word_2, palindrome_checker(pal_word_2)); | ||
|
|
||
|
|
||
| println!("\nNot palindromes \n"); | ||
| let pal_word_1 = "taco"; | ||
| let pal_word_2 = "mother"; | ||
| println!("The word {} is not palindrome - [{}]",pal_word_1, palindrome_checker(pal_word_1)); | ||
| println!("The word {} is not palindrome - [{}]",pal_word_2, palindrome_checker(pal_word_2)); | ||
|
|
||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.