Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: automateaching -- part 2: proof of concept

by Tux (Canon)
on Sep 30, 2020 at 13:29 UTC ( #11122367=note: print w/replies, xml ) Need Help??

in reply to automateaching -- part 2: proof of concept

Feel free to use in the TIMTOWTDI section :)

Assignment should clearly state capitals or lower case. (assumed lower case below).

This was too much of "I could not rest" to resist:

use 5.18.2; use warnings; use charnames qw(:full); use Test::More; # 1: Create an array named @letters with 5 elements and fill it with f +irst 5 letters # of the English alphabet diag ("Assignment 1"); # Q: Capitals or lower-case? my $l = [ "a" .. "e" ]; my @letters; @letters = ("a", "b", "c", "d", "e"); is_deeply (\@l +etters, $l); @letters = ("a" .. "e"); is_deeply (\@l +etters, $l); @letters = map { chr } 0x61 .. 0x65; is_deeply (\@l +etters, $l); # Assuming ASCII @letters = map { chr ($_ + ord "a") } 0 .. 4; is_deeply (\@l +etters, $l); # Assuming ASCII @letters = map { lc } "A" .. "E"; is_deeply (\@l +etters, $l); @letters = split m// => "abcde"; is_deeply (\@l +etters, $l); @letters = map { charnames::string_vianame ("LATIN SMALL LETTER $_") } "A" .. "E"; is_deeply (\@l +etters, $l); @letters = map { chr charnames::vianame ("LATIN SMALL LETTER $_") } "A" .. "E"; is_deeply (\@l +etters, $l); @letters = map { substr "the quick brown fox jumps over the lazy dog", + $_, 1 } 36, 10, 7, 40, 2; is_deeply (\@l +etters, $l); @letters = (sort grep m/\S/ => split m// => "the quick brown fox jumps + over the lazy dog")[0..4]; is_deeply (\@l +etters, $l); @letters = (sort split m// => "the quick brown fox jumps over the lazy + dog")[8..12]; is_deeply (\@l +etters, $l); @letters = (sort unpack "(A)*", "the quick brown fox jumps over the la +zy dog" =~ s{\s+}{}gr)[0..4]; is_deeply (\@l +etters, $l); @letters = @{[ "a" .. "e" ]}; is_deeply (\@l +etters, $l); @letters = sort keys %{{qw( b 3 d 2 a 1 e 9 c 0 )}}; is_deeply (\@l +etters, $l); @letters = unpack "x3(a)*", pack "Q>", 418262508645; is_deeply (\@l +etters, $l); @letters = (unpack "(a)*",pack"Q<",435475931745)[0..4]; is_deeply (\@l +etters, $l); # Not one statement, so these won't qualify $letters[0] = "a"; $letters[1] = "b"; $letters[2] = "c"; $letters[3] = "d"; $letters[4] = "e"; is_deeply (\@l +etters, $l); @letters = ("a"); push @letters, "b", "c" .. "e"; is_deeply (\@l +etters, $l); @letters = do { eval q{"a"-"e"} =~ s/-/../r }; is_deeply (\@l +etters, $l); # 2: Remove the first element using a list operator and assign it to a + scalar variable diag ("Assignment 2"); my $a2 = [ "b" .. "e" ]; my (@a2, $first) = @letters; @letters = @a2; $first = shift @letters; is_deeply (\@letters, +$a2); is ($first, "a"); @letters = @a2; $first = splice @letters, 0, 1; is_deeply (\@letters, +$a2); is ($first, "a"); @letters = @a2; ($first, @letters) = @letters; is_deeply (\@letters, +$a2); is ($first, "a"); # 3: Remove the last element using a list operator and assign it to a +scalar variable diag ("Assignment 3"); my $a3 = [ "b" .. "d" ]; my (@a3, $last) = @letters; @letters = @a3; $last = pop @letters; is_deeply (\@letters, +$a3); is ($last, "e"); @letters = @a3; $last = splice @letters, -1, 1; is_deeply (\@letters, +$a3); is ($last, "e"); @letters = @a3; ($last, @letters) = ($letters[-1], @letters[0..($#letters-1)]); is_deeply (\@letters, +$a3); is ($last, "e"); # 4: Join these two removed elements with a '-' (using single quotes) +sign and assign # the result to a scalar named $result # Q: Why single quotes? WHY? I only use single quotes if I really have + to diag ("Assignment 4"); my $result; $result = "$first-$last"; is ($result, " +a-e"); $result = "$first@{['-']}$last"; is ($result, " +a-e"); $result = $first . '-' . $last; is ($result, " +a-e"); $result = join '-' => $first, $last; is ($result, " +a-e"); $result = do { local $" = '-'; "@{[$first, $last]}" }; is ($result, " +a-e"); $result = sprintf "%s%s%s", $first, '-', $last; is ($result, " +a-e"); done_testing;

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: automateaching -- part 2: proof of concept
by Discipulus (Abbot) on Oct 01, 2020 at 09:24 UTC
    Hello Tux,

    Thanks for sharing your TIMTOWTDIness :)

    Taking it seriously it demonstrate an important concept: learning is a path to follow, possibly alongside a teacher. Many of us can produce ten different ways to satisfy an assignment using perl. But this is not the point.

    As you noticed (lack of lower case specification for the array and the costraint of a single quote for the dash) it is very important to be clear in the assignement, making it also pedantic, and to be sure it imply the usage of already presented elements.

    A teacher must introduce concepts and verify how much students have incorporated them.

    Teaching, at first, is dedicated to fill ignorant's gap with notions and concepts (then teach how to learn and how to think, but is not my goal).

    So a course (in general but also mines) starts with assumed ignorance in one field, and step by step introduces elements and tests the overall students understanding.

    To produce PPI tests making all your example to be verified is an immane task, not worth even to plan. While teaching or learning the appropriate virtue is patience not hubris infact to learn is fondamental to recognize somethig superior who teach you.

    So I can add this note to my Perl::Teacher project:

    about assignements: -be sure to imply only already introduced elements, possibly refering +to the lesson where they were discussed -in the hints section put reminders to previous lessons -be pedantic in the assignement -possibly show up what was expected by tests when datastructures are i +nvolved (this can clarify an assignement)

    Tux!! out of the classroom!! :)


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11122367]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2021-04-15 01:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found