Skip to main content
Commonmark migration
Source Link

#Java 8, 158 154 bytes

Java 8, 158 154 bytes

interface M{static void main(String[]a){int i=a[0].length()-2;System.out.println(a[0].substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+a[0].substring(i));}}

Try it here.

EDIT: Only now reading program instead of the default function/program in the challenge description.. So added the bordercode with interface and main method.

If a function would be allowed it would be (99 95 bytes)

s->{int i=s.length()-2;return s.substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+s.substring(i);}

Try it here.

Explanation:

s->{                        // Method with String as both parameter and return-type
  int i=s.length()-2;       //  The length of the input - 2
  return s.substring(0,i=1  //  Return the first part of the input from index 0 to 1
    +(i*=Math.random()))    //    + a random integer between 0 and length-2
   +" ~BOO!~ "              //   appended with the literal " ~BOO!~ "
   +s.substring(i);         //   appended with the rest of the input-String
}                           // End of method

#Java 8, 158 154 bytes

interface M{static void main(String[]a){int i=a[0].length()-2;System.out.println(a[0].substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+a[0].substring(i));}}

Try it here.

EDIT: Only now reading program instead of the default function/program in the challenge description.. So added the bordercode with interface and main method.

If a function would be allowed it would be (99 95 bytes)

s->{int i=s.length()-2;return s.substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+s.substring(i);}

Try it here.

Explanation:

s->{                        // Method with String as both parameter and return-type
  int i=s.length()-2;       //  The length of the input - 2
  return s.substring(0,i=1  //  Return the first part of the input from index 0 to 1
    +(i*=Math.random()))    //    + a random integer between 0 and length-2
   +" ~BOO!~ "              //   appended with the literal " ~BOO!~ "
   +s.substring(i);         //   appended with the rest of the input-String
}                           // End of method

Java 8, 158 154 bytes

interface M{static void main(String[]a){int i=a[0].length()-2;System.out.println(a[0].substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+a[0].substring(i));}}

Try it here.

EDIT: Only now reading program instead of the default function/program in the challenge description.. So added the bordercode with interface and main method.

If a function would be allowed it would be (99 95 bytes)

s->{int i=s.length()-2;return s.substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+s.substring(i);}

Try it here.

Explanation:

s->{                        // Method with String as both parameter and return-type
  int i=s.length()-2;       //  The length of the input - 2
  return s.substring(0,i=1  //  Return the first part of the input from index 0 to 1
    +(i*=Math.random()))    //    + a random integer between 0 and length-2
   +" ~BOO!~ "              //   appended with the literal " ~BOO!~ "
   +s.substring(i);         //   appended with the rest of the input-String
}                           // End of method
added 637 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 8, 99158 95154 bytes

interface M{static void main(String[]a){int i=a[0].length()-2;System.out.println(a[0].substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+a[0].substring(i));}}

Try it here.

EDIT: Only now reading program instead of the default function/program in the challenge description.. So added the bordercode with interface and main method.

If a function would be allowed it would be (99 95 bytes)

s->{int i=s.length()-2;return s.substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+s.substring(i);}

Explanation:

Try it here.

Explanation:

s->{                        // Method with String as both parameter and return-type
  int i=s.length()-2;       //  The length of the input - 2
  return s.substring(0,i=1  //  Return the first part of the input from index 0 to 1
    +(i*=Math.random()))    //    + a random integer between 0 and length-2
   +" ~BOO!~ "              //   appended with the literal " ~BOO!~ "
   +s.substring(i);         //   appended with the rest of the input-String
}                           // End of method

#Java 8, 99 95 bytes

s->{int i=s.length()-2;return s.substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+s.substring(i);}

Explanation:

Try it here.

s->{                       // Method with String as both parameter and return-type
  int i=s.length()-2;      //  The length of the input - 2
  return s.substring(0,i=1 //  Return the first part of the input from index 0 to 1
    +(i*=Math.random()))   //    + a random integer between 0 and length-2
   +" ~BOO!~ "             //   appended with the literal " ~BOO!~ "
   +s.substring(i);        //   appended with the rest of the input-String
}                          // End of method

#Java 8, 158 154 bytes

interface M{static void main(String[]a){int i=a[0].length()-2;System.out.println(a[0].substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+a[0].substring(i));}}

Try it here.

EDIT: Only now reading program instead of the default function/program in the challenge description.. So added the bordercode with interface and main method.

If a function would be allowed it would be (99 95 bytes)

s->{int i=s.length()-2;return s.substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+s.substring(i);}

Try it here.

Explanation:

s->{                        // Method with String as both parameter and return-type
  int i=s.length()-2;       //  The length of the input - 2
  return s.substring(0,i=1  //  Return the first part of the input from index 0 to 1
    +(i*=Math.random()))    //    + a random integer between 0 and length-2
   +" ~BOO!~ "              //   appended with the literal " ~BOO!~ "
   +s.substring(i);         //   appended with the rest of the input-String
}                           // End of method
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 8, 99 95 bytes

s->{int i=s.length()-2;return s.substring(0,i=1+(i*=Math.random()))+" ~BOO!~ "+s.substring(i);}

Explanation:

Try it here.

s->{                       // Method with String as both parameter and return-type
  int i=s.length()-2;      //  The length of the input - 2
  return s.substring(0,i=1 //  Return the first part of the input from index 0 to 1
    +(i*=Math.random()))   //    + a random integer between 0 and length-2
   +" ~BOO!~ "             //   appended with the literal " ~BOO!~ "
   +s.substring(i);        //   appended with the rest of the input-String
}                          // End of method