Home > Mobile >  Prolog problems {lists}
Prolog problems {lists}

Time:04-01

I'm having some problems in implementing code in prolog because I find it kind of hard to understand it since I'm habitual to normal coding :(

I have to sort a list of integers but it has to keep the duplicated values. I tried to think of a solution and I would use bubble sort but I don't know how to write it in prolog... If someone can explain the code step by step and to enlighten me I would really appreciate...

And yeah, another problem I have is to sort a list consisting of integers and lists of numbers... I have no idea how to start with this one... For example: [1, 2, [4, 1, 4], 3, 6, [7, 10, 1, 3, 9], 5, [1, 1, 1], 7] needs to output [1, 2, [1, 4, 4], 3, 6, [1, 3, 7, 9, 10], 5, [1, 1, 1], 7].

I tried to write some code but it doesn't work at all and I gave up... I copied something from the internet for the first problem but it doesn't really make sense for me...

CodePudding user response:

Prolog is normal coding

  • Related