Skip to main content
Commonmark migration
Source Link

#Java 10, 44 bytes

Java 10, 44 bytes

f->b->{int r=1;for(;b>0;b-=f)r*=b;return r;} 

Takes the factorial as first input, base as second.

Try it online.

This above doesn't work for the largest test case due to the limited integer range (32-bits). To fix this we can use BigIntegers, which coincidentally is exactly double the size - 88 79 bytes:

f->b->{var r=f.ONE;for(;b.signum()>0;b=b.subtract(f))r=r.multiply(b);return r;} 

-9 bytes thanks to @OlivierGrégoire.

Try it online.

Explanation:

f->b->{ // Method with two integer parameters and integer return-type int r=1; // Result-integer, starting at 1 for(;b>0; // Loop as long as the base is still larger than 0 b-=f) // After every iteration: decrease the base by the factorial r*=b; // Multiply the result by the base return r;} // Return the result 

#Java 10, 44 bytes

f->b->{int r=1;for(;b>0;b-=f)r*=b;return r;} 

Takes the factorial as first input, base as second.

Try it online.

This above doesn't work for the largest test case due to the limited integer range (32-bits). To fix this we can use BigIntegers, which coincidentally is exactly double the size - 88 79 bytes:

f->b->{var r=f.ONE;for(;b.signum()>0;b=b.subtract(f))r=r.multiply(b);return r;} 

-9 bytes thanks to @OlivierGrégoire.

Try it online.

Explanation:

f->b->{ // Method with two integer parameters and integer return-type int r=1; // Result-integer, starting at 1 for(;b>0; // Loop as long as the base is still larger than 0 b-=f) // After every iteration: decrease the base by the factorial r*=b; // Multiply the result by the base return r;} // Return the result 

Java 10, 44 bytes

f->b->{int r=1;for(;b>0;b-=f)r*=b;return r;} 

Takes the factorial as first input, base as second.

Try it online.

This above doesn't work for the largest test case due to the limited integer range (32-bits). To fix this we can use BigIntegers, which coincidentally is exactly double the size - 88 79 bytes:

f->b->{var r=f.ONE;for(;b.signum()>0;b=b.subtract(f))r=r.multiply(b);return r;} 

-9 bytes thanks to @OlivierGrégoire.

Try it online.

Explanation:

f->b->{ // Method with two integer parameters and integer return-type int r=1; // Result-integer, starting at 1 for(;b>0; // Loop as long as the base is still larger than 0 b-=f) // After every iteration: decrease the base by the factorial r*=b; // Multiply the result by the base return r;} // Return the result 
added 37 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Java 10, 44 bytes

f->b->{int r=1;for(;b>0;b-=f)r*=b;return r;} 

Takes the factorial as first input, base as second.

Try it online.

This above doesn't work for the largest test case due to the limited integer range (32-bits). To fix this we can use BigIntegers, which coincidentallycoincidentally is exactly double the size (88exactly double the size - 88 79 bytes):

f->b->{var r=f.ONE;for(;b.compareTosignum(f.ZERO)>0;b=b.subtract(f))r=r.multiply(b);return r;} 

Try it online.-9 bytes thanks to @OlivierGrégoire.

Try it online.

Explanation:

f->b->{ // Method with two integer parameters and integer return-type int r=1; // Result-integer, starting at 1 for(;b>0; // Loop as long as the base is still larger than 0 b-=f) // After every iteration: decrease the base by the factorial r*=b; // Multiply the result by the base return r;} // Return the result 

#Java 10, 44 bytes

f->b->{int r=1;for(;b>0;b-=f)r*=b;return r;} 

Takes the factorial as first input, base as second.

Try it online.

This above doesn't work for the largest test case due to the limited integer range (32-bits). To fix this we can use BigIntegers, which coincidentally is exactly double the size (88 bytes):

f->b->{var r=f.ONE;for(;b.compareTo(f.ZERO)>0;b=b.subtract(f))r=r.multiply(b);return r;} 

Try it online.

Explanation:

f->b->{ // Method with two integer parameters and integer return-type int r=1; // Result-integer, starting at 1 for(;b>0; // Loop as long as the base is still larger than 0 b-=f) // After every iteration: decrease the base by the factorial r*=b; // Multiply the result by the base return r;} // Return the result 

#Java 10, 44 bytes

f->b->{int r=1;for(;b>0;b-=f)r*=b;return r;} 

Takes the factorial as first input, base as second.

Try it online.

This above doesn't work for the largest test case due to the limited integer range (32-bits). To fix this we can use BigIntegers, which coincidentally is exactly double the size - 88 79 bytes:

f->b->{var r=f.ONE;for(;b.signum()>0;b=b.subtract(f))r=r.multiply(b);return r;} 

-9 bytes thanks to @OlivierGrégoire.

Try it online.

Explanation:

f->b->{ // Method with two integer parameters and integer return-type int r=1; // Result-integer, starting at 1 for(;b>0; // Loop as long as the base is still larger than 0 b-=f) // After every iteration: decrease the base by the factorial r*=b; // Multiply the result by the base return r;} // Return the result 
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Java 10, 44 bytes

f->b->{int r=1;for(;b>0;b-=f)r*=b;return r;} 

Takes the factorial as first input, base as second.

Try it online.

This above doesn't work for the largest test case due to the limited integer range (32-bits). To fix this we can use BigIntegers, which coincidentally is exactly double the size (88 bytes):

f->b->{var r=f.ONE;for(;b.compareTo(f.ZERO)>0;b=b.subtract(f))r=r.multiply(b);return r;} 

Try it online.

Explanation:

f->b->{ // Method with two integer parameters and integer return-type int r=1; // Result-integer, starting at 1 for(;b>0; // Loop as long as the base is still larger than 0 b-=f) // After every iteration: decrease the base by the factorial r*=b; // Multiply the result by the base return r;} // Return the result