Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.
pretentious wrote:Welcome to bat country
pretentious wrote:I don't suppose this will involve some kind of recursive algorythm? though dealing with such numbers will probably break the stack
5050505050505050504994949494949494949495
jgr wrote:This was pretty trivial.
- Code: Select all
5050505050505050504994949494949494949495
Tell me it's right and give me my pointz
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
int main (void)
{
int i;
mpz_t n;
mpz_t total;
mpz_t tmp;
mpz_t sum;
mpz_init(n);
mpz_init(total);
mpz_init(tmp);
mpz_init(sum);
mpz_set_ui(n, 9);
mpz_set_ui(total, 0);
for (i = 0; i < 20; i++) {
// (n(n+1)(n+2)) / 6
mpz_add_ui(tmp, n, 1);
mpz_mul(sum, n, tmp);
mpz_add_ui(tmp, n, 2);
mpz_mul(sum, sum, tmp);
mpz_div_ui(sum, sum, 6);
mpz_add(total, total, sum);
mpz_mul_ui(n, n, 10);
mpz_add_ui(n, n, 9);
}
gmp_printf("%Zd\n", total);
mpz_clear(n);
mpz_clear(total);
mpz_clear(tmp);
mpz_clear(sum);
exit(EXIT_SUCCESS);
}
main = print . sum . take 20 . map tetra . iterate ((+ 9) . (* 10)) $ 9
where tetra n = (n * (n + 1) * (n + 2)) `div` 6
#!/usr/bin/ruby
prompt = "> "
puts "Enter the number to iterate:"
print prompt
num = gets.chomp
puts "Enter amount of decimal places:"
print prompt
places = gets.chomp.to_i
def tri(n)
return (n*(n+1)*(n+2)/6)
end
value = 0
while places > 0
number = ''
places.times { number += num }
n = number.to_i
value += tri(n)
places -= 1
end
puts "Answer:"
puts value
#!/usr/bin/ruby
# Find the product of the sum of all triangle numbers up to: 9..n, where n is the decimal value we specify i.e, 3 = 999, 4 = 9999
puts "How many decimal places would you like to check:" # asking user for how many decimal places to get product of
print "> " # setting a little prompt
places = gets.chomp.to_i # getting the decimal value to get product of
places_save = places # saving the decimal value, since we change it later (line: 26)
def tri(places) # creating a function called tri with the paramater as the decimal value to check
sixes = '' # setting a null value where we will store additional 6's (This changes depending on the decimal value)
zeros = '' # setting a null value where we will store additional 0's (This changes depending on the decimal value)
if places > 1 # if the decimal place to check is greater than 1
places = places-1 # subtract one from that value
places.times { sixes += '66' } # for every decimal value add '66' to our sixes variable
places.times { zeros += '0' } # for every decimal value add a '0' to our zeros variable
return "16"+sixes+"5"+zeros # return the value for the product of the triangle numbers
elsif places == 1 # if the decimal place to check is equal to 1
return 165 # return 165 (This is the product of: 1(1+1)/2 through 9(9+1)/2)
end # end the if
end # end the function
total = 0 # initializing a variable which will hold our final product
while places > 0 # while places is greater than 0
value = tri(places) # store the product of the current decimal place in a variable called value
total += value.to_i # have total equal that value converter to an integer, since the function returns it as a string
places -= 1 # subtract 1 from our places variable
end # end the loop if places is no longer greater than 0
puts "The total sum for %s digits, is: %s" % [places_save, total] # print the product of the sum of all triangle numbers up to our desired decimal position
result = let get n = div (n*(n+1)*(n+2)) 6 in let arr = take 20 (iterate ((+9) . (*10)) 9) in sum[get x | x <- arr]
get n = div (n*(n+1)*(n+2)) 6
main = print (sum[get x | x <- arr]) where arr = take 20 (iterate ((+9) . (*10)) 9)
num=raw_input('Enter last triangle to compute 1-')
decplaces=len(str(num))
solution=0
while decplaces>0:
number=''
repeats=decplaces
while repeats>0:
number+=num[0]
repeats-=1
n=int(number)
solution+=((n*(n+1)*(n+2))/6)
decplaces-=1
print solution
Users browsing this forum: No registered users and 0 guests