Ok. I just don't want to get in trouble for breaking any rules.

# The MatHS Team Collab!

**t1_hopscotch**#84

Thanks for your concerns, both of you I only know that private messages aren't allowed, has there been any private communication allowed for collabs on the forum in the past or anything?

If not, I think I can ask THT about having only username and password in moderated private topics for collabs (and closing the topic after that, keeping other discussions to normal topics) — as definitely people are always setting up collab accounts, and they want to be able to log in themselves. I'd rather have them have a moderated, closed PM with the login details than people being griefed by hacking...

**t1_hopscotch**#86

Hmm these seems like a good workaround to approach it too.

I think I've seen people waiting to be on at the same time, posting login details then editing/deleting their post, but I guess it depends on timing too if someone else catches it...

**JonnyGamer**#87

@Liza, sounds good! I'll tag t1 or you the next time we make a PM for passwords so that you guys can block it. I really like the idea of the hidden topic because we can share passwords **much** more securely. Thanks!

**t1_hopscotch**#88

I'm not sure if Liza had told you yet but yay I would be able to moderate PMs for collab accounts – just allowing one post with the username and password, so I am going to close the other one.

**t1_hopscotch**#90

I didn't mean to make so much but I unexpectedly ended up getting the Pascal Triangle clone thing to work I wanted to work through it together with you all actually but of course we can still do that!!

this is the extreme version 63*63 grid:

I just gradually built on what I'd been jotting down previously (I initially meant to just test out if they would work) It is interesting seeing that breaking down a problem into parts can help

I also want to publish this on the MatHS Collab account too, maybe I can copy the code over.

The actual code is basically essentially the same as all the notes I've been jotting down

## I don't want to spoil the experience of working out for anyone, I found it fun to work through. but I love explaining stuff so there's stuff here if you like reading *still in progress*

# Idea:

Just a reminder that this is what we were interested in re-creating in Hopscotch

The Wikipedia caption says:

Each frame represents a row in Pascal's triangle. Each column of pixels is a number in binary with the least significant bit at the bottom. Light pixels represent ones and the dark pixels are zeroes.

## Message from me: don't look at this if you want to try work out for yourself what is going on :) I'm explaining what I didn't get at first

Each frame is a row in Pascal's triangle, where the row is centred and each column corresponds to a number.

The number in each column is represented in binary with the units digit at the bottom. Instead of 1's and 0's, the pixels are coloured yellow and black.

What numbers look like in binary:

```
1 = 1
2 = 10
3 = 11
4 = 100
5 = 101
6 = 110
7 = 111 etc.
```

And here I worked through each of the first five frames, or rows of Pascal's triangle, to illustrate:

# Initial plan:

So the plan starts off with this:

```
calculate the numbers in each row of Pascal's triangle
convert the number in each row to binary
colour pixels accordingly
```

yep, just the main steps here. not worried about how to do each of those yet before we write this, just writing them down first

Now, how to actually calculate the numbers in Pascal's triangle. Previously, I had been imagining doing it using lists for another programming language, and actually adding numbers to work out each row. Then the Wikipedia page reminded me of the combinations formula. We can use it find the number in each entry of Pascal's triangle.

So the updated line looks like this:

```
calculate the numbers in each row of Pascal's triangle using the combinations formula,
with n choose k being: frame_number choose column number,
where the leftmost column is 0 and the rightmost column is equivalent to the frame number
```

for working out numbers in binary, the row number will correspond to what power of 2

# ...in construction...

The other content down there is not ready

Getting closer to implementation details (working out the bits and pieces of limitations with code, and how things will actually be coded)

- numbering the rows and columns will help with calculations

Now how to actually calculate combinations and convert numbers to binary

The combinations formula (explained in the Wikipedia article from earlier) is`n choose k = n! / ( k! * (n-k)! )`

```
n choose k:
return n! / ( k! * (n-k)! )`
```

```
binary(number):
repeat subtracting the highest possible power of two from number
```

Breaking down the combinations formula further, this requires factorial. I explained implementing factorial in Hopscotch in another topic

- Creating the grid

I decided to label the middle column as 0 and have negative numbers going off one side and positive numbers going off the other

The basic idea I had in mind was this:

This was the numbering system I used for each of the clone row and column IDs:

You can see I used the row numbers to correspond to the powers of 2.

As for the column numbers, I decided to centre them on the middle number out of them all. (mid = `frame/2`

)

except, if you have an even number of total frame values, the mid value will be a non-whole number. I decided to shift it to make it a whole number (shift by 0.5 or -0.5).

[in progress, taking a break at the moment ]

Idea that I ended up using for colouring

```
set color to black initially
if pixel's row number should be filled in
colour pixel yellow
else
do nothing // pixel stays black
```

```
set pixel.on to false
set column number for pixels to (frame choose pixel k number)
convert column number to binary
if pixel.row_number is a 1 digit for the binary representation of the column_number
set pixel.on to true
```

Going closer to code level

```
self.on = 0 // 0 for false, 1 for true
set self.column_number to frame choose mid/2 + self.column_id
```

The code for high level idea:

For calculating the binary version of a number:

```
// Representing a number in binary
// Column number will be the number represented in each column
Set exponent to 0
Repeat while 2^exponent < columnNum
Increase exponent by 1
End
Set columnNumBinaryVersion to columnNum // using columnNumBinaryVersion for manipulating during calculations
Set exponentCandidate to exponent
Repeat times (exponent + 1)
If 2^exponentCandidate <= columnNumBinaryVersion and columnNumBinaryVersion > 0
Set columnNumBinaryVersion to columnNumBinaryVersion - 2^exponentCandidate
Set flagBinExponent to exponentCandidate
End
Increase exponentCandidate by - 1
End
// for clones
When self.rowID == flagBinExponent
Set self.on to 1
Set flagBinExponent to -1
End
```

The actual code:

Can you see it corresponding to the pseudcocode plan?

Whew, this is called a top down approach to development — you start off high level, focusing on your main aims without too much of the details, then gradually break each task into smaller parts and work more into the detail. this is sort of an abstract way of thinking and I learnt more about it in my computer science class. speaking of which, I'm sure Stradyvarious will be interested to see this (will tag once I'm done)

Also thinking about a specific case for a problem can definitely help when you're trying to work out addressing the general case

I miss doing this level of explanation and hanging around on the maths topics since I've gotten a bit busier on the forum

**MR.GAM3R**#91

I saw that on your profile, and it looks awesome! Also is pretty complex, will check out the code tomorrow

**t1_hopscotch**#92

ooh nah it can be straightforward to understand I am in fact in the process of explaining the design process, I think the actual code is less clear than my initial thoughts. nothing beats getting to think about the problem slowly yourself too, for me, but I love explaining so that will be there if you would like to look at that too :)

**JonnyGamer**#93

Wow! That's incredible! We should make a little left and right button to go forward or backward in the frames! That looks amazing! That is a very good programming challenge!

I see you added the Mandelbrot Set gif as the matHS collab avatar! Awesome! That should be the next thing we Code! (We need to decide what account we are using first)

**t1_hopscotch**#94

Hi JonnyGamer!!

Oooh that's an awesome idea!

The `frame`

variable in the project controls what frame it is, we'd just need to add buttons which change that when pressed. In fact, I'll get to trying to copy the code over (I'm going to try doing it using the project JSON)

Ooh that was actually @Hermione who'd put that I think the link wasn't working so I just fixed it

And that would be amaaazing to try think about coding

And yeah we've got 2 accounts, I'm not sure which to log into

**t1_hopscotch**#96

Hmm there is

- 'MathsHS Team' from @Hermione
- was the other one 'The MatHS Team', @JonnyGamer?

I will check on Hopscotch...

I can't seem to find them from searching. But was MatHS the name we had decided?

**t1_hopscotch**#97

At the moment @JonnyGamer will be away for a bit I think from his general topic

**t1_hopscotch**#100

Okay I found the account because I remember seeing it in my activity tab

Hopscotch search wasn't very helpful for finding either of the accounts...