Saturday, September 19, 2020

Writing Odia in LaTeX

Finally I was able to write Odia letters in LaTeX. I tried polyglossia but somehow couldn't make it work. Then I succeeded with the fontspec package. It came out to be simpler than all the complex indic examples found in web. Here is the document. 

 Note: Odia unicode font file kalinga.ttf must be present in C:\Windows\Fonts folder. PdfLatex wont work, One must use XeLatex to compile the document

\documentclass{article}
\usepackage{fontspec}
\newfontfamily\oriyafont{kalinga.ttf}
\DeclareTextFontCommand{\textodia}{\oriyafont}
\title{\LaTeX \textodia{ରେ ଓଡ଼ିଆ ଲେଖା}}
\author{\textodia{ସ୍ୱରୁପାନନ୍ଦ ବିଷୟୀ}}
\begin{document}
\date{}
\maketitle
\section{\textodia{ଓଡ଼ିଆ ଉଇକିପିଡ଼ିଆରୁ}}
\textodia{ଓଡ଼ିଆ ଏକ ଭାରତୀୟ ଭାଷା ଯାହା ଏକ ଇଣ୍ଡୋ-ଇଉରୋପୀୟ ଭାଷାଗୋଷ୍ଠୀ ଅନ୍ତର୍ଗତ ଇଣ୍ଡୋ-ଆର୍ଯ୍ୟ ଭାଷା । ଏହା ଭାରତ ଦେଶର ଓଡ଼ିଶା ପ୍ରଦେଶରେ ସର୍ବାଧିକ ବ୍ୟବ‌ହାର କରାଯାଉଥିବା ମୁଖ୍ୟ ସ୍ଥାନୀୟ ଭାଷା ଯାହା ୯୧}.\textodia{୮୫}\% \textodia{ଲୋକ ବ୍ୟବ‌ହର କରନ୍ତି । ଓଡ଼ିଶା ସମେତ ଏହା ପଶ୍ଚିମ ବଙ୍ଗ, ଛତିଶଗଡ଼, ଝାଡ଼ଖଣ୍ଡ, ଆନ୍ଧ୍ର ପ୍ରଦେଶ ଓ ଗୁଜରାଟ (ମୂଳତଃ ସୁରଟ)ରେ କୁହାଯାଇଥାଏ । ଏହା ଓଡ଼ିଶାର ସରକାରୀ ଭାଷା । ଏହା ଭାରତର ସମ୍ବିଧାନ ସ୍ୱିକୃତୀପ୍ରାପ୍ତ ୨୨ଟି ଭାଷା ମଧ୍ୟରୁ ଗୋଟିଏ ଓ ଝାଡ଼ଖଣ୍ଡର ୨ୟ ପ୍ରଶାସନିକ ଭାଷା । ଓଡ଼ିଆ ଷଷ୍ଠ ଭାରତୀୟ ଭାଷା ଭାବରେ ଏକ ସ୍ୱତନ୍ତ୍ର ଓ ଅନ୍ୟ ଭାଷାଦ୍ୱାରା ପ୍ରଭାବିତ ହୋଇ ନ‌ ଥିବା ଭାଷା ଭାବରେ ଶାସ୍ତ୍ରୀୟ ଭାଷାର ମାନ୍ୟତା ପାଇଛି ।}

\end{document}

Friday, August 7, 2020

Divisibility

 One of my friends asked me to come up with a solution for this problem in Java/C#

public int isXDivisibleByY(int x, int y)
{
/* 
The method should meet the following conditions:

1. Method returns 1, if X can   be divided by Y without a remainder
2. Method returns 0, if X can't be divided by Y without a remainder
3. Solution must not include any conditional checks (if condition, equality operators, the ternary and null-coalescing operators etc.)
4. Solution must not include any exception handling (try-catch-finally)
5. It should work all kinds of inputs of x and y
*/
}

Challenges & Solutions

  1. I had failed to notice that there is no straight forward way to cast a boolean to int in Java. This is missing in Java because Java designers (correctly) recognized that the boolean / integer overloading in C and C++ was a significant source of errors. Source (https://stackoverflow.com/questions/16281760/why-doesnt-java-allow-casting-boolean-int). Thank God, there's this weird compareTo method in Boolean.
  2. Without a try-catch-Finally, Handling divide by Zero gracefully is not easy. However a simple cast of float to the divisor is handy. Thanks to the division rules https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17.2


Final Solution by me:

public int isXDivisibleByY(int x, int y )
{
return 1 - Boolean.compare((x%(float)y) > 0, false) ;
}

Well, compare method may use conditionals internally but I guess, this is one possible solution without a visible conditional...

Next thing to try: Applying https://en.wikipedia.org/wiki/Divisibility_rule