Тёмный

Coding Challenge  

The Coding Train
Подписаться 1,7 млн
Просмотров 75 тыс.
50% 1

Опубликовано:

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 130   
@harsaroorabhyankar
@harsaroorabhyankar 6 лет назад
Don't ever stop programming and uploading Dan, please.
@reetard3708
@reetard3708 6 лет назад
wht abt when he dead? Hmmmmm
@justinward3679
@justinward3679 6 лет назад
Then Dan's AI will take over the channel.
@azyfloof
@azyfloof 6 лет назад
I hope I live long enough to see Dan code his own replacement :O
@mikasa3427
@mikasa3427 6 лет назад
You could give your topple command (x, y) parameters so it only checks the one middle pixel to see if it needs to be toppled, and if it does then recursively calls itself for the four pixels around it. It’ll run way quicker than having to check every pixel every time.
@portalsrule1239
@portalsrule1239 Год назад
implemented this and it made my topple function much faster. thanks for the idea (it helps with rendering too since you only need to render *changed* cells)
@CarelessMiss
@CarelessMiss 6 лет назад
8:36 Perfect vibrato! Edit: omg a heart!!
@SirajRaval
@SirajRaval 6 лет назад
Congrats on 500K! :)
@TheCodingTrain
@TheCodingTrain 6 лет назад
Thank you Siraj!
@ramseshendriks2445
@ramseshendriks2445 6 лет назад
yeah congrats dan!!
@jweipjklawe4766
@jweipjklawe4766 6 лет назад
Notice me sandpile
@tiileaf
@tiileaf 6 лет назад
Congrats on 500k! You deserve it Dan! :)
@hamzaa.8082
@hamzaa.8082 6 лет назад
the best channel on programming and cocaine effects on programmers.
@Victor_Marius
@Victor_Marius 6 лет назад
You can make it faster by "for" looping only from a minimum x up to a maximum x, and a minimum y up to a maximum y, avoiding looping through the yellow zone (and only through the "sand" rectangle)
@ryansaul6119
@ryansaul6119 6 лет назад
Started this challenge unlike any other... I had no idea how you could possibly recreate this visualization. Thanks for the great video, Daniel.
@kevnar
@kevnar 6 лет назад
I made the sandpiles go up to a maximum of 7 and fall off in 8 directions. And I used (256 / 8) * sandpiles(x)(y) for the coloring. It looks like some sort of alien lizard scales.
@phookadude
@phookadude 4 года назад
Wrote a version of this in QB64. Uses 2 arrays, one for the basic data and one for the update (the update just has the -4 and +1's accumulated for each pass) these arrays are then added together if the update array is non zero, also if the update occurs that's the only time it prints a pixel to the screen. It does 1000 generations (on 320x320 arrays) in about 3 seconds at the start and at 180000 generations that's about 6 seconds. Really cool to watch.
@giorgosd3624
@giorgosd3624 6 лет назад
To make this faster u could store a "previousPiles" 2D array and then just swap them in topple(), instead of making a new one every frame :p Another suggestion would be to have a variable like a sandpiles "mask" so u can change it easier, for example in the video its: [[0,1,0], [1,0,1], [0,1,0]] but others would be interesting as well!
@giorgosd3624
@giorgosd3624 6 лет назад
Congratz for ur 500k subscribers u deserve it :)
@l0m-dev
@l0m-dev 6 лет назад
Giorgos D Can't he put both if statements in one for loop with else?
@giorgosd3624
@giorgosd3624 6 лет назад
ShadowPlayz I think so, but instead of just assigning the num, should add to it (+=) like he did in the video, or else when its 3 for example (by propagation from neighbors) and u only assign the num to it, the 3 "sands" are lost
@AmericanOtter
@AmericanOtter 6 лет назад
You could probably do a topple in place with the current array in memory. I was thinking something like: -Iterate over each pixel - if num > 3 - pixels[num] - 4 - pixels[above, below, left, right num] += 1 - iterate again Obviously this is more pseudo code than real code and would likely be recursive, looking something like: Function Topple(){ - Iterate over each pixel - if num > 3 - pixels[num] - 4 - pixels[above, below, left, right num] += 1 If ([insert some sort of search for 4, maybe a binary search]) return 1 } Bool Loop = True While Loop: Loop = Topple() In topple return 0 if all pixels are less than 3, 1 if there are any pixels with a 4. Mind you I'm typing this out on mobile and thinking it through while typing it out so take it with some salt as I said recursive but then typed out a non recursive loop lol. Regardless, this would skip creating a new array in memory and do everything in place in the current array
@giorgosd3624
@giorgosd3624 6 лет назад
@AmericanOtter U cant do it with only one 2D array unfortunately.. Imagine there are consecutives "3" near a "4", your algorithm would do something like this (assuming neighbors on top/below): 2,2,4,3,3,3,3 --> 2,3,1,1,1,1,0 It will propagate the 4 many times in one topple pass and only on the direction of looping, the correct should be: 2,3,0,4,3,3,3
@prithwirajdutta3827
@prithwirajdutta3827 6 лет назад
Amazing Dan ! You are adding some real value in the world.
@anthonycannet1305
@anthonycannet1305 3 года назад
A faster way to get to the end sooner is to not do only 4 at a time, instead topple each cell entirely in the topple function. So in a grid 000/080/000 it would go straight to 020/202/020 instead of doing 010/141/010 in between. So instead of just subtracting 4 each time you divide it by 4 rounded down and put that into each neighboring cell, then get the remainder and put that back in the cell for the next generation
@Contra1828
@Contra1828 4 года назад
Note: this is kind of an advanced topic, but if you want a challenge and to do something nobody's ever done before (because there's not *that* many people writing sandpile programs): implement the HashLife algorithm for sandpiles. It produces a ridiculous, literally exponential speedup for game of life, and I see no reason why it shouldn't work for sandpiles.
@randomisedrandomness
@randomisedrandomness 6 лет назад
I did this before and found a few ways to make it faster: 1. Don't check pixels that the sandpile hasn't reached yet. 2. Don't subtract from a pixel that is divisible by 4.For example, if it has a value of 1024, zero it and add 256 to each surrounding pixel. (saves a looooot of steps) 3. A sandpile for a starting value of 4x is a sum of 4 sandpiles for a starting value of x. So if you want to see what a sandpile of 4096 looks like, calculate one for 1024, multiply every pixel by 4 and then continue with processing it. (not sure about that one, it was a long time ago) However, you cant use these steps if you want to see the sandpile grow, but only if you want to see the end result.
@TheCodingTrain
@TheCodingTrain 6 лет назад
Great tips, thank you!
@DiogoSantos-dw4ld
@DiogoSantos-dw4ld 6 лет назад
Has anyone got any nice sandpiles colouring suggestions? Now trying this out in p5.js :)
@TheCodingTrain
@TheCodingTrain 6 лет назад
I'd like to know too!
@eduar2tc904
@eduar2tc904 6 лет назад
This is my crazy man of code.
@AMTunLimited
@AMTunLimited 6 лет назад
You should make a video about FFT and convolution. You could do a bluring algorithm, or even this one (maybe, I'm actually not sure now that I think about it), much faster and more efficiently and I think it's a really good trick to have in your back pocket.
@TheCodingTrain
@TheCodingTrain 6 лет назад
Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues
@niranjannitesh
@niranjannitesh 6 лет назад
I love the way you teach. I'm learning ML through your RU-vid channel. Please when can I expect a video on Convolution Neural Nets?
@TheCodingTrain
@TheCodingTrain 6 лет назад
Sometime later this summer I hope!
@Minecraftgnom
@Minecraftgnom 3 года назад
I used the code and made it a hexagonal matrix with carry-limit of 5. The deskewed image isn't a perfect hexagon, but it still looks awesome! :D
@probablyapproximatelyok8146
@probablyapproximatelyok8146 3 года назад
On line 25, I think is should be nextpiles[x][y] += (-4);, not (num-4). Otherwise you may never reach an end. For example if you have 5 in one spot and 0s adjacent to it, with your current algorithm, there would then be 6 in that spot instead of 1, and then the amount of sand in that spot would just keep growing exponentially.
@kustomweb
@kustomweb 6 лет назад
Always use curly brackets, makes reading the code much easier
@jimmccloskey3601
@jimmccloskey3601 3 года назад
Is the grid swap truly necessary? To me, the line "sandpiles = nextpiles;" alone does the trick -- no need to set 'nextpiles' back to the original since it gets overwritten at the start of the topple() function. When I comment out "nextpiles = tmp;", I don't notice any difference in the result.
@BinaryReader
@BinaryReader 6 лет назад
Dan, you're a champ :D keep on keeping on !!!
@somewhatobsessedwithgaming9862
Now use a quadtree to find all the high value pixels to speed up the program.
@ThankYouESM
@ThankYouESM 2 года назад
LIKED and SUBBED. Looking forward to learning Fluid Simulation with it also splashing.
@DowzerWTP72
@DowzerWTP72 6 лет назад
I'm sure it's something someone will code themselves (maybe I'll give it a crack tomorrow), but it'd be cool to add a mousepressed event which adds a bunch of sand to the mouse position. Be interesting to see how the two expanding circles interact with one another.
@DowzerWTP72
@DowzerWTP72 6 лет назад
Ok so I decided to give it a go, and it is awesome! The different circles actually interact with one another. I am going to choose some better colours though because currently I have yellow, then less yellow etc etc!
@jantheil9239
@jantheil9239 6 лет назад
Congrats to 500 k!
@sarveshwarans8037
@sarveshwarans8037 6 лет назад
It looks so lovely
@CreepAnimation
@CreepAnimation 6 лет назад
The result is nice! But there is an error line 16 it should be "+=" just like line 25. Congrats on 500k btw ;)
@AmericanOtter
@AmericanOtter 6 лет назад
Would be interesting to try doing topple in place instead of creating a new array. Likely not faster but a challenge none the less
@RupertBruce
@RupertBruce 3 года назад
Using Conway game of life to do base 4 arithmetic 😎
@TylerDunphy
@TylerDunphy 6 лет назад
Can you do a coding challenge of Tetris! Like if you agree so he’ll see this comment!
@dielfonelletab8711
@dielfonelletab8711 6 лет назад
Go add it to the github page! www.github.com/CodingTrain/Rainbow-Topics/issues
@hydra4370
@hydra4370 6 лет назад
Tetris sounds like fun, perhaps a neural network that plays tetris (ha)
@inigo8740
@inigo8740 6 лет назад
Is that a 10x10?
@TylerDunphy
@TylerDunphy 6 лет назад
debblez22k5 petaminx*
@inigo8740
@inigo8740 6 лет назад
@@debblez I was joking, in case you couldn't tell. Do you not know the meme?
6 лет назад
"Not good with colours" and immediately writes down 255, 0, 255 for pink :D #humble
@TheCodingTrain
@TheCodingTrain 6 лет назад
It's the only one I know!
@Protoxide22
@Protoxide22 6 лет назад
couldn't the topple function have just one loop by just adding the values to the elements in the array? (and in case of toppling just using the code he already has in the second loop)
@wjrasmussen666
@wjrasmussen666 Год назад
Wonder what would happen if you used an image as the starting data...
@Saandy_
@Saandy_ 6 лет назад
???
@cassandradawn780
@cassandradawn780 4 года назад
LOL
@morpheus532
@morpheus532 4 года назад
lmfaooo
@alexfrasca673
@alexfrasca673 6 лет назад
Can you do a coding challenge where you simulate ocean tidal forces on an irregular perlin-noisy spheroid with a moon?
@totaltotalmonkey
@totaltotalmonkey 6 лет назад
Does the finished pile's parameter approximate a circle?
@gareginhayrapetyan8463
@gareginhayrapetyan8463 6 лет назад
Does someone has this code in Java(not the processing). I'm mainly interested in draw function.
@Pheonix1328
@Pheonix1328 6 лет назад
Is there a reason you don't use try/catch when dealing with edge cases? That's what I've been doing, so I'm just wondering if it's a good way of handling them.
@TBONE11
@TBONE11 6 лет назад
I would not recommend using a try/catch to handle these edge cases. Because throwing an exception is an expressive process. Also once the loop goes near the edge if could be throwing hundreds or even thousands of exceptions. As a general coding practice never use exceptions to handle flow control when you know what the problem is going to be and can be fixed completely with a single if statement. Also its much easier for someone to read. For example you see an if statement checking that an index is inside the array, that's very clear to see the reason, but if you see a try/catch around a block of code than it could be anything and maybe the try/catch may be for a method inside the block, but the reason for the try/catch is not as clear. Not to mention that an if statement will pretty much always be faster than the many thrown exceptions. Hope this helped.
@Pheonix1328
@Pheonix1328 6 лет назад
Thanks for all the info. When you said throwing exceptions is an "expressive" process, did you mean expensive? I do make sure to well document my code, so anyone looking at it would know what the try/catch it doing.
@TBONE11
@TBONE11 6 лет назад
Pheonix1328 Yes, sorry I meant expensive, throwing an exception is very expensive in terms of speed and when using for edge cases when you know the problem and when it will not just be throwing one exception but possibly thousands. Also for the case in the video if you did use a try/catch (not recommending) but you would need a try catch around each of the neighbours checks when a simple if statement would do. As a final note you mentioned that you comment and document your code which is great, but it's better if the code documents itself. As I mentioned, seeing an if statement that checks an array for out of bounds is very clear and doesn't even need to be commented of documented, but a try/catch around a block of code is not as clear.
@titiento
@titiento 6 лет назад
Ive wanted to make this challenge since the video on numberphile came out !!!
@yx4292
@yx4292 6 лет назад
Very nice video!
@mickyr171
@mickyr171 6 лет назад
Congrats on 500k Daniel :D Does anyone know a good resource to find these sorts of ideas? i love to watch the videos here then try and make them myself in python
@topa9487
@topa9487 6 лет назад
GitHub is where he goes
@ramizchili8024
@ramizchili8024 4 года назад
9:07 he instead puts ‘sanpils’ instead of ‘sandpiles’... Really?
@Xnoob545
@Xnoob545 4 года назад
Nobody: The Coding Train: *_-sAnPiLs-_*
@sarveshwarans8037
@sarveshwarans8037 6 лет назад
Marriage between patterns and processing
@robert3258
@robert3258 6 лет назад
hey dan, love the videos! Could you possibly remake any of your simple deep learning videos in tensorflow.js? Your explanations always help
@TheCodingTrain
@TheCodingTrain 6 лет назад
Working on it!
@twentytwentyoneishvkmemory7430
Sand: Bye universe
@tomonota1
@tomonota1 6 лет назад
Ukulele!!
@marcvd1
@marcvd1 6 лет назад
During the live stream I blurted something about doing this in one pass, in stead of two. Should be faster, right. So I did this but my implementation turns out to be slower (almost twice). I guess because I need more if statements do get the same behaviour. learned something :-)
@TheCodingTrain
@TheCodingTrain 6 лет назад
Oh, good to know!
@snowq2051
@snowq2051 6 лет назад
Hello there i need some help about games ios data
@JurajPecháč
@JurajPecháč 6 лет назад
Scribit - Turn your wall into an interactive canvas 100 % funded in 2 hours (kickstarter)!
@melwyn95
@melwyn95 6 лет назад
Maybe this is the algorithm behind the game chain reaction on android.
@user-ng9uk1vp8u
@user-ng9uk1vp8u 4 года назад
I wanna you make a code about particle life.
@albertkovtoun662
@albertkovtoun662 6 лет назад
Where can I download the coding train background?
@TheCodingTrain
@TheCodingTrain 6 лет назад
github.com/CodingTrain/website/issues/474
@skylerzhang1757
@skylerzhang1757 2 года назад
You named it sanpiles
@Ascor-bu2tr
@Ascor-bu2tr 6 лет назад
Would have been nice to do this in JavaScript with Tensorflow... Seemed like a job for tensorflow.js
@soumyadeepdas1199
@soumyadeepdas1199 6 лет назад
please do a coding challenge of low poly image generator with processing!!!!
@TheCodingTrain
@TheCodingTrain 6 лет назад
Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues
@seddikibelgacem2393
@seddikibelgacem2393 6 лет назад
sorry can you make a video about prototype inheretence thank you
@furrane
@furrane 6 лет назад
Booooring xD
@johncerpa3782
@johncerpa3782 6 лет назад
lovelyy
@boudewijnpleij
@boudewijnpleij 6 лет назад
Could you let this run overnight and speed up the result?
@TheCodingTrain
@TheCodingTrain 6 лет назад
Great idea!
@rickybloss8537
@rickybloss8537 6 лет назад
I made this a few years ago. :)
@imaginaryobligation951
@imaginaryobligation951 6 лет назад
7
@ban-dono4006
@ban-dono4006 6 лет назад
Which language is this plz ?!!!
@TheCodingTrain
@TheCodingTrain 6 лет назад
It's made with Processing (processing.org) which is Java.
@clipsus_clips
@clipsus_clips 6 лет назад
hi
@aaronpumm
@aaronpumm 6 лет назад
Its 7 Pieces of Sand not 6
@heekimsang
@heekimsang 6 лет назад
Anyone else hear CPG grey?
@CarelessMiss
@CarelessMiss 6 лет назад
only 5 comments, wee I'm early
@williambillemeyling5647
@williambillemeyling5647 6 лет назад
Hello Dan. On your website: thecodingtrain.com/Tutorials/. I think some of your tutorials are missing like nr 13 or from 2 to 6 for example. :) Just would like to have overview :)
@TheCodingTrain
@TheCodingTrain 6 лет назад
Yes, I'm really behind on keeping the website up to date. Would welcome contributions! github.com/CodingTrain/website
@siddhantjain2402
@siddhantjain2402 6 лет назад
wow third!
@Xnoob545
@Xnoob545 3 года назад
Swowoeikabbalah k
@mystuff8602
@mystuff8602 Год назад
UwU sandpile, notice me ^_^
@balsoft01
@balsoft01 6 лет назад
12:10 about as stupid as any other apple user I've seen so far in my life... WHY DO YOU NEED A SECOND ARRAY? THIS IS SO MEMORY&TIME INEFFICIENT! YOU JUST COULD DO ONE PASS ON AN INITIAL ARRAY! argh...
@balsoft01
@balsoft01 6 лет назад
And the problem at 16:00 wouldn't have happened if you've used the same array, duh.
@the0neskater
@the0neskater 4 года назад
Cool video but I must say that this code is pretty awful. Copying the entire array every time it topples is absolute insanity. I guess that isn't the point of the video. Just worries me how many people will be using these videos as a learning resource eh.
@robogaming3045
@robogaming3045 6 лет назад
1st like! (I literally just woke up 🙃)
@elox5
@elox5 6 лет назад
[insert unoriginal early comment here]
Далее
Coding Challenge 108: Barnsley Fern
17:07
Просмотров 126 тыс.
Coding Marching Squares
26:28
Просмотров 180 тыс.
Pure Comedy #ti13
00:38
Просмотров 213 тыс.
Vibes in Ney York🗽❤️! #shorts
00:26
Просмотров 20 млн
How can a jigsaw have two distinct solutions?
26:23
Просмотров 262 тыс.
What's special about 277777788888899? - Numberphile
14:24
Coding Challenge #89: Langton's Ant
20:58
Просмотров 156 тыс.
Coding Challenge 181: Weighted Voronoi Stippling
28:59
Просмотров 165 тыс.
Coding Challenge #61: Fractal Spirograph
44:19
Просмотров 77 тыс.
Coding Challenge #28: Metaballs
23:48
Просмотров 170 тыс.
Coding Challenge #127: Brownian Tree Snowflake
19:25
Просмотров 80 тыс.
Coding Challenge #90: Floyd-Steinberg Dithering
28:51
Просмотров 437 тыс.