Group Abstract Group Abstract

Message Boards Message Boards

6
|
49.1K Views
|
58 Replies
|
51 Total Likes
View groups...
Share
Share this post:

[WSG20] Programming Fundamentals Week 1

During week 1 of Daily Wolfram Study Group, May 2020, we will be looking at the following topics:

  • Day 1: Working with Data
  • Day 2: Building Interfaces
  • Day 3: Functional Programming
  • Day 4: Tips for Writing Fast Code

We will look at lecture videos from the Wolfram U archives and also work on simple coding examples and mini projects.

Feel free to post questions on the material we cover in these sessions here.

58 Replies

Can we download the notebooks in this series? If so where can we find the links too the notebooks?

POSTED BY: Charles Glover

HI Charles, Links to notebook downloads have been shared with registered participants. If you haven't already, please feel free to sign up at https://wolfr.am/MRRR3lFC

Thanks

Can we download the notebooks in this series? If so where can we find the links too the notebooks?

POSTED BY: Charles Glover
Posted 6 years ago

My final attempt at the PigLatin challenge. The code is much improved since my last submission. It passes all of the tests on the specification, including preserving punctuation + Rohit NamJoshi's Test procedure. I haven't tried to submit to the challenge web page, but will do so later. Any comments welcome: Having never really had a need to process strings before, I found this to be a difficult task...

PigLatin[text_String] := Module[{s = text},

  vlclst = {"a", "e", "i", "o", "u"};
  vuclst = {"A", "E", "I", "O", "U"};
  punclist = {".", ",", ";", ":", "!"};
  lst = StringExtract[s, All];

  StrngReorder[strRO_] :=
   StringInsert[
    StringTake[strRO, 1 - StringLength[strRO]],
    StringPart[strRO, 1],
    If[StringEndsQ[strRO, punclist], -2, -1]
    ];

  StrngStartConsonant[strSC_] :=
   StringFreeQ[
    StringPart[strSC, 1],
    vlclst,
    IgnoreCase -> True
    ];

  StrngAddWay[strAW_] :=
   StringInsert[strAW,
    "way",
    If[StringEndsQ[strAW, punclist], -2, -1]
    ];

  StrngAddAy[strAY_] :=
   StringInsert[
    NestWhile[StrngReorder[#] &, strAY, StrngStartConsonant[#] &],
    "ay",
    If[StringEndsQ[strAY, punclist], -2, -1]
    ];

  StrngMoveFirstVowel[strFV_] :=
   StringInsert[
    StringTake[strFV, 1 - StringLength[strFV]],
    StringTake[strFV, 1],
    If[StringEndsQ[str, punclist], -2, -1]
    ];

  StrngAddAy2[strAY2_] := Module
    [{str = strAY2},
    str = StrngMoveFirstVowel[strAY2];
    StrngAddAy[str]
    ];

  StrngRule2[str2_] := If[
    StringStartsQ[str2, vlclst],
    StrngAddWay[str2],
    str2];

  StrngRule3[str3_] := If[
    StrngStartConsonant[str3],
    StrngAddAy[str3],
    str3];

  StrngRule4[str4_] := If[
    StringStartsQ[str4, vuclst] && 
     StringContainsQ[StringTake[str4, {2, StringLength[str4]}], 
      vlclst],
    StrngAddAy2[str4],
    str4
    ];

  lst = StrngRule4 /@ StrngRule3 /@ StrngRule2 /@ lst;

  StringRiffle[lst]
  ]
POSTED BY: Updating Name

A very unproductive way of doing this challenge but I am not familiar with If statements in Wolfram

Attachments:
POSTED BY: Yuliia Maidannyk
Posted 6 years ago

Hi Yuliia,

Use pigTests from my answer above to test your solution.

pigTests // 
 KeyValueMap[If[(r = textpiglatin[#1]) == #2, True, Print["Expected: ", #2, " Got: ", r]; False] &]

Expected: If ethay ordway ontainscay onay owercaselay owelsvay, othingnay isway angedchay.

Got: If ethay ordway ontainscay onay owercaselay owels,vay othingnay isway anged.chay

It fails on the sentence with punctuation test.

POSTED BY: Rohit Namjoshi

Thank you. I fixed the code to account for punctuation and cleaned everything up a bit.

Attachments:
POSTED BY: Yuliia Maidannyk
Attachments:
POSTED BY: Yuliia Maidannyk

Thanks for the posts folks. We'll continue the discussion on the "Pig Latin" challenge here.

Follow the Wolfram Study Group discussions for "Programming Fundamentals Week 2" at https://community.wolfram.com/groups/-/m/t/1970834

Posted 6 years ago

Abrita Here's my solution to the PigLatin challenge, It works on all of the sample words and sentences given in the challenge, but when I try and upload it too the Wolfram Challenge Web page it says it runs too slow, but on my machine the timing is all but instantaneous. Any hints on what I've done wrong would be appreciated. I've updated the code, which appears to work, but not on the Wolfram Challenge Web page

PigLatin[text_String] := Module[{s = text},

  vlclst = {"a", "e", "i", "o", "u"};
  vuclst = {"A", "E", "I", "O", "U"};
  lst = TextWords[s];

  StrngReorder[strRO_] := 
   StringTake[strRO, 1 - StringLength[strRO]] <> StringPart[strRO, 1];

  StrngStartConsonant[strSC_] := 
   StringFreeQ[StringPart[strSC, 1], vlclst, IgnoreCase -> True];

  StrngProcess4[str_] := Module[{sg = str},
    sg = StringTake[sg, 1 - StringLength[sg]] <> StringTake[sg, 1];
    NestWhile[StrngReorder[#] &, sg, StrngStartConsonant[#] &] <> "ay"
    ];

  StrngRule2[str2_] := 
   If[StringStartsQ[str2, vlclst], str2 <> "way", str2];

  StrngRule3[str3_] := If[StrngStartConsonant[str3],
    NestWhile[StrngReorder[#] &, str3, StrngStartConsonant[#] &] <> 
     "ay", str3];

  StrngRule4[str4_] := If[
    StringStartsQ[str4, vuclst] && 
     StringContainsQ[StringTake[str4, {2, StringLength[str4]}], 
      vlclst],
    StrngProcess4[str4], str4
    ];

  lst = StrngRule4 /@ StrngRule3 /@ StrngRule2 /@ lst;
  lstjoin = lst[[1]];
  Do[lstjoin = lstjoin <> " " <> lst[[i]], {i, 2, Length[lst]}];
  lstjoin

  ]
POSTED BY: Stuart Reilly
Posted 6 years ago

Hi Stuart,

There are a few cases that your solution does not handle correctly. If you take pigTests from my solution above and run your code against those tests there are three failures.

pigTests // 
 KeyValueMap[
  If[(r = PigLatin[#1]) == #2, True, Print["Expected: ", #2, " Got:", r]; False] &]

Expected: eOchray Got:Ochre

Expected: eeAgray Got:Agree

Expected: If ethay ordway ontainscay onay owercaselay owelsvay, othingnay isway angedchay. Got:If ethay ordway ontainscay onay owercaselay owelsvay othingnay isway angedchay

POSTED BY: Rohit Namjoshi
PigLatin[x_] :=

 Block[{lowerVowels = {"a", "e", "i", "o", "u"}, consonants}, 
  consonants = {"B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N",
     "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "b", "c", "d", 
    "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", 
    "v", "w", "x", "y", "z", "A", "E", "I", "O", "U"};
  StringRiffle[Map[If[StringFreeQ[#, lowerVowels], #,
      If[StringContainsQ[StringTake[#, 1], lowerVowels],
       If[
        Total[Boole[
           StringContainsQ[Characters[#], PunctuationCharacter]]] == 0,
        # <> "way", 
        StringJoin[Drop[Characters[#], -1]] <> "way" <> 
         Last[Characters[x]]],
       If[
        Total[Boole[
           StringContainsQ[Characters[#], PunctuationCharacter]]] == 0,
        StringJoin[Reverse[TakeDrop[Characters[#],

        LengthWhile[
         Boole[StringContainsQ[Characters[#], consonants]], #1 == 
           1 &]
        ]]] <> "ay",
    StringJoin[Reverse[TakeDrop[Drop[Characters[#], -1],

        LengthWhile[
         Boole[StringContainsQ[Characters[#], consonants]], #1 == 
           1 &]
        ]]] <> "ay" <> Last[Characters[#]]]]] &, StringSplit[x]]]]

Cloud version of the code

POSTED BY: Arturo Silva
Posted 6 years ago

enter image description here

I feel like we are wrapping layer after layer, forming a snowball of code that I hope doesn't melt. This is "brakety" and "wrappery" hence I get lost in the brackets and can't visualize what is happening underneath very well. Having said that I find all this valuable and instructive!

POSTED BY: Aaron Moment
Posted 6 years ago
POSTED BY: Rohit Namjoshi

Daily Challenge (Day 3): Give "Pig Latin" a shot https://challenges.wolfram.com/challenge/pig-latin

We didn't get to patterns on Thrusday. We'll look at them tomorrow and then get back to the challenge.

Hi Abrita, Here's my code. It works!

PigLatin[x_] :=

 Block[{lowerVowels = {"a", "e", "i", "o", "u"}, consonants}, 
  consonants = {"B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N",
     "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "b", "c", "d", 
    "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", 
    "v", "w", "x", "y", "z", "A", "E", "I", "O", "U"};
  StringRiffle[Map[If[StringFreeQ[#, lowerVowels], #,
      If[StringContainsQ[StringTake[#, 1], lowerVowels],
       If[
        Total[Boole[
           StringContainsQ[Characters[#], PunctuationCharacter]]] == 0,
        # <> "way", 
        StringJoin[Drop[Characters[#], -1]] <> "way" <> 
         Last[Characters[x]]],
       If[
        Total[Boole[
           StringContaracters[#], PunctuationCharacter]]] == 0,
        StringJoin[Reverse[TakeDrop[Characters[#],

            LengthWhile[
             Boole[StringContainsQ[Characters[#], consonants]], #1 == 
               1 &]
            ]]] <> "ay",
        StringJoin[Reverse[TakeDrop[Drop[Characters[#], -1],

            LengthWhile[
             Boole[StringContainsQ[Characters[#], consonants]], #1 == 
               1 &]
            ]]] <> "ay" <> Last[Characters[#]]]]] &, StringSplit[x]]]]

[Cloud version of the code][1]

POSTED BY: Arturo Silva
POSTED BY: Arturo Silva
Posted 6 years ago
POSTED BY: Rohit Namjoshi
POSTED BY: Arturo Silva

Yes, absolutely. We'll send all the relevant links (to the videos and the download locations for the notebooks) in a consolidated email at the end of the week to all the registered attendees.

[WSG20] Programming Fundamentals Week 1

Attachments:
POSTED BY: Yuliia Maidannyk

A desktop version of the previous post:

Manipulate[
 Column[{Row[{Column[{Style["Release Title:", color], 
       EntityList[EntityClass["Movie", "StarWarsFranchise"]][[
        releaseNumber]]}], "  ",
     Column[{Style["Director:", color], 
       EntityList[EntityClass["Movie", "StarWarsFranchise"]][[
          releaseNumber]][EntityProperty["Movie", "Director"]][[1]]}],
      "   ",
     Column[{Style["Producer:", color], 
       EntityList[EntityClass["Movie", "StarWarsFranchise"]][[
          releaseNumber]][EntityProperty["Movie", "Producers"]][[1]]}],
     "   ",
     Column[{Style["Production Budgent:", color], 
       EntityClass["Movie", "StarWarsFranchise"][
         EntityProperty["Movie", "ProductionBudget"]][[
        releaseNumber]]}]}],
   Style["Cast and Roles:", color], 
   Grid@Partition[
     Column /@ 
      Transpose[{Keys[
         EntityList[EntityClass["Movie", "StarWarsFranchise"]][[
           releaseNumber]][EntityProperty["Movie", "CastAndRoles"]]], 
        First /@ 
         Values[EntityList[
             EntityClass["Movie", "StarWarsFranchise"]][[
            releaseNumber]][
           EntityProperty["Movie", "CastAndRoles"]]]}], 4]}],
 {releaseNumber, Range@10, ControlType -> Setter}, {releaseNumber, 
  Range@10, Slider}, {color, Purple}]

enter image description here

Posted 6 years ago

I can make a collage of the leading actors of each movie.

Here's the code for ten actors (based on Abrita's code):

Manipulate[ ImageCollage[PersonData[movie["Cast"][[Range[10]]], "Image"]],

{movie, EntityList[EntityClass["Movie", "StarWarsFranchise"]]} ]

That results in:

StarWars-Episode1

POSTED BY: Arturo Silva
Posted 6 years ago

POSTED BY: Stuart Reilly
Posted 6 years ago
POSTED BY: Colin Scully

enter image description here

POSTED BY: Yuliia Maidannyk

Daily Challenge (May 5): Make an interactive version of the visualization from the previous day that allows your reader to explore the data--select and compare various features against each other. (Explore a bit yourself and select a few meaningful properties for the list of choices you'd like to offer your reader; don't include ALL the entity properties of the Movie entity).

A simple snippet to get you started:

Manipulate[
 ImageResize[movie["Image"], Medium], 
 {movie, EntityList[EntityClass["Movie", "StarWarsFranchise"]]}]
Posted 6 years ago

An actual analysis or comparison of production costs should include the time value of money referenced to some date, otherwise the comparison is invalid... right?

Q: (I'm new to Wolfram curated datasets) Is there a document or notebook associated with each curated dataset that describes how the data was curated? And, like the "daily challenge" problem, how would we know if the money values are referenced to some year's dollars or are just the time value of money for the given date? Besides a document/notebook describing the curation process and source for datasets, it would be nice to have a separate document/notebook that describes the particulars of a given dataset (like how money values should be interpreted), etc.

POSTED BY: Dave McCollum

Good point.

So the the entities are part of the continuously updated Wolfram Knowledgebase also used in Wolfram|Alpha. Here are some of the data sources used for the knowledgebase: https://reference.wolfram.com/language/ref/entity/Source.html

You'll find more information about each entity on its associated documentation page. For e.g. https://reference.wolfram.com/language/ref/entity/Movie.html. The curated data can be a result of pulling in information from multiple sources and the specifics of the curation process are not usually included.

Meanwhile for the datasets on the Wolfram Data Repository you will find the "Source Metadata" at the bottom of each data resource that gives you more detailed information.

Posted 6 years ago
POSTED BY: Muhammad Ali

You should receive the links in the daily reminder email for the webinars. If you are not receiving those emails kindly write to wolfram-u@wolfram.com.

Hi Abrita, where can I access to the weekly quizzes and videos of the session? Can you give me any page link?

POSTED BY: Regina Cervantes
Posted 6 years ago
POSTED BY: Stuart Reilly
POSTED BY: Arturo Silva
POSTED BY: Arturo Silva
POSTED BY: Arturo Silva

Perfectly ok to copy paste code snippets. Notebook not needed.

Posted 6 years ago

POSTED BY: Tingting Zhao

Hi Valeriu, I had a DateListPlot in mind. But the fun of using the Wolfram Language is that there are so many ways of doing the same thing. And your chart highlights the information just as well. Thanks for sharing.

Sure, Abrita, with DateListPlot[] it's much more simpler:

DateListPlot[
 EntityClass["Movie", 
   "StarWarsFranchise"][{EntityProperty["Movie", "ReleaseDate"], 
   EntityProperty["Movie", "ProductionBudget"]}]]

enter image description here

Could you please post links to the quizzes mentioned in the session today. Thank you.

@Sviatoslav Archava could you please email wolfram-u@wolfram.com and we will send the link to you.

You can register for study groups at https://www.wolfram.com/wolfram-u/special-event/study-groups/

For this week specifically: sign up here

Posted 6 years ago

Please send the link of the study group to regster

POSTED BY: M al

Daily Challenge (May 4): A challenge in the spirit of "May the fourth be with you".

Chart the production budget against the release date of the Star Wars movies (from the WL EntityClass "StarWarsFranchise"). Which movie had the lowest production budget?

Posted 6 years ago

"Star Wars: The Clone Wars" 8.5 million USD

POSTED BY: rjehanathan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard