r/PowerShell • • Sep 18 '19

Parenting Through PowerShell

My 8 year old decided to pretend to be sick so he would get sent home from school the other day. So after we finished all the work the teach gave us, I decided to make him some extra work. Since they are learning double digit addition I wrote a quick script that will generate a page with 25 problems on it. I kept printing him off new sheets until the end of the regular school day.

I thought I'd share it in case anyone else has a 2nd grader who likes to play hooky. https://www.dowst.dev/homework-double-digit-addition-without-carrying/

Does anyone else have any examples of parenting through PowerShell?

229 Upvotes

67 comments sorted by

View all comments

Show parent comments

2

u/Lee_Dailey [grin] Sep 19 '19

/lee wonders ... is ka-splam insane, unsane, non-sane, or barely won a sanity/insanity roll freaky? [grin]

2

u/ka-splam Sep 19 '19 edited Sep 19 '19

Lol, I think I'm going mad spending so long trying to get this version working!

      {(⍪' +'),⊃⍵}¨1↓{⍵,⍣(100>+/⊃p)⊢p←⊂9+? 89 89}⍣{6=≢⍺}⊢⍬
   16     60     56     18     29 
 + 72   + 26   + 30   + 68   + 64 

It's fun though, in a way, like Regex is fun!

If this is the first nine numbers:

      ⍳9
1 2 3 4 5 6 7 8 9 

Then this is the addition table of each one, with each one:

      (⍳9) ∘.+ (⍳9)
 2  3  4  5  6  7  8  9 10
 3  4  5  6  7  8  9 10 11
 4  5  6  7  8  9 10 11 12
 5  6  7  8  9 10 11 12 13
 6  7  8  9 10 11 12 13 14
 7  8  9 10 11 12 13 14 15
 8  9 10 11 12 13 14 15 16
 9 10 11 12 13 14 15 16 17
10 11 12 13 14 15 16 17 18

And this is a bitmap on that table, of all the places where 10> value shown by a 1 (true), and 0 (false):

      10>(⍳9) ∘.+ (⍳9)
1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 0 0
1 1 1 1 1 1 0 0 0
1 1 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

And this is the coordinates (x, y) indexes into the matrix, where the 1 values are:

      ⍸10>(⍳9) ∘.+ (⍳9)
 1 1  1 2  1 3  1 4  1 5  1 6  1 7  1 8  2 1  2 2  2 3  2 4  2 5  2 6  2 7  3 1  3 2  3 3  3 4 
 3 5  3 6  4 1  4 2  4 3  4 4  4 5  5 1  5 2  5 3  5 4  6 1  6 2  6 3  7 1  7 2  8 1 

So those are all the pairs where the single digit addition would still be a single digit answer, no carrying. Smaller, simpler version.

Putting the same thing on both sides of a function can use ⍨ to echo it to both sides so (⍳9) ∘.+ (⍳9) -> ∘.+⍨ (⍳9) and the parens don't do anything there, so they can go..

Isn't there a certain regex-style novelty there?

1

u/Lee_Dailey [grin] Sep 19 '19

howdy ka-splam,

i've come to consider APL to be ... the equivalent of quantum mechanics. useful, interesting, bizarre, and a handy bit of evidence that really smart people tend to be more than slightly freaky ... [grin]

take care,
lee

2

u/ka-splam Sep 19 '19

Haha, yes I'd agree with a lot of that. I'm just hoping that if I go close enough, some of their smarts' dust will rub off on me :P

1

u/Lee_Dailey [grin] Sep 19 '19

[grin]

2

u/ka-splam Sep 19 '19

It's not working yet; Adám from Dyalog came up with 9+91(⊢,-)¨?5⍴90 to generate the pairs in about 3 minutes and 4 revisions, I've got a lonnggggg way to go. :D

2

u/Lee_Dailey [grin] Sep 19 '19

howdy ka-splam,

i hope you are having fun with it. [grin] i do enjoy digging thru a problem ... but APL is like an especially cryptic page of egyptian hieroglyphs.

take care,
lee