Skip to content

Commit

Permalink
added code
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptonean committed Oct 2, 2024
1 parent da0d642 commit 916767c
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions validators/not_so_basic.ak
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use aiken/collection/list
use aiken/option
use aiken/primitive/int
use aiken/primitive/bytearray

type FixedP =
Pair<Int, Int>
Expand Down Expand Up @@ -199,4 +200,98 @@ fn check_datum(dat:The_datum)->Bool{

test check_datum_test(){
check_datum(The_datum{datum:Some(15)}) == True
}
// fn palindrome(input: ByteArray) -> Bool {
// let len = bytearray.length(input)
// if bytearray.length(input) <= 1 {
// True
// } else if bytearray.at(input, 0) == bytearray.at(input, len - 1) {
// palindrome(bytearray.slice(input, start: 1, end: len - 2))
// } else {
// False
// }
// }

// test palindrome_test() {
// palindrome("rahar") == True && palindrome("rahat") == False
// }

// fn count_vowels(x){
// let vowel = ["a","e","i","o","u"]
// if list.has(x,vowel){
// True}
// else{
// False
// }
// }

// test count_vowels_test(){
// count_vowels([["faizan"]]) == True
// }

// fn count_vowels1(x:ByteArray){
// let i =2
// let vovel = ["a","e","i","o","u"]
// let found = bytearray.take(x,i)
// if list.has(vovel,found){
// True
// }else{
// False
// }
// }

// test count_vowels1_test(){
// count_vowels1("Faizan") == True
// }
// //else if bytearray.at(input, 0) == bytearray.at(input, len - 1) {
// // palindrome(bytearray.slice(input, start: 1, end: len - 2))
// fn count_vowels2(x){
// let vovel = "aeiou"
// let len = bytearray.length(x)
// if bytearray.at(x,1) == bytearray.at(vovel,0){
// True
// }else{
// False
// }
// }

// test count_vowels2_test(){
// count_vowels2("faizan")== True
// }

const vowels = "aeiouAEIOU"

fn count_vowels3(x: ByteArray) -> Int {
bytearray.foldl(x, 0, fn (byte, acc) {
if bytearray.index_of(vowels, bytearray.from_int_big_endian(byte, 1)) != None {
acc + 1
} else {
acc
}
})
}

test count_vowels_test3() {
count_vowels3("faizan") == 3
}

fn count_vowel(string: ByteArray, n: Int) -> Int {
let vowel_list = "aeiouAEIOU"
when bytearray.is_empty(string) is {
True -> n
False ->
if bytearray.index_of(vowel_list, bytearray.take(string, 1)) == None {
count_vowel(bytearray.drop(string, 1), n)
} else {
count_vowel(bytearray.drop(string, 1), n + 1)
}
}
}

fn count_v(string: ByteArray) -> Int {
count_vowel(string, 0)
}

test count_vowel_check() {
count_v("faizan") == 3
}

0 comments on commit 916767c

Please sign in to comment.