0
votes
3answers
109 views

How can I use NestWhileList instead of While in this case?

OK, the problem occurred when I challenged with Project Euler No. 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. My code is: ...
1
vote
0answers
126 views

Is learning haskell still necessary to MMA users? [closed]

I'm major in Math and I had learned haskell for one week. But I'm unaccustomed to its coding style. I saw many people said if you want to master functional programming, then you shall use haskell. ...
1
vote
0answers
112 views

Finding Values of All Nine Constants in q-hypergeometric Equation

I suspect that an identity of the form $$\sum_{j=-n}^{j=n}(-1)^jq^{j(5j+1)/2}=\sum_{r=0}^{n}f_{ar+bn+c}(-1)^{n-r}q^{(n-r)(dr+en+f)/2}\frac{(q;q)_{gr+hn+j}}{(q;q)_{n-r}}$$ for $a, \dots , j$ integer ...
0
votes
1answer
73 views

How to write series of Do[ ]'s with a single Table[ ]?

Edited to provide more information (sorry I don't know how to format matrices here) I would like to replace: m = 4; ...
5
votes
7answers
556 views

Better code to find Narcissistic number

My code finding Narcissistic numbers is not that slow, but it's not in functional style and lacks flexibility: if $n \neq 7$, I have to rewrite my code. Could you give some good advice? ...
10
votes
5answers
477 views

How to find first list element that differs from average of N previous elements by more than a given amount?

Given a list of real numbers, I need to write a function that returns the value of the first element in the list that differs from the mean of the previous $N$ elements by greater than $P$ standard ...
11
votes
4answers
541 views

How to write this without For loop

Suppose I have a few lists of numbers and want to exponentiate element-wise, then sum up everything into a polynomial. For example, if I have ...
0
votes
1answer
249 views

How can I improve my code with efficient mathematica built-in functions?

I have written a module for my assignment like below. V[n + 1] = rk[x[n], y[n] ,z[n], V[n]]; vs = V[n].V[n+1]; V[n + 1] = I want to modify it with efficient ...
14
votes
3answers
537 views

How can I improve my code for drawing a tree?

This code draws a tree, but it's not in the functional style. ...
7
votes
3answers
441 views

Rewriting For loop to FoldList or similar

In CrossValidated, the answer to a question on prediction of number of viewers of Gangnam Style is given in R. I have mapped the answer directly to Mathematica: ...
12
votes
5answers
678 views

How to improve this code for solving the “Mr.S and Mr.P” puzzle?

Mr.S and Mr. P puzzle — "Formalization of two Puzzles Involving Knowledge", McCarthy, John (1987) We pick two numbers $a$ and $b$, such that $a\geq b$ and both numbers are within the range ...
4
votes
3answers
356 views

Generate a Combination of letters by a number

I'm trying to write a function f. example: ...
6
votes
0answers
114 views

What are some general strategies to avoid using For loops? [duplicate]

Possible Duplicate: Iterating over lists in Mathematica While there are some cases where a For loop might be reasonable, it's a general mantra – one I ...
2
votes
3answers
161 views

Using Nest inside NestList

I need results like this: {Cos[Cos[x]], Sin[Cos[Cos[x]]],Cos[Cos[Sin[Cos[Cos[x]]]]], Sin[Cos[Cos[Sin[Cos[Cos[x]]]]]], ... } I've tried to use ...
13
votes
3answers
275 views

How to keep some of the results of the NestList

I'm using some iterative arithmetics to calculate wave propagation with the help of NestList. I have to use a small step size for iteration to guarantee the accuracy, which lead to too much data (e.g, ...
8
votes
2answers
227 views

Cases[data,Colon[key,_]] vs. Cases[data,key:_] toward XPath, XQuery

Exploring methods to index and search tree-structured key:value pairs via named-entity index (key paths) as opposed to Position-based indexing. Using Rule as ...
18
votes
3answers
1k views

Does every Symbol in Mathematica induce a monad?

From my question about types in Mathematica, I assume that every Symbol in Mathematica is a type if it appears as a Head of some ...
14
votes
2answers
686 views

Using a list of tuples in a pure function

I want to use a list of tuples within a function to make assignments. Say I want to make assignments of the form value[i,j] = val What I have is a list of ...
16
votes
1answer
318 views

Are there advantages to using additional arguments of common functions rather than alternative ways of calculating with lists?

(Apologies for the long question title.) One of the interesting, if sometimes confusing, things about Mathematica is that there is always more than one way to do things. Even intermediate users can ...
21
votes
6answers
1k views

Can this be written well, without loops?

Inspired by this question I would like to know if the following code can be written without explicit loops (For, While, etc.) in a clean, efficient and non-contrived way. I have been unable to do so. ...