Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cupid(s1 : String, s2:String) : Int = {
- val s1Arr = s1.toCharArray()
- val s2Arr = s2.toCharArray()
- def secretAlgo(chars1 : Array[Char],chars2 : Array[Char]) : Int = {
- var value = 0
- var array = new ListBuffer[Char]
- for(i <- 0 to chars1.length-1) {
- for(j <- 0 to chars2.length-2) {
- if(chars1(i) == chars2(j)) {
- array += chars1(i)
- }
- }
- }
- if(array.length > 0 ) {
- for(c <- array) {
- value = value + c.toInt
- }
- }
- else {
- for(c <- chars1) {
- value = value + c.toInt
- }
- for(c <- chars2) {
- value = value + c.toInt
- }
- }
- if(value > 100) {
- value = secondSecretAlgo(value)
- }
- value
- }
- def secondSecretAlgo(sum : Int) : Int = {
- sum match {
- case sum if(sum > 100) => {
- val res = (sum/(s1.length()+s2.length())) *2
- if(res > 100) secondSecretAlgo(res) else res
- }
- case _ => sum
- }
- }
- val res = secretAlgo(s1Arr,s2Arr)
- var love = 0
- if(res < 10) {
- love = res * (s1.length()+s2.length())
- if(love > 100) {
- love = secondSecretAlgo(love)
- if(love < 10) {
- love = Math.pow(love.toDouble, 3.0).toInt
- }
- }
- }
- else {
- love = res
- }
- love
- }
Add Comment
Please, Sign In to add comment