Ad
Code
Diff
  • /**
      The output of this kata is the number you need to create the metal sign
      with your fingers, using these rules:
      - You start with all fingers "up"
      - You count from your thumb
      - You put the finger where you end down
      - You start again with your thumb (or the next finger which is up)
      - If your number is not yet reached and you are out of fingers you count on with the "left" side
      - The Metal Sign is Thumb down, Index up, Middle down, Ring down, Pinky up
      - Have fun :-)
      - If you are really fast you can also try with the "Double Metal" (Same with 10 Fingers)
    **/
    
    // Parallell programmed / quick draft with ChatGPT - non-functional yet ^^
    
    function createMetalSign(number) {
      const fingers = [1, 1, 1, 1, 1]; // Initialize all fingers "up"
      let currentFinger = 0; // Start counting from the thumb (index 0)
    
      while (number > 0) {
        if (fingers[currentFinger] === 1) {
          // If the finger is up, put it down
          fingers[currentFinger] = 0;
          number--;
        }
    
        // Move to the next finger
        currentFinger = (currentFinger + 1) % 5;
      }
      console.log(fingers)
      return fingers;
    }
    
    • /**
    • The output of this kata is the number you need to create the metal sign
    • with your fingers, using these rules:
    • - You start with all fingers "up"
    • - You count from your thumb
    • - You put the finger where you end down
    • - You start again with your thumb (or the next finger which is up)
    • - If your number is not yet reached and you are out of fingers you count on with the "left" side
    • - The Metal Sign is Thumb down, Index up, Middle down, Ring down, Pinky up
    • - Have fun :-)
    • - If you are really fast you can also try with the "Double Metal" (Same with 10 Fingers)
    • **/
    • function calculate(){
    • console.log(0);
    • }
    • // Parallell programmed / quick draft with ChatGPT - non-functional yet ^^
    • function createMetalSign(number) {
    • const fingers = [1, 1, 1, 1, 1]; // Initialize all fingers "up"
    • let currentFinger = 0; // Start counting from the thumb (index 0)
    • while (number > 0) {
    • if (fingers[currentFinger] === 1) {
    • // If the finger is up, put it down
    • fingers[currentFinger] = 0;
    • number--;
    • }
    • // Move to the next finger
    • currentFinger = (currentFinger + 1) % 5;
    • }
    • console.log(fingers)
    • return fingers;
    • }