Coding Challenge 167: Ulam Spiral of Prime Numbers

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


References:

Videos:

Timestamps:
0:00 Welcome! Choo choo!
0:23 History of the Ulam Spiral
1:16 Diagramming the Spiral
2:18 Starting to Code
3:25 How and when do I rotate?
4:25 Coding the number spiral
7:00 Debugging!
9:40 Visualizing the spiral
12:22 What is a prime number?
14:31 Code to check if a number is prime.
18:57 Marking primes in the spiral
19:40 Porting to Processing (Java)
22:46 More references & examples

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

#primenumbers #p5js #javascript
Рекомендации по теме
Комментарии
Автор

For this setup, where we are explicitly checking primes one at a time sequentially, if we dedicate some memory to storing previous primes, and only check our list of primes from 2 to sqrt(value), this saves a massive amount of time.

ferociousfeind
Автор

I love the direction you're taking your channel, Daniel, very nice editing and explanation! You were the reason I started coding a couple of years ago and I honestly can't thank you enough! I am currently studying computer science at university, thank you for your wonderful channel!

Matdrox
Автор

O nie! Coding Train wybrał papieżową liczbę o 18:53, to znak :D

Kucharskov
Автор

While I appreciate all the machine learning videos, I really like simpler ones too: some cool math and fun visualizations. Loved this one!

zrodger
Автор

18:50 you picking out 2137 randomly out of all prime numbers hit me like a bag of bricks

Zayren_
Автор

Love the fact that you showed your thought process, mistakes and frustrations, since that is exactly what everyone goes through when trying to solve a problem and portrays a realisitic view of what programming is. There are so many programming „tutorials“ out there that show you the perfect answer to a problem and act as if everything leading up to the solution made sense and was obvious, showing no mistakes at all. Which might make you think that they guys are so much better than they actually are and that you are just bad at programming. Really informative and entertaining video.

sergiojimenez
Автор

16:30 it is enough to check whether the number is divisible by another number less than the square root of the former because if you find the latter one you can also find another factor which is greater than the square root of the first number.

PMA_ReginaldBoscoG
Автор

When I designed this, I created a grid that stored every number, and rotated around the spiral by always trying to turn left, and only kept going forwards instead if the spot to the left wasnt empty.

rearedcape
Автор

I just wanted to stop by and say that when I was in high school several years ago I watched these videos and it really piqued my interest in computer science in such an engaging way. That was one of my first introductions to this field and inspired me so much that now I'm about to graduate with a degree in computer science this spring. Now I'm going through these coding challenge videos again with a much deeper understanding and it's enjoyable to know what's going on this time. Thank you so much!

Tyler-gbil
Автор

I realize I'm a few months late on this but the number of steps you take on each side matches with the location of the perfect squares (1, 4, 9, 16, 25, and so on). If you had started your spiral with 0 in the center, then the perfect squares would be directly on the upper left and bottom right corners of the spiral. Since you started at 1, they're shifted 1 step back from the corners. Of course, in your project what you're doing is quite good but if you wanted to start somewhere ahead (say ignore the first 1000 numbers) you can figure out your position and step size by consulting the perfect squares (and their roots)

feronanthus
Автор

Just a quick optimization for your isPrime routine. Simply compare the squared numbers so you don't need the expensive sqrt call, i.e. i * i < value
Well, unless i^2 becomes to big for its underlying data type, of course.

sebastianzander
Автор

I am a senior software developer. Sometimes I don't focus on what you are coding while other times I don't understand what and how you are doing something? I come here to find fun in your videos which the way you teach. At the end of the day I always return taking a happy and smiling face. Never fail.

code_magpie
Автор

I love these simple coding challenges!! So informative.

jessetrevena
Автор

I love how you make so many pretty examples just so you can show them for a couple of seconds at the end. You put a lot of effort!

DenisovichDev
Автор

Every once in awhile this channel surfaces in my feed (yes, I'm subscribed). I always feel so uplifted after watching his videos. Daniel's enthusiasm is contagious.

JesseSteinfort
Автор

I actually did that exact spiral algorithm on my own one day. I was making a game where a unit had to brute-force explore every tile on a map. That was the algorithm I came up with.

kevnar
Автор

The amount of knowledge that is going into these videos is just phenomenal.
When he calls out his own mistakes and makes it more fun to solve it is just amazing to watch

CuriousWithOscar
Автор

Prime numbers are amazing, there is always something to learn from them

UnaLuz
Автор

You’re like a second web development teacher for me. I attend university and I’m in a p5js-based web dev class. you’re the professor i never knew i needed.

kinbeatss
Автор

16:26
Speaking of efficiency, you could save the primes found in an array and just check the modulo with those already found primes.
You don‘t need to check if a number is divisible by 12, if you know that it isn‘t divisible by 2 or 3.

Lotschi