June 2007
29 posts
From time to time when i get bored i play a bit with Topcoder is a fun way to get better in solving problems. I decide to make approaches in different progarmming languages, above i post the problem statement and the solution i made in Ruby/Java, enjoy.
Problem Statement, SRM 355 div 2, 250 points:
In Russia, the Value Added Tax is 18% for almost all goods, with the exception of certain food items, which have a Value Added Tax of only 10%.
You are given a String product, the name of a product, and an int price, the price of the product before tax. You are also given a String[] food, each element of which is the name of a food product. If the given product is an element in food, it is a food item (and thus subject to 10% tax), and otherwise, it is a non-food item (and thus subject to 18% tax). Return the price of the product after tax has been added.
Java aprroach
public class ValueAddedTax {
public double calculateFinalPrice(String product, int price, String[] food) {
double res = 0.0;
for ( int i = 0; i if ( food[i].equals(product) ) {
res = (double)(price*0.10)+price;
break;
}
else
res = (double)(price*0.18)+price;
}
return res;
}
}
Ruby approach
class ValueAddedTax
def calculateFinalPrice(product, price, food)
food.each do |f|
if f == product then
res = (price*0.10)+price
return res
end
end
res = (price*0.18)+price
return res
end
end
I think is time for making a change for this tumblelog, in a deeper tech way. I just want to get better in whatever thing i do concerning my carrier. That’s why i will begin with writting things about programming PHP/Java/Ruby are in my thoughts this days so i will begin with that. I was thinking in posting cool things about Tumblr too, when i find them of course.
So stay tune :-)