# simply right-reduce please

**URL:** <https://community.wolfram.com/t/simply-right-reduce-please/4812>\
**Category:** Questions\
**Tags:** mathematica\
**Created:** [February 10, 2015, 1:57pm UTC](https://community.wolfram.com/t/simply-right-reduce-please/4812 "2015-02-10T13:57:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erikitter](https://avatars.discourse-cdn.com/v4/letter/e/c37758/32.png) [@erikitter](https://community.wolfram.com/u/erikitter)\
**Post date:** [February 10, 2015, 1:57pm UTC](https://community.wolfram.com/t/simply-right-reduce-please/4812/1 "2015-02-10T13:57:29Z")

</div>

Hello,

this is a very basic and therefore somewhat embarrising one, but … cannot figure it out.

I have a list, e.g, {2, 9, 2, 9, 1, 10, 1, 1, 3, 1, 8, 2, 8, 2} (representing a solution of a numbers puzzle but not important) and I need to make it the number 292911011318282. So I need to take an element multiply it by 10 if it is \<10, otherwise 100 and add the rest of the list applying the same function. Therefore this seems to be the very basic right-reduce of functional programming and certainly there is that function somewhere in Mathematica but I do not see it and I fail misserably simulating it with a own function for quite some time now.

It should do (Scheme):

(define (right-reduce combine initial s)  
(if (empty-stream? s)  
initial  
(combine (head s)  
(right-reduce combine initial (tail s)))))

just for Lists in Mathematica (and of topic: are there (potentially) endless streams in Mathematica with lazy evaluation such as there are in Scheme or Haskell?).

I cannot solve my problem by hand as there are a few thousand solutions to be compared and I also should learn how to right-reduce in Mathematica so - please…

so embarrising.

---

<div class="post-metadata">

**Author:** ![nma](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@nma](https://community.wolfram.com/u/nma)\
**Post date:** [February 10, 2015, 2:21pm UTC](https://community.wolfram.com/t/simply-right-reduce-please/4812/2 "2015-02-10T14:21:32Z")

</div>

> I have a list, e.g, {2, 9, 2, 9, 1, 10, 1, 1, 3, 1, 8, 2, 8, 2}  
> (representing a solution of a numbers puzzle but not important) and I  
> need to make it the number 292911011318282

one way

```
lst = {2, 9, 2, 9, 1, 10, 1, 1, 3, 1, 8, 2, 8, 2};
FromDigits[lst]
(* 29292011318282 *)

```

another way

```
lst = {2, 9, 2, 9, 1, 10, 1, 1, 3, 1, 8, 2, 8, 2};
ToExpression@StringJoin[ToString[#] & /@ lst]
  (*292911011318282*)

```

---

<div class="post-metadata">

**Author:** ![jpd](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/jpd/32/34994_2.png) [@jpd](https://community.wolfram.com/u/jpd)\
**Post date:** [February 10, 2015, 2:40pm UTC](https://community.wolfram.com/t/simply-right-reduce-please/4812/3 "2015-02-10T14:40:30Z")

</div>

rightReduce[combine\_, initial\_, {head\_, tail\_\_\_}] := combine[head, rightReduce[combine, initial, {tail}]]  
rightReduce[_, initial_, {}] := initial
