Delegates

Discussion of challenges you have already solved
moose
Posts: 67
Joined: Fri Jul 16, 2010 7:32 pm

Post 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
Taurath
Posts: 5
Joined: Mon Feb 06, 2012 7:15 pm

Post 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
th4wri
Posts: 8
Joined: Tue Mar 29, 2016 10:27 am
Location: TuNiSiA

Post 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
Post Reply