The Powers That Be

Discussion of challenges you have already solved
Marv
Posts: 17
Joined: Tue Nov 25, 2008 12:58 pm

The Powers That Be

Post 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
DocJoe
Posts: 5
Joined: Sun Nov 02, 2008 1:22 pm
Location: Vagina Hole

Post 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
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post 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]
JanB
Posts: 8
Joined: Fri Nov 28, 2008 5:32 pm

Post by JanB »

solved it in java :twisted:
User avatar
yes-man
Posts: 32
Joined: Fri Jan 30, 2009 5:14 pm

Post by yes-man »

The answer is 'man bc'.
hobbist
Posts: 5
Joined: Sun Jun 28, 2009 4:02 pm

Post 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.
User avatar
linz123
Posts: 1
Joined: Sat Nov 01, 2008 8:03 am
Contact:

Post by linz123 »

http://web2.0rechner.de/
plus http://nopaste.ch/formattext/ (Wrap lines after 33 characters)
markobr
Posts: 17
Joined: Thu May 20, 2010 4:09 pm
Location: Tübingen
Contact:

Perl

Post 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";
s7mahess
Posts: 2
Joined: Fri Jan 09, 2009 9:03 pm

Post 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);
  }
}
polarlemniscate
Posts: 6
Joined: Wed Mar 03, 2010 1:56 pm

wolframalpha FTW

Post by polarlemniscate »

see above!
Grevas
Posts: 10
Joined: Sat Oct 16, 2010 3:47 pm

Post 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:
KervyN
Posts: 1
Joined: Sat Oct 16, 2010 4:51 pm
Contact:

Post by KervyN »

wolframalpha + notepad (shame on me)
nano-gilmour
Posts: 1
Joined: Mon Nov 15, 2010 9:35 pm

Post 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
Schnapphahn
Posts: 12
Joined: Sun Oct 26, 2008 4:33 pm

Post by Schnapphahn »

just like KervyN, and my 1st attempt was 2697927297682107.
mkf00
Posts: 1
Joined: Mon Feb 07, 2011 2:51 am

Post 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
great website, btw^^
Post Reply