Il faut que j echange la position de 2 valeur d une liste

Bonjour,je suis en licence informatique et j ai une fonction que je comprend ce qu elle fait mais j arrive pas a l ecrire ,il faut je switch entre 2 valeur d une liste , on peut donner n importe quel indice qui va switch avec l indice 0 exemple: [1;2;3;4] 3 donc la valeur de l indice 3 qui est 4 va switch avec la valeur de l indice 0 qui donne [4;2;3;1]

1 Like

Est-ce que c’est une question de transposer une valeur d’une liste ? Dans ce cas-là je me servirais de la fonction List.mapi, cela vous permettrez de récréer la liste avec l’indice donnée pour chaque élément en vous servant d’une fonction plutôt simple.

Avec ce genre de problème il est plus utile d’une point de vue pédagogique à mon avis de tenter de l’écrire vous même donc je vous laisse avec ce conseil en espérant que cela vous met sur la bonne piste.

il faut juste que la fonction me permet d echanger 1ere valeur de la liste avec la valeur de l indice qu on souhaite [1;2;3;4] la premier valeur est 1 et si par exemple on choisit 3 donc [1;2;3;4] 3 alors le 1 va etre echanger avec l indice 3 qui est 4 qui va nous donner [4;2;3;1]
et j ai le droit de rappeler une seul fois la fonction concate de tri comptage

  1. Ecrire une fonction retourner_spatule : a’ list → int → a’ int
    retourner_spatule l i renvoie la liste l,dans laquelle les crêpes située a la spatule (donc de l indice 0 à l indice i inclus) ont été retournées.
    Vous avez le droit d appeler la fonction concat du tri comptage ,une seul fois

You could get more help if you post in English :slight_smile:

What did you try to do by yourself? You should make an effort on the quality of your posting btw. It looks like you typed this on your phone and your intent is not very clear or readable.

I think you could find chapter 5 from the book “Ocaml from the very beginning” useful: https://johnwhitington.net/ocamlfromtheverybeginning/split09.html

You can solve this problem without requiring any external functions, just basic Ocaml constructs.

Try to split your problem into multiple functions and write some unit tests to validate pieces of your logic bit by bit.

Hello, I am in computer license and I have a function that I understand what it does but I can not write it, it is necessary I exchange between 2 value of a list, we can give any index that will exchange with the index 0 example: [1;2;3;4] 3 so the value of the index 3 which is 4 will exchange with the value of the index 0 which will exchange with the value of the index 0 which gives [4;2;3;1]
enunciate:
Write a retourner_spatule function: a’ list → int → a’ int
retourner_spatule l i returns the list l, in which the pancakes located at the spatula (therefore from the index 0 to the index i included) have been returned.
You have the right to call the concat function of the sorting count only once