diff --git a/examples/cairo/scripts/palindrome/.gitignore b/examples/cairo/scripts/palindrome/.gitignore new file mode 100644 index 0000000..d913617 --- /dev/null +++ b/examples/cairo/scripts/palindrome/.gitignore @@ -0,0 +1,2 @@ +target + diff --git a/examples/cairo/scripts/palindrome/.tool-versions b/examples/cairo/scripts/palindrome/.tool-versions new file mode 100644 index 0000000..15f5979 --- /dev/null +++ b/examples/cairo/scripts/palindrome/.tool-versions @@ -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 diff --git a/examples/cairo/scripts/palindrome/Scarb.lock b/examples/cairo/scripts/palindrome/Scarb.lock new file mode 100644 index 0000000..94e62d8 --- /dev/null +++ b/examples/cairo/scripts/palindrome/Scarb.lock @@ -0,0 +1,6 @@ +# Code generated by scarb DO NOT EDIT. +version = 1 + +[[package]] +name = "palindrome" +version = "0.1.0" diff --git a/examples/cairo/scripts/palindrome/Scarb.toml b/examples/cairo/scripts/palindrome/Scarb.toml new file mode 100644 index 0000000..edbd504 --- /dev/null +++ b/examples/cairo/scripts/palindrome/Scarb.toml @@ -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] diff --git a/examples/cairo/scripts/palindrome/snfoundry.toml b/examples/cairo/scripts/palindrome/snfoundry.toml new file mode 100644 index 0000000..306a097 --- /dev/null +++ b/examples/cairo/scripts/palindrome/snfoundry.toml @@ -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 diff --git a/examples/cairo/scripts/palindrome/src/lib.cairo b/examples/cairo/scripts/palindrome/src/lib.cairo new file mode 100644 index 0000000..d0248a9 --- /dev/null +++ b/examples/cairo/scripts/palindrome/src/lib.cairo @@ -0,0 +1 @@ +mod palindrome_checker; diff --git a/examples/cairo/scripts/palindrome/src/palindrome_checker.cairo b/examples/cairo/scripts/palindrome/src/palindrome_checker.cairo new file mode 100644 index 0000000..520c2f2 --- /dev/null +++ b/examples/cairo/scripts/palindrome/src/palindrome_checker.cairo @@ -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)); + +}