Customised Java UTF-16

I have implemented customized encoding mechanism for javaUTF16. Does this implementation support all the characters? public class Encoding { public static void main(String[] args) { byte [] arr = new byte[1000]; String str = “abcde” ; //even this encoding works supplementary characters Encode(arr,0,str); System.out.println(Decode(arr,str.length())); } public static byte[] Encode(byte[] ByteArray , int offset ,String str) … Read more

K&R Exercise 3-3: Expand Shorthand Notations (e.g. a-d to abcd)

The following code is my answer for exercise 3-3 in K&R: #include <stdio.h> #include <ctype.h> #define MAXLINE 1000 /* maximum output line size */ int my_getline(char s[], int lim); void expand(char s1[], char s2[]); /* Exercise 3-3. Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete … Read more

C code to parse out certain characters in a string

I have the following code int eval(char* string) { char* token; outputString[0] = NULL; token = strtok(string, ” “); while(token != NULL){ if(strstr((char *) token, “@”) != NULL) { strcat(outputString, “@”); token = calc(token); } strcat(outputString, token); strcat(outputString, ” “); token = strtok(NULL, ” “); } printf(“%s\n”, outputString); } It is called on a string … Read more

Parsing n lines to count vowels – HackerEarth

I have written a haskell program for the following ‘Code Monk’ Challenge at HackerEarth. Here is the challenge description. Basically, we are looking for the number of vowels in a string. The first input n is the number of string to parse, followed by n number of random strings. And here is my implementation: import … Read more

A Trie data structure in Java

this is the first time I’ implementing a Trie. My goal was to make it as simple as possible. So here is the result: Can I simplify anything else? Are there some things I can change to increase performance ? Also any feedback on code quality/design is welcome 🙂 package trie; public class Node … Read more

Weighted Uniform Strings

Problem Adapted from this HackerRank problem. Instead of printing YES or NO, I just want to return the Set of all possible weights for an input String. I found this example to be illustrative Implementation Some of my thoughts are in the implementation as comments import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class … Read more

Solution to itoa

As some of you might know I’ve been working my way through the C Programming Language (2nd). I recently finished a rough implementation of the itoa exercise (chapter 3). It’s important to note that we haven’t been introduced to any advanced subjects like pointers, dynamic arrays etc yet. The exercise is to create a string … Read more

Unicode Conversions

This is the implementation I’ve been using to convert between unicode strings for a while. I basically pieced it together from information off the internet, including finding a work around for the bug in the Microsoft Visual C++ standard libraries of certain versions. I’ve really only been using the UTF-8 and UTF-32 conversions, so the … Read more