Skip to main content
ratans6128
May 26, 2023
Solved

Get a list, sorted in increasing order by the last element in each tuple from a given list of non-empty tuples

  • May 26, 2023
  • 7 replies
  • 0 views

Write a program to get a list, sorted in increasing order by the last element

in each tuple from a given list of non-empty tuples.

Input: [(1, 3), (3, 2), (2, 1)]


Output: [(2, 1), (3, 2), (1, 3)]

    Best answer by stefanhelzle0001

    Where do you guys get these assignments from? What is your solution?

    As it is a bit difficult to create list of lists in Appian, I use maps to define the tuples.

    a!localVariables(
      local!tuples: {
        a!map(a: 1, b: 3),
        a!map(a: 3, b: 2),
        a!map(a: 2, b: 1),
      },
      todatasubset(
        a!forEach(
          items: local!tuples,
          expression: a!map(
            tuple: fv!item,
            sort: fv!item.b
          )
        ),
        a!pagingInfo(
          startIndex: 1,
          batchSize: 1000,
          sort: a!sortInfo(
            field: "sort",
            ascending: true
          )
        )
      ).data.tuple
    )

    7 replies

    stefanhelzle0001
    Brainy
    May 26, 2023

    Where do you guys get these assignments from? What is your solution?

    As it is a bit difficult to create list of lists in Appian, I use maps to define the tuples.

    a!localVariables(
      local!tuples: {
        a!map(a: 1, b: 3),
        a!map(a: 3, b: 2),
        a!map(a: 2, b: 1),
      },
      todatasubset(
        a!forEach(
          items: local!tuples,
          expression: a!map(
            tuple: fv!item,
            sort: fv!item.b
          )
        ),
        a!pagingInfo(
          startIndex: 1,
          batchSize: 1000,
          sort: a!sortInfo(
            field: "sort",
            ascending: true
          )
        )
      ).data.tuple
    )

    ratans6128
    May 26, 2023

    Stefan ,  i am just practicing appian and checking whether  complex questions of different languages can be solved in appian or not.

    harshitb6843
    May 26, 2023

    I don't think this is you checking. This is us doing the work for you. Try building the logic on your own or else how do you claim that you are learning? Use chatGPT next time to save everyone's time. 

    davel001150
    May 26, 2023

    Simple answer I would say is that Appian is Turing Complete.  To prove it; do you want to try building a Turing Machine simulator?  That would be the tape with the symbols on it, and you can read symbols, store symbols, write symbols, and move the tape backwards and forwards.  If the Turing Machine works, then it can solve literally anything given enough time and RAM.

    stefanhelzle0001
    Brainy
    May 26, 2023

    Now we are talking! Then we could build the game of live in that turing machine which be itself is turing complete ... you made my day :-)

    davel001150
    May 26, 2023

    Conway's game of life easy in Appian.  Only problem is that it only refreshes every 30 seconds, or you have to furiously mash a button over and over.  So it would be a very slow Conway's game of life.  But that proves Appian is Turing Complete, because it can simulate a Turing Machine, specifically Conway's Game of Life.

    Now, does it have a QUICK way to solve a particular problem?  Answer is generally "yes".