Posts Tagged with "String Manipulation"

Project Euler 89: Develop a method to express Roman numerals in minimal form.

Saturday, March 24, 2012


I feared that the problems would become harder and harder, and after solving problem 88 I feared Problem 89 of Project Euler. Luckily for me I was wrong, problem 89 is not that difficult. The problem reads The text file contains one thousand numbers written in valid, but not necessarily minimal, Roman numerals; that is, they are arranged in descending units and obey the subtractive pair rule. Find the number of characters saved by writing each of these in their minimal form.My first thoughts regarding this problem was to make a converter for converting romans to arabic numbers and then a converter the other way as well. However after analyzing the problem a bit more I realized that the number of replacements that we can make is limited since we know that there are no more than 4 consecutive digits and we know that they are ordered unless they are already using the subtractive rule.

Continue reading...

Project Euler 42: How many triangle words does the list of common English words contain?

Sunday, May 15, 2011


Problem 42 of Project Euler presents us with a new string manipulation problem. The problem asks us the following The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are:1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.Most of the code is already written in an earlier problem, so the solution for this problem is about finding an inverse function for the triangle function and apply that to the word sum to see if the word is a triangle number.

Continue reading...

Project Euler 36: Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2

Saturday, April 16, 2011


In Problem 36 of Project Euler we are revisiting palindromic numbers. This time with we need to find numbers which are not only palindromic in base 10 but also in base two, meaning in a binary representation. The problem description readsFind the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.I will take 3 approaches in this post. First I will do like in the solution to problem 4 by making string manipulation to reverse the number and compare it to the original number in both base 2 and 10. The second step I will build a function which can reverse an integer in any base without converting it to a string. The last step will be to generate palindromic numbers, so we only have to check if a number is palindromic in the other base.

Continue reading...

Project Euler 22: What is the total of all the name scores in the file of first names?

Wednesday, January 12, 2011


Given problem 22 of Project Euler which reads What is the total of all the name scores in the file?The way I want to solve this problem, is to split it into three parts Read the input file and turn the data into a manageable data structure Sort the data Sum up and provide the answerSo this post will be split into three parts with most focus on the second part, as that is where the meat is. I will swap the sections a bit, such that I treat section 1 and 3 first to set up the framework. At last I will shortly treat two different sorting algorithms plus the .NET API way for sorting.

Continue reading...
This site uses cookies.