Page 1 of 2

The Powers That Be

Posted: Wed Nov 26, 2008 1:13 am
by Marv
Heres my Code in Ruby:

Code: Select all

x = ((17**39)**11).to_s
result = ''
(x.size/33).times {|t|result<<x[t*33,1]}
p result

Posted: Sun Nov 30, 2008 4:39 pm
by DocJoe
Nice challenge. Now I know how to do large number multiplication in python. :)

that's the solution in python
from decimal import *
getcontext().prec=600
getcontext().power(getcontext().power(Decimal('17'),Decimal('39')),Decimal('11'))

the rest is some string editing...

Only one thing: The description is a bit misleading, because it says "every 33rd digit". It assumes that the first digit is the zeroth digit. Well... thats how how we count isn't it... ;)

Cheers
DJ

Posted: Sun Nov 30, 2008 5:34 pm
by gfoot
You don't need to import anything fancy to work with large integers - just write the expression as normal. Python silently switches types to a flexible type when the numbers get too large for a normal integer.

Code: Select all

n = (17 ** 39) ** 11
print str(n)[::33]

Posted: Sun Nov 30, 2008 6:13 pm
by JanB
solved it in java :twisted:

Posted: Sun Feb 08, 2009 2:39 am
by yes-man
The answer is 'man bc'.

Posted: Sun Jun 28, 2009 11:00 pm
by hobbist

Code: Select all

x = str(((17**39)**11)) 
x2 = ''
for i in range(0,len(x),33):
    x2 += x[i]
print 'powers that be ', x2

Gawd, I love python. Can't wait until I really start learning.

Posted: Sat Aug 22, 2009 12:00 pm
by linz123
http://web2.0rechner.de/
plus http://nopaste.ch/formattext/ (Wrap lines after 33 characters)

Perl

Posted: Fri May 21, 2010 12:35 am
by markobr

Code: Select all

use bignum;
$r = ((17 ** 39) ** 11);
for ($i = 0; $i < length($r); $i += 33) {
	print substr($r,$i,1);
}
print "\n";

Posted: Wed Jun 30, 2010 7:30 am
by s7mahess
Solved it in C++,

was much harder than the ways above but worked

Code: Select all

#include <iostream>

using namespace std;

string add(string augend,string addend){  //funktioniert nur für positive ganzzahlen
  int i,j,k,s1,s2,sum,uber=0;
  string str,result="";
  i=augend.length()-1;
  j=addend.length()-1;
  if (i>=j){
  	k=i;
  }
  else{
  	k=j;
  }

  while (k>=0){
    if (i>=0){
    	s1=augend.at(i)-48;
    }
    else{
      s1=0;
    }
    if (j>=0){
    	s2=addend.at(j)-48;
    }
    else{
    	s2=0;
    }

    sum=s1 + s2 + uber + 48;
    if (s1+s2+uber>=10){
      uber=1;
      sum=sum-10;
      if (k==0){
      	k++;
      }
    }
    else{
      uber=0;
    }
    str=sum;
    result=result.insert(0,str);
    i--;j--;k--;
  }
  return(result);
}

string multi(string multiplicand,string multiplier){
  string str_counter="0",result="";
  while (str_counter.compare(multiplier) != 0){
  	result=add(multiplicand,result);
  	str_counter=add(str_counter,"1");
  }
  return(result);
}

string power(string base,string exponent){
  string str_counter="1",result=base;
  while (str_counter.compare(exponent) != 0){
  	result=multi(result,base);
  	str_counter=add(str_counter,"1");
  }
  return(result);
}

int main(){
  string str1="17",str2="429",str3;
  str3=power(str1,str2);
  cout << str3 << endl;
  for (int i=1;i<=str3.length()/33;i++){
  	cout << str3.at(33*i-33);
  }
}

wolframalpha FTW

Posted: Wed Jul 14, 2010 8:26 pm
by polarlemniscate
see above!

Posted: Sat Oct 16, 2010 10:06 pm
by Grevas
DocJoe wrote:Nice challenge. Now I know how to do large number multiplication in python. :)
And I know now how to do it in PHP.

Code: Select all

$x = bcpow(bcpow(17, 39), 11);
for($i = 0; $i < strlen($x); $i++) {
	echo $x[$i];
	if(($i+1) % 33 == 0) echo "<br />";
}
But i don't think i will need it :lol:

Posted: Sun Oct 31, 2010 4:40 pm
by KervyN
wolframalpha + notepad (shame on me)

Posted: Sat Nov 20, 2010 3:18 am
by nano-gilmour
KervyN wrote:wolframalpha + notepad (shame on me)
Windows Calculator and notepad also, Nice to know it's not only me how takes simple ways :D

Posted: Fri Apr 22, 2011 7:07 pm
by Schnapphahn
just like KervyN, and my 1st attempt was 2697927297682107.

Posted: Fri Apr 22, 2011 8:43 pm
by mkf00
gfoot wrote:You don't need to import anything fancy to work with large integers - just write the expression as normal. Python silently switches types to a flexible type when the numbers get too large for a normal integer.

Code: Select all

n = (17 ** 39) ** 11
print str(n)[::33]
python FTW

my code:

Code: Select all

#!/bin/python
a = (17 ** 39) ** 11
count = count + a[0]
for i in range(0, len(a)):
	if i % 33 == 0:
		count = count + a[i]
print count