Factorial digit sum in APL (Project Euler 20) - math

First I found +/⍎¨⍕(!8) and it gave me the result 9. But if I do 100!, as the number is big, I am not able to get that.
With ⍎¨⍕(!100) I am getting a syntax error: ⍎SYNTAX ERROR
Is there any other way to solve the problem or can you suggest me some modifications?

!100 is a large number and when you format it's result you'll get a string representing a number in E notation.
⍕!100 → '9.332621544E157', when you attempted to eval (⍎) each character you ran into a syntax error since E has no meaning.
There are two ways to split a large integer into it's digits:
Firstly with inverse decode, examples can be found on the APLcart
10⊥⍣¯1!100
This is vulnerable to floating point imprecision, however.
The second and preferred option is using big from the dfns library, which can be imported using the quad function CY.
'big'⎕CY'dfns'
Examples here
And thankfully the last example covers your exact case! Factorial 100 is ↑×big/⍳100
The final solution to the problem could look like this:
+/⍎¨↑×big/⍳100

Related

how to find out only one digit in a int number?

Im new so if this question was already Asked (i didnt find it scrolling through the list of results though) please send me the link.
I got a math quiz and im to lazy to go through all the possibilities so i thought i can find a program instead. I know a bit about programming but not much.
Is it possible (and in what programming language, and how) to read only one digit, e.g at the 3rd Position, in a integer?
And how is an integer actually saved, in a kind of array?
Thanks!
You can get rid of any lower valued digit (the ones and tens if you only want the hundreds) by dividing with rounding/truncation. 1234/100 is 12 in most languages if you are doing integer division.
You can get rid of any higher valued digits by using taking the modulus. 12 % 10 is 2 in many languages; just find out how the modulus is done in yours. I use "modulus" meaning "divide and keep the rest only", i.e. it is the opposite of "divide with rounding"; that which is lost by rounding is the final result of the modulus.
The alternative is however to actually NOT see the input as a number and treat it as text. That way it is often easier to ignore the last 2 characters and all leading characters.

Julia power operator ^ returns different value than python pow()

i made a rsa-encryption demo to learn julia but ran into a problem.
this should be no issue of overflow and all values fit rsa criteria when i check with python code.
any pointers are welcome. julia is an awesome language and i would like to figure this out.
check these images to see my problem:
You need BigInt(message)^used_e, and similar. The problem you are seeing is integer overvflow before you convert to BigInt. Note that powermod(BigInt(message), used_e, used_N) will be much faster since it will keep all the intermediate numbers smaller.
Note that in Julia x % y is a synonym for the rem(x, y) function “from Euclidean division, returning a value of the same sign as x”, whereas for an RSA implementation, you need the mod function instead, where the result has the same sign as y. (But you really actually want powermod over BigInt here for performance.)

Vector as an exponent in Julia

I have very basic question. I am new to Julia and used to code in R a lot. I need to take a scalar to the multiple powers, represented by a vector: 3^[2,3]. I got an error "Method error: no method matching ^...". I tried 3^Array([2,3]), but got the error again. At the same time, 3*[2,3] works as expected. Is there any way to do it in Julia without using for loop?
I think you are looking for the . or broadcast functions that allow you to apply any other functions elementwise!
3 .^ [2,3] or broadcast(^, 3, [2,3])
Small edit: you'll need a space after the number to be exponentiated, e.g. 3 .^[2,3].

Multiplication in R without using the multiplication sign

I like solving my math problems(high school) using R as it is faster than writing on a piece of paper. One problem I'm having is that I have to keep writing the multiplication sign, example:
9x^2 + 24x + 16 yields = Error: unexpected symbol in "9x"
Is there any way in R to multiply 4x, without having to write 4*x but only 4x?
Would save me some time in having to write one extra character the whole time! Thanks
No. Having a number in front of a character without any space simply isn't valid syntax in R.
Take a step back and look at the syntax rules for, say, Excel, Matlab, Python, Mathematica. Every language has its rules, generally (:-) ) with good reason. For example, in R, the following are legal object names:
foo
foo.bar
foo1
foo39
But 39foo is not legal. So if you wanted any sequence [0-9][Letters] or the reverse to indicate multiplication, you'd have a conflict with naming rules.

Solve Physics exercise by brute force approach

Being unable to reproduce a given result. (either because it's wrong or because I was doing something wrong) I was asking myself if it would be easy to just write a small program which takes all the constants and given number and permutes it with a possible operators (* / - + exp(..)) etc) until the result is found.
Permutations of n distinct objects with repetition allowed is n^r. At least as long as r is small I think you should be able to do this. I wonder if anybody did something similar here..
Yes, it has been done here: Code Golf: All +-*/ Combinations for 3 integers
However, because a formula gives the desired result doesn't guarantee that it's the correct formula. Also, you don't learn anything by just guessing what to do to get to the desired result.
If you're trying to fit some data with a function whose form is uncertain, you can try using Eureqa.

Resources