gmazel

//Am I missing a reference in LinqPad? //I get an error in LinqPad on line 9 below from Listing 2-14. Generate Logo commands to draw a //Serpinski triangle.linq: //"CS0103 The name 'serpinskyTriangle' does not exist in the current context" * string serpinskiTriangle = "A"; * Func transformA = x => x.Replace("A","B-A-B"); * Func markBs = x => x.Replace("B","[B]"); * Func transformB = x => x.Replace("[B]","A+B+A"); * int length = 6; * Enumerable.Range(1,length) * .ToList() * .ForEach (k => serpinskiTriangle = * transformB(transformA(markBs(serpinskyTriangle)))); * * serpinskiTriangle * .Replace("A", "forward 5" + Environment.NewLine) * .Replace("B", "forward 5" + Environment.NewLine) * .Replace("+", "left 60" + Environment.NewLine) * .Replace("-", "right 60" + Environment.NewLine) * .Dump("LOGO Commands for drawing Serpinsky Triangle"); // Thanks! // Gregg

About

Username
gmazel
Joined
Visits
11
Last Active
Roles
Member
Points
20

Activity

  • //Am I missing a reference in LinqPad?
    //I get an error in LinqPad on line 9 below from Listing 2-14. Generate Logo commands to draw a //Serpinski triangle.linq:

    //"CS0103 The name 'serpinskyTriangle' does not exist in the current context"
    1. string serpinskiTriangle = "A";
    2. Func transformA = x => x.Replace("A","B-A-B");
    3. Func markBs = x => x.Replace("B","[B]");
    4. Func transformB = x => x.Replace("[B]","A+B+A");
    5. int length = 6;
    6. Enumerable.Range(1,length)
    7. .ToList()
    8. .ForEach (k => serpinskiTriangle =
    9. transformB(transformA(markBs(serpinskyTriangle))));

    10. serpinskiTriangle
    11. .Replace("A", "forward 5" + Environment.NewLine)
    12. .Replace("B", "forward 5" + Environment.NewLine)
    13. .Replace("+", "left 60" + Environment.NewLine)
    14. .Replace("-", "right 60" + Environment.NewLine)
    15. .Dump("LOGO Commands for drawing Serpinsky Triangle");
    // Thanks!
    // Gregg
    April 19
    • nescafe
      nescafe
      It's a simple spelling error. serpinskyTriangle is not declared. serpinskiTriangle is (y=i). Please post your question in the Discussions section next time, it will be picked up sooner than in the Activity section

      Script: http://share.linqpad.net/4477wp.linq

      Result:
    • nescafe
      nescafe
      https://lh3.googleusercontent.com/oIf3WEdmwQA0POLF291KMtRtI8ysyEyA2ei9qj7rii2LvPR8CA82rR_E49vv1szumAShOjs9nbb76WOnNMv8-Uhss47-_2MjnV5cM6hE1OqvSX_TPhZa9-UZ6-ExeciqGo_3G5jjCg1VmBy30dhpB_Cb3x7NWYVB54GGzdEdwaHm7PhCFN82dpDSbsOCl5LZDKPOZgSzowzem1oOzuLXqHmJuxOPHAJQLvewZKdOdLDMSFkqx3yvHcSWoDXpesmYvwjUo5CybYr9eFiMJjdlRDp3SvogbO__fTK6eMdmH0OO9uES5toRD2vROnIkDGXLAvbDAYqsLBpzswLy5L6S3dXz1EsewsVSAxYaUhl8w0dJ9ioAVzaN-u4f0CLpC1ePX6j9jynYvE8kgfQsAUyO5-JMhgy5dbqT2blFao2K0NjlUJz-QwLotapRYiVZTc-jMAgQBJ_yc0RHXrqn-Ep7v1JTyzt3FeqmSfoWwSWVsr2KXEm-Yyz5OyPjBsGNOBk2rftDFB8vkC5p2i_HYJ7GNiBcxkkJBI9C0dsKpc75stlMohvns9kMnakh1C1QlFqKGWvN-27OWMZUEknh2_Mi9xhIcZSVnLVIZ2yJjiGNvxHaq1cKsXSTL-f1iA88p8U7OXjon17P90MFKPTY4M1N_Ai7fhbl32-FhJNoylUOTzBUTFstjtn_oTqr1OFN2zcA03kPJyKvMT-EmebreF-0tdKmPQLSZMdTsYmX4AjWT637UvP0-IIZnjXBvj6hzL7W_JcekKc09yVFz65J0hxkSn9ioxvr0nx_aXrkUHri0zRFRi1EQQsjQD1N=w315-h371-no
    • nescafe
      nescafe
      Image generated using https://www.calormen.com/jslogo/
    • gmazel
      gmazel
      Thank you!
Avatar

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!