Sud91

Untitled

Feb 13th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. def cupid(s1 : String, s2:String) : Int = {
  2. val s1Arr = s1.toCharArray()
  3. val s2Arr = s2.toCharArray()
  4.  
  5. def secretAlgo(chars1 : Array[Char],chars2 : Array[Char]) : Int = {
  6. var value = 0
  7. var array = new ListBuffer[Char]
  8. for(i <- 0 to chars1.length-1) {
  9. for(j <- 0 to chars2.length-2) {
  10. if(chars1(i) == chars2(j)) {
  11. array += chars1(i)
  12. }
  13. }
  14. }
  15.  
  16. if(array.length > 0 ) {
  17. for(c <- array) {
  18. value = value + c.toInt
  19. }
  20. }
  21. else {
  22. for(c <- chars1) {
  23. value = value + c.toInt
  24. }
  25. for(c <- chars2) {
  26. value = value + c.toInt
  27. }
  28. }
  29. if(value > 100) {
  30. value = secondSecretAlgo(value)
  31. }
  32.  
  33. value
  34. }
  35. def secondSecretAlgo(sum : Int) : Int = {
  36. sum match {
  37. case sum if(sum > 100) => {
  38. val res = (sum/(s1.length()+s2.length())) *2
  39. if(res > 100) secondSecretAlgo(res) else res
  40. }
  41. case _ => sum
  42. }
  43. }
  44.  
  45. val res = secretAlgo(s1Arr,s2Arr)
  46. var love = 0
  47. if(res < 10) {
  48. love = res * (s1.length()+s2.length())
  49. if(love > 100) {
  50. love = secondSecretAlgo(love)
  51. if(love < 10) {
  52. love = Math.pow(love.toDouble, 3.0).toInt
  53. }
  54. }
  55. }
  56. else {
  57. love = res
  58. }
  59. love
  60. }
Add Comment
Please, Sign In to add comment