Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16255 > unrolled thread

Re: Programming Fail

Started byAlex Krasnov <akrasnov@cory.eecs.berkeley.edu>
First post2013-11-19 07:36 +0000
Last post2013-11-19 07:36 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Programming Fail Alex Krasnov <akrasnov@cory.eecs.berkeley.edu> - 2013-11-19 07:36 +0000

#16255 — Re: Programming Fail

FromAlex Krasnov <akrasnov@cory.eecs.berkeley.edu>
Date2013-11-19 07:36 +0000
SubjectRe: Programming Fail
Message-ID<l6f4e1$1q$1@smc.vnet.net>
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:	Sound[Thread[SoundNote[Flatten[Characters[A]] /. pitchMap]]]

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:	Sound[Thread[SoundNote[ToExpression[Flatten[Characters[A]]] /. 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"};
In:	Sound[Thread[SoundNote[Flatten[A] /. pitchMap]]]

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"};
>
> Sound[Thread[SoundNote[Flatten[IntegerPartitions[5]] /. pitchMap]]]
>
>
> 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"};
>
> Sound[Thread[SoundNote[Flatten[A]] /. pitchMap]]]
>
>
> 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
>
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web