Re: Programming Fail

• To: mathgroup at smc.vnet.net
• Subject: [mg132033] Re: Programming Fail
• From: Dean Rosenthal <deanrosenthal at gmail.com>
• Date: Tue, 19 Nov 2013 02:59:16 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-outx@smc.vnet.net
• Delivered-to: mathgroup-newsendx@smc.vnet.net
• References: <20131117232215.A9F846A15@smc.vnet.net> <Pine.GSO.4.64.1311171800480.21281@cory> <CAKAKAgJ7DBtQLEdinA=c5YFhnZcmP4EzyCymBaoqhDgNYq2HyA@mail.gmail.com> <CAKAKAgLncmvbGoiGukP0y++Xvd47nWXE_13nPbeFRmP7koY_Hw@mail.gmail.com> <Pine.GSO.4.64.1311172227080.3375@cory>

```If you are giving a "go to" argument in the first routine, just don't start with "0".  That's good to know about the length argument, thanks.
--
Dean Rosenthal
www.deanrosenthal.org

> On Nov 18, 2013, at 1:37 AM, Alex Krasnov <akrasnov at cory.eecs.berkeley.edu> wrote:
>
> Your solution is similar to my second one but fails given leading zeros:
>
> In:    ToExpression[Characters["0123"]]
> Out:    {0, 1, 2, 3}
>
> In:    IntegerDigits[ToExpression["0123"]]
> Out:    {1, 2, 3}
>
> You can provide a length argument if known:
>
> In:    IntegerDigits[ToExpression["0123"], 10, 4]
> Out:    {0, 1, 2, 3}
>
> Alex
>
>
>> On Sun, 17 Nov 2013, Dean Rosenthal wrote:
>>
>> Looks like inserting ToExpression does the work:
>>
>>
>>
>> Where "a" is the output of the first routine.  Thanks for your input, Alex,
>> I wouldn't have used ToExpression without your suggestion.
>>
>>
>> Thanks,
>>
>> Dean
>>
>>
>> On Sun, Nov 17, 2013 at 10:05 PM, Dean Rosenthal <deanrosenthal at gmail.com>wrote:
>>
>>> Thanks.  Yes, that is correct, pitchMap uses integers. Here is where I am,
>>> I am invoking "IntegerDigits" to create the sound object:
>>>
>>>
>>>
>>> Where the values are, those need to come from this:
>>>
>>>
>>> StringJoin[
>>>
>>> NestList[
>>>  StringReplace[#, {"0" -> "2", "2" -> "12", "1" -> "23", "3" -> "45",
>>>     "4" -> "56"}] &, "0", 4]];
>>>
>>>
>>> I can add the pitch mapping, they instrument, length of time later.  But
>>> I'm not sure how to make the output from:
>>>
>>>
>>> StringJoin[
>>>
>>> NestList[
>>>  StringReplace[#, {"0" -> "2", "2" -> "12", "1" -> "23", "3" -> "45",
>>>      "4" -> "56"}] &, "0", 4]];
>>>
>>>
>>> land HERE:
>>>
>>>
>>>
>>>
>>> Thanks,
>>>
>>> Dean
>>>
>>>
>>> PS. Also, if I use these particular values 0->2, etc. - note that the
>>> sound object won't respond to "0", i.e. won't map correctly (I've bumped
>>> each value up by one, so the starting point is "1" in my .nb)
>>>
>>>
>>> On Sun, Nov 17, 2013 at 9:36 PM, Alex Krasnov <
>>> akrasnov at cory.eecs.berkeley.edu> wrote:
>>>
>>>> The main issue is that A uses strings but pitchMap uses integers. Here
>>>> are three possible solutions:
>>>>
>>>> In:     A = NestList[StringReplace[#, {"0" -> "2", "2" -> "12", "1" ->
>>>> "23", "3" -> "45", "4" -> "56"}] &, "0", 7];
>>>> In:     pitchMap = {"0" -> "B4", "1" -> "C4", "2" -> "D4", "3" -> "E4",
>>>> "4" -> "F4", "5" -> "G4", "6" -> "A4"};
>>>>
>>>> In:     A = NestList[StringReplace[#, {"0" -> "2", "2" -> "12", "1" ->
>>>> "23", "3" -> "45", "4" -> "56"}] &, "0", 7];
>>>> In:     pitchMap = {0 -> "B4", 1 -> "C4", 2 -> "D4", 3 -> "E4", 4 ->
>>>> "F4", 5 -> "G4", 6 -> "A4"};
>>>> pitchMap]]]
>>>>
>>>> In:     A = NestList[Flatten[Replace[#, {0 -> 2, 2 -> {1, 2}, 1 -> {2,
>>>> 3}, 3 -> {4, 5}, 4 -> {5, 6}}, 1]] &, {0}, 7];
>>>> In:     pitchMap = {0 -> "B4", 1 -> "C4", 2 -> "D4", 3 -> "E4", 4 ->
>>>> "F4", 5 -> "G4", 6 -> "A4"};
>>>>
>>>> Unfortunately, Mathematica displays 0 and "0" in the same way. You can
>>>> use FullForm in order to avoid confusion.
>>>>
>>>> Alex
>>>>
>>>>
>>>>
>>>> On Sun, 17 Nov 2013, Dean Rosenthal wrote:
>>>>
>>>> Hi:
>>>>>
>>>>> My question is going to take all of you about a split second to answer.
>>>>> Sadly, programming is something I seem to be congenitally incapable of
>>>>> teaching myself and doing well.  I usually just cut and paste specifics
>>>>> into prewritten algorithms.
>>>>>
>>>>> If you do this
>>>>>
>>>>> pitchMap = {1 -> {"C4", "D4"}, 2 -> "D4", 3 -> "E4", 4 -> "F4", 5 ->
>>>>> "G4"};
>>>>>
>>>>>
>>>>>
>>>>> You get a music player and can play the result.
>>>>>
>>>>>
>>>>> If you do this:
>>>>>
>>>>>
>>>>> A = NestList[
>>>>> StringReplace[#, {"0" -> "2", "2" -> "12", "1" -> "23", "3" -> "45",
>>>>>   "4" -> "56"}] &, "0", 7]
>>>>>
>>>>> pitchMap = {0 -> "B4", 1 -> "C4", 2 -> "D4", 3 -> "E4", 4 -> "F4", 5->
>>>>> "G4",
>>>>> 6 -> "A4"};
>>>>>
>>>>>
>>>>>
>>>>> You get nothing, just output.  See what I did there?  I substituted,
>>>>> because that's what you do if you don't know how to program!  On the face
>>>>> of things, I can't see why it wouldn't work, but I've wasted at least an
>>>>> hour going through documentation and Googling and trying different
>>>>> approaches.  I'm not a programmer and I can't seem to teach myself how to
>>>>> do this, ideas?
>>>>>
>>>>>
>>>>> Thanks,
>>>>>
>>>>>
>>>>> Dean
>>>
>>>
>>> --
>>> Dean Rosenthal
>>> www.deanrosenthal.org
>>
>>
>> --
>> Dean Rosenthal
>> www.deanrosenthal.org
>>

```

• Prev by Date: Re: Programming Fail
• Next by Date: Re: Animate cannot be combined?
• Previous by thread: Re: Programming Fail
• Next by thread: Re: Programming Fail