Timeline for Find the simplest value between two values
Current License: CC BY-SA 3.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 2, 2014 at 11:19 | history | edited | Stretch Maniac | CC BY-SA 3.0 |
deleted 15 characters in body
|
Oct 2, 2014 at 6:00 | comment | added | Justin |
186 chars: void f(float a,float b){for(float i=1,d;;i*=2){for(d=0;d<i*Math.max(Math.abs(b),Math.abs(a));d++){for(float x:new float[]{d/i,-d/i}){if(x<b&&x>a){System.out.print(x);System.exit(0);}}}}} . Avoiding importing saves it, and you would have needed the static imports. The stuff in the java.lang package are automatically "imported"
|
|
Oct 2, 2014 at 2:37 | comment | added | Stretch Maniac | @feersum you probably aren't patient enough :) | |
Oct 2, 2014 at 2:37 | history | edited | Stretch Maniac | CC BY-SA 3.0 |
added 11 characters in body
|
Oct 2, 2014 at 1:49 | comment | added | xnor | @ypnypn This is an issue that comes in Java in that you can't do imports without wrapping the function in a class. Here's what I say: You can have a "floating" import statement separate from the function, but the chars in the import statement count, including a char for newline. So this is 189 chars. | |
Oct 2, 2014 at 1:46 | comment | added | xnor | I edited the rules to not worry about precision or representation issues. Floats are fine. | |
Oct 2, 2014 at 1:07 | comment | added | feersum |
This doesn't work for large values either. E.g. if I call f((float)1e30, (float)1e31) it appears to go into an infinite loop. Or was I just not patient enough?
|
|
Oct 2, 2014 at 0:07 | comment | added | Ypnypn | I don't think imports are free. | |
Oct 1, 2014 at 23:15 | history | edited | Stretch Maniac | CC BY-SA 3.0 |
added 109 characters in body
|
Oct 1, 2014 at 22:30 | history | answered | Stretch Maniac | CC BY-SA 3.0 |