Page 2 of 2

Posted: Tue Jun 28, 2011 1:24 pm
by moose
A little knowledge of math and a little python:

Code: Select all

summe = (2118**2 + 2118)/2
for i in xrange(1, 47):
    summe += i**2
print summe

Posted: Tue Feb 14, 2012 7:59 am
by Taurath
Mine in Ruby (which I learned today, be gentle) :P

Code: Select all

x = 0
y = 1
while y < 2119 do
	x = x + y
	#machine to check if whole number
	def whole?(x)
		(x - x.floor) == 0
		end
	z = Math.sqrt(y)
	if whole?(z) == true
		x = x + y
		end
	y = y + 1
	end
puts x

Posted: Tue Aug 14, 2018 10:27 am
by th4wri
java solution using regex :p

Code: Select all

package hacker.org;

import java.util.regex.Pattern;

public class Delegates {

	public static void main(String[] args) {

		int sum = 0;
		for(int i=1; i<=2118; i++) {
			if(Pattern.compile("(.0)$").matcher(Double.toString(Math.sqrt(i))).find()) {
				System.out.println(i); //for me hh
				sum += 2*i;
			}
			else sum += i;
		}
		
		System.out.println("Sum : " + sum);
		
	}

}
Result :
1
4
9
16
25
36
49
64
81
100
121
144
169
196
225
256
289
324
361
400
441
484
529
576
625
676
729
784
841
900
961
1024
1089
1156
1225
1296
1369
1444
1521
1600
1681
1764
1849
1936
2025
2116
Sum : 2277532