calcme = '93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx'
total = 0
position = 0
strlen = len(calcme)
while position < strlen:
if calcme[position] != 'x':
total = total + int(calcme[position])
position = position + 1
elif calcme[position] == 'x':
calcme = calcme.replace('x', '', 1)
position = position - 2
strlen = len(calcme)
print total
~~~~
note: i'm not necessarily a mad hacker, i'ts my screen name
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
// parse String and replace x with Integer.MIN_VALUE
String s ="93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx";
for (int i=0; i< s.length(); i++) {
String sub = s.substring(i, i+1);
if (sub.equals("x")) {
list.add(Integer.MIN_VALUE);
} else {
list.add(Integer.valueOf(sub));
}
}
int count = 0;
for (int i = 0; i< list.size(); i++) {
if (list.get(i)!= Integer.MIN_VALUE){
count += list.get(i);
} else {
list.remove(i);
i -=3;
}
}
System.out.println(count);
}
public final class QuickSolver {
/**
* @param args
*/
public static void main(String[] args) {
StringBuilder sumtext = new StringBuilder("93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx");
int sum = 0;
for (int i = 0; i < sumtext.length(); i++) {
if (sumtext.charAt(i) == 'x') {
sumtext.deleteCharAt(i);
i -= 3;
}
else
sum += Integer.parseInt(String.valueOf(sumtext.charAt(i)));
}
System.out.println(sum);
}
}
String text = "93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx";
ArrayList<Character> neu = new ArrayList<Character>();
int i = 0;
char j;
for (int a = 0; a < text.length(); a++) {
neu.add(text.charAt(a));
}
int a = 0;
int b = neu.size();
while (a < b) {
if (neu.get(a) == 'x') {
neu.remove(a);
b--;
a--;
a--;
} else {
j = neu.get(a);
i = i + Character.getNumericValue(j);
a++;
}
}
v=i=0;s=list("93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx")
while i<len(s):
if s[i].isdigit(): v += int(s[i]);i += 1;
else: del s[i];i -= 2
print v
Not quite a single line of Perl but does the trick
string="93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx"
sum,tb,ob = 0
string.each_char {|d|
if d!="x"
tb,ob = ob,d.to_i
sum += d.to_i
else
sum += tb+ob
end
}
puts sum
calcValue x = calcValue' ("00"++x)
where
calcValue' (a:b:x:xs) =
if x == 'x'
then (calcValue' (a:b:xs))+read([a])+read([b])
else
(calcValue' (b:x:xs))+read([x])
calcValue' _ = 0
I'm quite new to haskell, so this solution is probably far from perfect...
(oh, and I'm indeed very creative about names XD)