June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,23 @@
|
|||
#include <iostream>
|
||||
#include <boost/multiprecision/gmp.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace mp = boost::multiprecision;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// We could just use (1 << 18) instead of tmpres, but let's point out one
|
||||
// pecularity with gmp and hence boost::multiprecision: they won't accept
|
||||
// a second mpz_int with pow(). Therefore, if we stick to multiprecision
|
||||
// pow we need to convert_to<uint64_t>().
|
||||
uint64_t tmpres = mp::pow(mp::mpz_int(4)
|
||||
, mp::pow(mp::mpz_int(3)
|
||||
, 2).convert_to<uint64_t>()
|
||||
).convert_to<uint64_t>();
|
||||
mp::mpz_int res = mp::pow(mp::mpz_int(5), tmpres);
|
||||
std::string s = res.str();
|
||||
std::cout << s.substr(0, 20)
|
||||
<< "..."
|
||||
<< s.substr(s.length() - 20, 20) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import ceylon.whole {
|
||||
wholeNumber,
|
||||
two
|
||||
}
|
||||
|
||||
shared void run() {
|
||||
|
||||
value five = wholeNumber(5);
|
||||
value four = wholeNumber(4);
|
||||
value three = wholeNumber(3);
|
||||
|
||||
value bigNumber = five ^ four ^ three ^ two;
|
||||
|
||||
value firstTwenty = "62060698786608744707";
|
||||
value lastTwenty = "92256259918212890625";
|
||||
value bigString = bigNumber.string;
|
||||
|
||||
"The number must start with ``firstTwenty`` and end with ``lastTwenty``"
|
||||
assert(bigString.startsWith(firstTwenty), bigString.endsWith(lastTwenty));
|
||||
|
||||
value bigSize = bigString.size;
|
||||
print("The first twenty digits are ``bigString[...19]``");
|
||||
print("The last twenty digits are ``bigString[(bigSize - 20)...]``");
|
||||
print("The number of digits in 5^4^3^2 is ``bigSize``");
|
||||
}
|
||||
|
|
@ -1 +1,3 @@
|
|||
5 4 3 2 pow pow pow asString dup left(20) . dup right(20) . size .
|
||||
import: mapping
|
||||
|
||||
5 4 3 2 pow pow pow >string dup left( 20 ) . dup right( 20 ) . size .
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
/*REXX program calculates and demonstrates arbitrary precision numbers (using powers). */
|
||||
numeric digits 200000 /*two hundred thousand decimal digits. */
|
||||
|
||||
n = 5 ** (4 ** (3 ** 2) ) /*calculate multiple exponentiations. */
|
||||
# = 5 ** (4 ** (3 ** 2) ) /*calculate multiple exponentiations. */
|
||||
|
||||
true=62060698786608744707...92256259918212890625 /*what answer is supposed to look like.*/
|
||||
rexx= left(n, 20)'...'right(n, 20) /*the left and right 20 decimal digits.*/
|
||||
rexx= left(#, 20)'...'right(#, 20) /*the left and right 20 decimal digits.*/
|
||||
|
||||
say ' true:' true /*show what the "true" answer is. */
|
||||
say ' REXX:' rexx /* " " " REXX " " */
|
||||
say 'digits:' length(n) /* " " " length of answer is. */
|
||||
say 'digits:' length(#) /* " " " length of answer is. */
|
||||
say
|
||||
if true == rexx then say 'passed!' /*either it passed, ··· */
|
||||
else say 'failed!' /* or it didn't. */
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
/*REXX program calculates and demonstrates arbitrary precision numbers (using powers). */
|
||||
numeric digits 5 /*just use enough digits for 1st time. */
|
||||
|
||||
n=5** (4** (3** 2) ) /*calculate multiple exponentiations. */
|
||||
#=5** (4** (3** 2) ) /*calculate multiple exponentiations. */
|
||||
|
||||
parse var n 'E' pow . /*POW might be null, so N is OK. */
|
||||
parse var # 'E' pow . /*POW might be null, so N is OK. */
|
||||
|
||||
if pow\=='' then do /*general case: POW might be < zero.*/
|
||||
numeric digits abs(pow) + 9 /*recalculate with more decimal digits.*/
|
||||
n=5** (4** (3** 2) ) /*calculate multiple exponentiations. */
|
||||
#=5** (4** (3** 2) ) /*calculate multiple exponentiations. */
|
||||
end /* [↑] calculation is the real McCoy. */
|
||||
|
||||
true=62060698786608744707...92256259918212890625 /*what answer is supposed to look like.*/
|
||||
rexx= left(n, 20)'...'right(n, 20) /*the left and right 20 decimal digits.*/
|
||||
rexx= left(#, 20)'...'right(#, 20) /*the left and right 20 decimal digits.*/
|
||||
|
||||
say ' true:' true /*show what the "true" answer is. */
|
||||
say ' REXX:' rexx /* " " " REXX " " */
|
||||
say 'digits:' length(n) /* " " " length of answer is. */
|
||||
say 'digits:' length(#) /* " " " length of answer is. */
|
||||
say
|
||||
if true == rexx then say 'passed!' /*either it passed, ··· */
|
||||
else say 'failed!' /* or it didn't. */
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
irb(main):001:0> y = ( 5**4**3**2 ).to_s; puts "5**4**3**2 = #{y[0..19]}...#{y[-20..-1]} and has #{y.length} digits"
|
||||
5**4**3**2 = 62060698786608744707...92256259918212890625 and has 183231 digits
|
||||
irb(main):001:0> y = ( 5**4**3**2 ).to_s
|
||||
puts "5**4**3**2 = #{y[0..19]}...#{y[-20..-1]} and has #{y.length} digits"
|
||||
|
|
|
|||
|
|
@ -5,5 +5,12 @@ use num::pow::pow;
|
|||
|
||||
fn main() {
|
||||
let big = BigUint::from_u8(5).unwrap();
|
||||
println!("{}", pow(big,pow(4,pow(3,2))));
|
||||
let answer_as_string = format!("{}", pow(big,pow(4,pow(3,2))));
|
||||
|
||||
// The rest is output formatting.
|
||||
let first_twenty: String = answer_as_string.chars().take(20).collect();
|
||||
let last_twenty_reversed: Vec<char> = answer_as_string.chars().rev().take(20).collect();
|
||||
let last_twenty: String = last_twenty_reversed.into_iter().rev().collect();
|
||||
println!("Number of digits: {}", answer_as_string.len());
|
||||
println!("First and last digits: {:?}..{:?}", first_twenty, last_twenty);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue