Advertisement
kimi19

common_letter.gs

Nov 30th, 2016
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Genie 1.05 KB | None | 0 0
  1. init
  2.     // get args, declare variables
  3.  
  4.     first:string = args[1]
  5.     second:string = args[2]
  6.     common:bool = false
  7.     first_pos:int = 0
  8.     second_pos:int = 0
  9.  
  10.     first_length:long = first.length - 1
  11.     second_length:long = second.length - 1
  12.  
  13.     var first_list = new array of char[first_length]
  14.     var second_list = new array of char[second_length]
  15.  
  16.     for var i = 0 to first_length
  17.         first_list[i] = (first[i])
  18.  
  19.     for var i = 0 to second_length
  20.         second_list[i] = (second[i])
  21.  
  22.     // compare the words (gets the very first instance of the same char)
  23.  
  24.     for var i = 0 to first_length
  25.         if common
  26.             break
  27.         second_pos = 0
  28.         first_pos++
  29.  
  30.         for var j = 0 to second_length
  31.             second_pos++
  32.             if first_list[i] == second_list[j]
  33.                 common = true
  34.                 break
  35.  
  36.     // print values
  37.     if common
  38.         var first_final = (string)first_list
  39.         var second_final = (string)second_list
  40.  
  41.         print first_final.substring(0, first_pos) + second_final.substring(second_pos) + "-" + second_final.substring(0, second_pos) + first_final.substring(first_pos)
  42.     else
  43.         print first + "-" + second
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement