Coding Challenge #126: Toothpicks

preview_player
Показать описание


References:

Videos:

Related Coding Challenges:

Timestamps:
0:00 Introducing today's topic
1:00 The On-Line Encyclopedia of Integer Sequences
2:41 Toothpick number sequence
3:36 Start Coding!
4:00 Create a toothpick class
4:38 Each toothpick will have a length, center point, and direction
7:20 Write a show() function
8:11 Create an array list of toothpicks
9:03 Add a toothpick at the center of the canvas
10:50 Create an array list to hold the next generation of toothpicks
14:00 Each toothpick checks whether its end points are free
19:01 Add a new toothpick at a free point
19:55 Use mousePressed() to add toothpicks
21:32 Optimize by only checking the new toothpicks
23:38 Dynamically adjust the scale of the toothpicks
27:39 Adjust strokeWeight as scale changes
29:15 Print the sequence to the console
30:09 Other toothpick variations
30:45 Conclusion and creative possibilities

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

#toothpickpattern #fractal #omarpol #processing
Рекомендации по теме
Комментарии
Автор

I started watching your videos recently and I really DO admire your work. I like how you think and your ability to explain what you are doing. You are an inspiration to me and I believe to many more people. I hope I will become as good as you someday. Please keep up the videos and know that what you are doing is amazing!

XeartyBG
Автор

I love how Dan uses some of the YouTube channels I'm subscribed to in such a fluent way
And I watched all these videos, which makes it even better

avi
Автор

Ah yes, reading numbers the content I came here for

arnoudh
Автор

near the end when you are trying to make the lines thicker, you put the formula in the stroke function instead of the stroke weight function

katherinegaymes
Автор

In the for loop, when setting available to false, you could add a „break“ statement, which will increase performance a bit :)

innoberger
Автор

Huge optimization potential at 18:57 - you set available to false but don't break out of the loop, so when the amount of toothpicks gets large you have to check n^3 iterations which slows it down massively.

GalHorowitz
Автор

I think it might have been nice to have toothpicks know their parents and then figure out if there is any easy way to determine free edges based off parents to reduce the search space for non-payment connections.

moshadj
Автор

I discovered The Coding Train a few weeks ago, and I've watched at least 15 coding challenge since then. It's so great to discover such awesome algorithms thanks to you ! Greetings from France :)

arnaud
Автор

One easy optimization would be to break out of the loop in createA/createB when a collision is found

ancom-mb
Автор

This was the perfect video for showing tree data structures :)
Leaf nodes will be your "placeable/valid" toothpicks

aladaris
Автор

You're the reason I got into coding. ☺️

xhir
Автор

What a coincidence, I created this fractal just a day before you uploaded this amazing video!

morganstoodley
Автор

"There's no reason for me to have two separate functions here, but... why not?"

DRY principle maybe :P

soyz
Автор

I would hace made lenghts even. If you make a toothpick 2 units long, its ends would be +- 1. And every endpoint and middlepoint of every toothpick would be perfectly aligned with the grid.

Otakutaru
Автор

Daniel, you are better than my CS professors xD

nondeterministic
Автор

Is there any challenge about physics of atoms or molecules of specific matters? I mean, it may be so cool to visualize the real material reactions with their behaviours (behaviour means all the things about them like mol pH or magnetism or density etc.)

f.jideament
Автор

Release an album of just you reading number sequences. Children can use it as a lullabye, and they'll become math prodigies.

kevnar
Автор

At 18:40 you could probably make it more consise and explicit by simply returning instead chaining ifs. E.g.

return ( (ax == x && ay == y) || (bx == x && by == y) );

Alternatively:

boolean aIntersect = (ax == x && ay == y);
boolean bIntersect = (bx == x && by == y);

return (aIntersect || bIntersect);

MrMyhz
Автор

I just tweeted my program output to Daniel yesterday.

SafetyBoater
Автор

A vector (in maths, not in processing) is a point in space and a direction. This would be very useful for a toothpick object, instead of having 4 values and a direction.
Since you know the length of a toothpick, you only need to know where the toothpick starts. This means you can skip bx and by completely.
Since you know the toothpick will be in a right angle at all times, you only need to know the length of it and its origin point. The length is constant, since all toothpicks have the same length, this can therefore be hard coded.
You are now left with 2 integers, ax and ay, along with a direction. Two points making up a coordinate, that's exactly what a Processing Vector is, so convert the 2 integers into a single pvector and your toothpick now consists of a point in space and a direction. All the information you need!

Oh... look at that, your toothpick is a mathematical vector. Rename it to mvector or just vector and you can reuse it in any program where you need a mathematical vector!

morphman