Guest User

Untitled

a guest
Sep 27th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.74 KB | None | 0 0
  1. fun main(args: Array<String>) {
  2.     /*
  3.     re-arrange to key/pairs of original to match target
  4.     make sure no value is assigned to two keys in original at the same time.
  5.  
  6.     You'd start with swapping original[2] with with placeholdingChar, such that placeholdingChar is now 'a'.
  7.     Then you'd lookup 'target' to see at which index 'a' belongs. Then you'd swap the value of that index in
  8.     'original' with 'a', and lookup target to see where that belongs.
  9.  
  10.     Proceed until all values are with their correct key.
  11.     */
  12. }
  13.  
  14. var placeholdingChar = "f"
  15.  
  16. val original = mutableMapOf(1 to "c",
  17.                      2 to "d",
  18.                      3 to "a",
  19.                      4 to "e",
  20.                      5 to "b")
  21.  
  22. val target = mapOf(1 to "a",
  23.                    2 to "b",
  24.                    3 to "c",
  25.                    4 to "d",
  26.                    5 to "e")
Advertisement
Add Comment
Please, Sign In to add comment