import java.math.*; /** A class to obtain the Hebrew language name of an arbitrary precision integer. * <br>This class should support all conceivable BigIntegers, limited only by the length of the name itself. * <br>Note that for numbers >= 10^9 this program uses the short scale and uses the word *billion* for 10^9 instead of *milliard* */ public class HebrewNumberNames{ //Vocabulary private static final String[] feminineVocabulary={"","\u05d0\u05d7\u05ea","\u05e9\u05ea\u05d9\u05dd","\u05e9\u05dc\u05d5\u05e9","\u05d0\u05e8\u05d1\u05e2","\u05d7\u05de\u05e9","\u05e9\u05e9","\u05e9\u05d1\u05e2","\u05e9\u05de\u05d5\u05e0\u05d4","\u05ea\u05e9\u05e2","\u05e2\u05e9\u05e8","\u05d0\u05d7\u05ea \u05e2\u05e9\u05e8\u05d4","\u05e9\u05ea\u05d9\u05dd \u05e2\u05e9\u05e8\u05d4","\u05e9\u05dc\u05d5\u05e9 \u05e2\u05e9\u05e8\u05d4","\u05d0\u05e8\u05d1\u05e2 \u05e2\u05e9\u05e8\u05d4","\u05d7\u05de\u05e9 \u05e2\u05e9\u05e8\u05d4","\u05e9\u05e9 \u05e2\u05e9\u05e8\u05d4","\u05e9\u05d1\u05e2 \u05e2\u05e9\u05e8\u05d4","\u05e9\u05de\u05d5\u05e0\u05d4 \u05e2\u05e9\u05e8\u05d4","\u05ea\u05e9\u05e2 \u05e2\u05e9\u05e8\u05d4"}; private static final String[] masculineVocabulary={"","\u05d0\u05d7\u05d3","\u05e9\u05e0\u05d9\u05dd","\u05e9\u05dc\u05d5\u05e9\u05d4","\u05d0\u05e8\u05d1\u05e2\u05d4","\u05d7\u05de\u05e9\u05d4","\u05e9\u05e9\u05d4","\u05e9\u05d1\u05e2\u05d4","\u05e9\u05de\u05d5\u05e0\u05d4","\u05ea\u05e9\u05e2\u05d4","\u05e2\u05e9\u05e8\u05d4","\u05d0\u05d7\u05d3 \u05e2\u05e9\u05e8","\u05e9\u05e0\u05d9\u05dd \u05e2\u05e9\u05e8","\u05e9\u05dc\u05d5\u05e9\u05d4 \u05e2\u05e9\u05e8","\u05d0\u05e8\u05d1\u05e2\u05d4 \u05e2\u05e9\u05e8","\u05d7\u05de\u05e9\u05d4 \u05e2\u05e9\u05e8","\u05e9\u05e9\u05d4 \u05e2\u05e9\u05e8","\u05e9\u05d1\u05e2\u05d4 \u05e2\u05e9\u05e8","\u05e9\u05de\u05d5\u05e0\u05d4 \u05e2\u05e9\u05e8","\u05ea\u05e9\u05e2\u05d4 \u05e2\u05e9\u05e8"}; private static final String[] intermediateVocabulary={"\u05e2\u05e9\u05e8\u05d9\u05dd","\u05e9\u05dc\u05d5\u05e9\u05d9\u05dd","\u05d0\u05e8\u05d1\u05e2\u05d9\u05dd","\u05d7\u05de\u05d9\u05e9\u05d9\u05dd","\u05e9\u05e9\u05d9\u05dd","\u05e9\u05d1\u05e2\u05d9\u05dd","\u05e9\u05de\u05d5\u05e0\u05d9\u05dd","\u05ea\u05e9\u05e2\u05d9\u05dd","\u05de\u05d0\u05d4","\u05de\u05d0\u05ea\u05d9\u05dd","\u05e9\u05dc\u05d5\u05e9 \u05de\u05d0\u05d5\u05ea","\u05d0\u05e8\u05d1\u05e2 \u05de\u05d0\u05d5\u05ea","\u05d7\u05de\u05e9 \u05de\u05d0\u05d5\u05ea","\u05e9\u05e9 \u05de\u05d0\u05d5\u05ea","\u05e9\u05d1\u05e2 \u05de\u05d0\u05d5\u05ea","\u05e9\u05de\u05d5\u05e0\u05d4 \u05de\u05d0\u05d5\u05ea","\u05ea\u05e9\u05e2 \u05de\u05d0\u05d5\u05ea"}; private static final String[] largeVocabulary={"","\u05d0\u05dc\u05e3","\u05de\u05d9\u05dc\u05d9\u05d5\u05df","\u05d1\u05d9\u05dc\u05d9\u05d5\u05df","\u05d8\u05e8\u05d9\u05dc\u05d9\u05d5\u05df","\u05e7\u05d5\u05d3\u05e8\u05d9\u05dc\u05d9\u05d5\u05df","\u05e7\u05d5\u05d9\u05e0\u05d8\u05d9\u05dc\u05d9\u05d5\u05df","\u05e1\u05e7\u05e1\u05d8\u05d9\u05dc\u05d9\u05d5\u05df","\u05e1\u05e4\u05d8\u05d9\u05dc\u05d9\u05d5\u05df","\u05d0\u05d5\u05e7\u05d8\u05d9\u05dc\u05d9\u05d5\u05df","\u05e0\u05d5\u05e0\u05d9\u05dc\u05d9\u05d5\u05df"}; private static final String[] largeVocabulary0={"","\u05d0\u05e0","\u05d3\u05d5\u05d0\u05d5","\u05d8\u05e8\u05d9","\u05e7\u05d5\u05d8\u05d5\u05d0\u05d5\u05e8","\u05e7\u05d5\u05d9\u05e0","\u05e1\u05e7\u05e1","\u05e1\u05e4\u05d8\u05e0","\u05d0\u05d5\u05e7\u05d8\u05d5","\u05e0\u05d5\u05d1\u05de"}; private static final String[] largeVocabulary1={"","\u05d3\u05e1","\u05d5\u05d9\u05d2\u05d9\u05e0","\u05d8\u05e8\u05d9\u05d2\u05d9\u05e0","\u05e7\u05d5\u05d3\u05e8\u05d2\u05d9\u05e0","\u05e7\u05d5\u05d9\u05e0\u05e7\u05d5\u05d2\u05d9\u05e0","\u05e1\u05e7\u05e1\u05d2\u05d9\u05e0","\u05e1\u05e4\u05d8\u05d5\u05d0\u05d2\u05d9\u05e0","\u05d0\u05d5\u05e7\u05d8\u05d5\u05d2\u05d9\u05e0","\u05e0\u05d5\u05e0\u05d2\u05d9\u05e0"}; private static final String[] largeVocabulary2={"","\u05e1\u05e0","\u05d3\u05d5\u05d0\u05d5\u05e1\u05e0","\u05d8\u05e8\u05d9\u05e1\u05e0","\u05e7\u05d5\u05d3\u05e8\u05d9\u05e0\u05d2\u05e0","\u05e7\u05d5\u05d9\u05e0\u05d2\u05e0","\u05e1\u05e1\u05e0","\u05e1\u05e4\u05d8\u05d9\u05e0\u05d2\u05e0","\u05d0\u05d5\u05e7\u05d8\u05d9\u05e0\u05d2\u05e0","\u05e0\u05d5\u05e0\u05d2\u05e0"}; //Returns the letter Vav (u05d5) if v is true, otherwise returns the empty String private static String condVav(boolean v){ return v?"\u05d5":""; } //name of a number from 1 to 999 private static String shortname(int n,String[] smallVocabulary,boolean fin,boolean vav){ n=n%1000; if(!fin){ if(n==1){return "";} else if(n==2){return condVav(vav)+smallVocabulary[2].substring(0,smallVocabulary[2].length()-1);} else{return shortname(n,smallVocabulary,!fin,vav);} } if(n==0){return "";} if(n<20){return condVav(vav)+smallVocabulary[n];} if(n<100){ if(n%10==0){return condVav(vav)+intermediateVocabulary[((n/10)%10)-2];} return intermediateVocabulary[((n/10)%10)-2]+" \u05d5"+smallVocabulary[n%10]; } if(n%100==0){return condVav(vav)+intermediateVocabulary[(n/100)+7];} return intermediateVocabulary[(n/100)+7]+" "+shortname(n%100,smallVocabulary,true,true); } //proper short scale word for 1000^n private static String thousandsPower(long n){ if(n<0){throw new ArithmeticException("negative powers unsupported");} if(n<=10){return largeVocabulary[(int)n];}n--; String pow=""; String millias=""; int suffix=(int)((n/10)%10); while(n>0){ int x=(int)(n%1000); n/=1000; pow=(x==0?"":millias)+pow; pow=largeVocabulary1[(x/10)%10]+pow; if(!(n==0&&x==1)){pow=largeVocabulary0[x%10]+pow;} pow=largeVocabulary2[x/100]+pow; millias+="\u05de\u05d9\u05dc\u05d9\u05d0\u05d4"; } return pow+(suffix==1?"\u05d9\u05dc\u05d9\u05d5\u05df":"\u05d8\u05d9\u05dc\u05d9\u05d5\u05df"); } /** Returns the Hebrew short scale masculine name for the given BigInteger n.*/ public static String masculineName(BigInteger n){ return masculineName(n,0); } /** Returns the Hebrew short scale masculine name for the BigInteger n*1000^off. * <br>This method allows the naming of large numbers without storing the trailing zeroes. */ public static String masculineName(BigInteger n,long off){ return name(n,off,false); } /** Returns the Hebrew short scale name for the given BigInteger n.*/ public static String name(BigInteger n){ return name(n,0); } /** Returns the Hebrew short scale name for the BigInteger n*1000^off. * <br>This method allows the naming of large numbers without storing the trailing zeroes. */ public static String name(BigInteger n,long off){ return name(n,off,true); } //Hebrew Number Name with gender and offset taken into account private static String name(BigInteger n,long off,boolean feminine){ if(off<0){throw new ArithmeticException("negative offset");} if(n.signum()==0){return "\u05d0\u05e4\u05e1";} if(n.signum()==-1){return name(n.negate(),off,feminine)+" \u05e9\u05dc\u05d9\u05dc\u05d9"+(feminine?"\u05ea":"");} int part=0; String s=""; while(n.signum()>0){ part=n.remainder(BigInteger.valueOf(1000)).intValue(); n=n.divide(BigInteger.valueOf(1000)); if(off==1&&part>=2&&part<=10){ if(part==2){s="\u05d0\u05dc\u05e4\u05d9\u05dd"+s;} else if(part==8){s="\u05e9\u05de\u05d5\u05e0\u05ea \u05d0\u05dc\u05e4\u05d9\u05dd"+s;} else{s=feminineVocabulary[part]+"\u05ea \u05d0\u05dc\u05e4\u05d9\u05dd"+s;} } else if(off>0&&part>0){s=(part>1?" ":"")+thousandsPower(off)+s;} if(!(off==1&&part>=2&&part<=10)){s=shortname(part,feminine&&off==0?feminineVocabulary:masculineVocabulary,off==0,n.signum()!=0)+s;} if(n.signum()>0&&part>0){s=" "+s;} off++; } return s; } public static void main(String[] args){ for(int c=0;c<=10000;c++){ String nom=name(BigInteger.valueOf(c)).replace(" ",""); System.out.println(c+" "+nom.length()); } } }