Raggedy, Raggedy
Introduction
This asks you to format monospaced text by splitting it across lines of max length L such that the sum of squares of the difference between the actual line lengths and L is mininal.
Solutions
Idea
Do some basic algebra, and compute the desired result.
Gotchas
be sure to use %.3f to print to three places
Code
Solution - Java
import java.util.*;
public class a {
Scanner in=new Scanner(System.in);
public static void main(String[] args) {
new a().go();
}
private void go() {
while(true){
double te=in.nextDouble(),tr=in.nextDouble();
if(te==0&&tr==0)break;
System.out.printf("%.3f\n", Math.sqrt((1-tr/te*tr/te)));
}
}
}