Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/cairo/scripts/palindrome/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target

6 changes: 6 additions & 0 deletions examples/cairo/scripts/palindrome/Scarb.lock
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"
8 changes: 8 additions & 0 deletions examples/cairo/scripts/palindrome/Scarb.toml
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]
11 changes: 11 additions & 0 deletions examples/cairo/scripts/palindrome/snfoundry.toml
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
1 change: 1 addition & 0 deletions examples/cairo/scripts/palindrome/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod palindrome_checker;
38 changes: 38 additions & 0 deletions examples/cairo/scripts/palindrome/src/palindrome_checker.cairo
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));

}