Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. def prog (char c, list l) {
  2. prog_helper(c, l, 0, [])
  3. }
  4.  
  5. def prog_helper (char c, list l, int pos) {
  6. if(pos>=l.size) {
  7. break;
  8. }
  9.  
  10. if(l.get(pos) is list) {
  11. // for every returned list, create 1 entry in result
  12. printCombination(prog_helper_sublist(c, l.get(pos), 0, []), l, pos)
  13. } else {
  14. // If the character to insert and the character in the list with the given position is the same, SKIP since it will be duplicate of the next one
  15. if(c != l.get(pos)) {
  16. print(c, l, pos)
  17. }
  18. }
  19.  
  20. prog_helper (c, l, pos+1, result)
  21. }
  22.  
  23.  
  24. def prog_helper_sublist (char c, list subL, int pos, list result) {
  25. if(pos>=l.size) {
  26. return result;
  27. }
  28.  
  29. if(l.get(pos) is list) {
  30. result.appendLists(prog_helper_sublist(c, l.get(pos), 0, []), pos)
  31. } else {
  32. // If the character to insert and the character in the list with the given position is the same, SKIP since it will be duplicate of the next one
  33. if(c != l.get(pos)) {
  34. result.append(c, l, pos);
  35. }
  36. }
  37.  
  38. prog_helper_sublist(c, subL, pos+1, result)
  39. }
  40.  
  41. def printCombination(list insertedSubList, list original, int pos) {
  42. // print original with element in pos replaced with insertedSubList
  43. }
  44.  
  45. def print(char c, list original, int pos) {
  46. // print original with c inserted in position pos
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement