Тёмный

Coding Challenge  

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

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

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 153   
@jespersvensson1964
@jespersvensson1964 5 лет назад
I love how you take the best from my favorite youtubers(SamrterEveryDay, Numberphile and 3Blue1Brown) videos and code it!
@TheRedKorsar
@TheRedKorsar 5 лет назад
Agree! I found this channel after all this three chanels. And now i'm watching this happy man, coding beautiful stuff :D I love programming!
@ilayws4448
@ilayws4448 5 лет назад
omg I just coded this when I saw you uploaded this video!
@ilayws4448
@ilayws4448 5 лет назад
You liked my comment!!
@idavid8128
@idavid8128 5 лет назад
I think you would like the Gauss series for pi, it converges very fast.
@ruler255
@ruler255 5 лет назад
DerivativeOfSenpi? Your name is so funny! I love it
@idavid8128
@idavid8128 5 лет назад
@@ruler255 Thank you !
@ffggddss
@ffggddss 4 года назад
And Ramanujan had a series that converges blazingly fast to π. Refinements of it are even a bit faster, and are used even now to compute those zillions-of-digits-of-π tables. What is the Gauss series for π? Fred
@Scotty-vs4lf
@Scotty-vs4lf 2 года назад
i just wrote that in js for fun, literally 3 iterations is more precise than javascript can handle
@AlgyCuber
@AlgyCuber 5 лет назад
the series can actually be interpreted as 4*pow(-1,k)/2k+1 from k = 0 to inf
@TheCodingTrain
@TheCodingTrain 5 лет назад
Ah, great point!
@AlgyCuber
@AlgyCuber 5 лет назад
ooooh you responded quick :D
@AlgyCuber
@AlgyCuber 5 лет назад
i'm watching standupmaths pi approximation right now xD
@giorgosd3624
@giorgosd3624 5 лет назад
Or like this, 4*(1-2*(k&1))/(2*k+1)
@mr.mirror1213
@mr.mirror1213 4 года назад
@@TheCodingTrain that is how we do mathematically in sequences
@hugolindberg4099
@hugolindberg4099 5 лет назад
Hey I like your videos! Can you program a rubiks solver plz?
@NolleEveraert
@NolleEveraert 5 лет назад
You can check code bullet videos. He made an awesome solver.
@hugolindberg4099
@hugolindberg4099 5 лет назад
SSnake I have and he iss soooooo good
@hugolindberg4099
@hugolindberg4099 5 лет назад
SSnake Thanks for the tip
@aryamaangoswamy179
@aryamaangoswamy179 5 лет назад
I had asked for this as well.
@Violet-tb8xo
@Violet-tb8xo 5 лет назад
your wish was granted.
@OonHan
@OonHan 5 лет назад
let pi = 4; *facepalm*
@aryamaangoswamy179
@aryamaangoswamy179 5 лет назад
more like let pi = ceil(PI);
@ruler255
@ruler255 5 лет назад
🤣🤣🤣🤣🤣🤣🤣🤣🤣
@DaveBriccetti
@DaveBriccetti 5 лет назад
I love the animation, and the idea of dynamically scaling it while showing a window of recent history.
@aryamaangoswamy179
@aryamaangoswamy179 5 лет назад
Woah 1 hour ago! (BTW I'll love Coding Train even if you posted 3.14159 hours ago)
@HakanTheUltimateHoca
@HakanTheUltimateHoca 5 лет назад
I prefer 2.718281828 hours
@ffggddss
@ffggddss 4 года назад
@@HakanTheUltimateHoca And I'm sure we'll get to that on February 71st! Fred
@Minty1337
@Minty1337 5 лет назад
cant wait to see pi-year episodes in 3141
@Elia2Tu
@Elia2Tu 5 лет назад
3141/5/9 will be a great day
@Dhukino
@Dhukino 4 года назад
3:50 instead of the conditions modify den --> den = (i * 2 + 3) * (-1)^(i+1). This way you multiply by -1 for even i and 1 for odd 1
@ffggddss
@ffggddss 5 лет назад
This (the alternating odd harmonic series) is probably the worst for actually calculating π. Each new digit requires 10 times as many terms as the previous digit!! But it's probably the best one for your purpose here, in which you graph how it's doing as it goes. Because any method that's halfway decent for calculation, would make for a very boring graph. It would slam down right on top of the actual value (to the precision of the graph) in just a few terms. But for one of those, you could graph the log of the absolute difference, yᵢ = log₁₀ |∑₁ⁿxᵢ - π| which is a bit more abstract, but would show the progress of convergence pretty well. As for the Ramanujan and Chudnovsky series, you'll need a multiple precision math library if you want to tackle those; each new term adds 8 or 10 more digits!! These are the ones used by the guys who try to set new records for the number of digits of π. I think they're up to over 10 trillion digits by now!!! There's the John Machin formula from 1706, ¼π = 4tan⁻¹(⅕) - tan⁻¹(1/239) using the Taylor series for arctan, but it's complicated to keep track of the number of terms of each of the two, to keep them in balanced precision. A better choice, that's a good compromise, would be to use the Taylor series for arcsin, to expand: π = 6sin⁻¹(½) Thanks for doing these videos - they're truly wonderful and inspiring! I love the way you can just keep coming up with a flow of ideas, then implement them and see the results right away! Fred
@TheCodingTrain
@TheCodingTrain 5 лет назад
Thank you for this thoughtful explanation!
@ffggddss
@ffggddss 5 лет назад
@@TheCodingTrain Is my math training showing? ;-) Anyway, this is a wonderful playground, and a learning tool, all rolled into one - it's exactly what I wish could have been available 50 years ago, when I was learning computer languages! Fred
@bastianroling1430
@bastianroling1430 5 лет назад
Could you make an Color-picker coding challange like wich Shows you the rgb value id love to see that. Loved the Video btw keep up the great work :)
@idk.5615
@idk.5615 5 лет назад
@the coding train... you could add den and then multiply den with -1 ...this makes den negativ every 2 loops because -def *(-1) =def and next loop den*(-1)=-den
@newsreaction9008
@newsreaction9008 3 года назад
It is stolen by Leibniz from Madhavan
@Adam-rt1lc
@Adam-rt1lc 5 лет назад
I am proud of myself. I know more digits of Pi then p5.js
@Starwort
@Starwort 5 лет назад
Me too _3.1415926535897932384643383_ _do I know more than you?_
@yashasvprajapati6851
@yashasvprajapati6851 5 лет назад
This is why I love programming! Doing crazy stuff and getting great and amazing results!
@andrewmasek2170
@andrewmasek2170 5 лет назад
Literally learned about the Leibniz series last week glad to see an application.
@filipbajraktari9099
@filipbajraktari9099 5 лет назад
Do that for number e. He has 3 formulas
@paulbraun4272
@paulbraun4272 5 лет назад
I did this once lol. It took like an hour to calculate ten digits of pi.
@ffggddss
@ffggddss 4 года назад
Guess how long it would take to get the next 10 digits? Fred
@lionpersia
@lionpersia 5 лет назад
I clicked on the video and paused it, then wrote the Leibniz approximation for pi in 2 lines of Python code: upper_limit = 1000000000 pi = sum([8 / (16 * m * m + 16 * m + 3) for m in range(upper_limit + 1)])
@KnakuanaRka
@KnakuanaRka 5 лет назад
lionpersia I’m pretty familiar with basic Python, but how does that work? I don’t see anywhere that would alternate sign, and I think you messed up the closure, because there’s no ].
@lionpersia
@lionpersia 5 лет назад
@@KnakuanaRka The alternating term (-1)^k / (2k+1) from k=0 to an upper_limit under the summation sign is both verbose and very slow. So, with a very simple acceleration trick, namely, summing the two consecutive terms into one (since k = 2m and then 2m+1), you get (-1)^2m / (4m+1) + (-1)^(2m+1) / (4m + 3) = (-1)^2m * [1/(4m+1) - 1/(4m+3)] = 2 * (-1)^2m / (16m^2 + 16m + 3) = 2 / (16m^2 + 16m + 3) through m=0 to an upper_limit. The leading 8 in my formula in my original comments comes from accounting the conversion of pi/4 to pi. The closing ] was omitted mistakenly, but I edited it in.
@KnakuanaRka
@KnakuanaRka 5 лет назад
lionpersia Sure enough.
@randominternetuser1681
@randominternetuser1681 5 лет назад
lionpersia You're missing a )
@lionpersia
@lionpersia 5 лет назад
@@randominternetuser1681 can you point out where?
@bapolino733
@bapolino733 5 лет назад
I love your Pi day specials. Pi is such a mysterious and interisting number
@davethedaemon9024
@davethedaemon9024 5 месяцев назад
Thanks! Just for giggles, I tried programming this in my SwissMicros DM42 which has quad precision (approx 34 decimal digits). I stopped it when the denominator went past 500,000 and got to 3.1415_88_. Yes, this series takes quite a while to get reasonably close to π. Going to 2,000,003 only gets one more decimal digit. I just bought an Arduino Giga and this would be a good test project.
@KakoriGames
@KakoriGames 5 лет назад
Hey, just so you know, any time you want to alternate between positive and negative terms you can just multiple everything by (-1)^n. When n is odd it will be negative and when n is even it will be positive, so you don't need that if-else statement.
@Reynevan94
@Reynevan94 5 лет назад
KakoriGames you know he will refactor this later...
@DaveBriccetti
@DaveBriccetti 5 лет назад
I wonder if JavaScript's power function would do that efficiently
@alexanderfl-ts3171
@alexanderfl-ts3171 5 лет назад
//For loop without if checks: double quaterPi = 0; for (long i = 1L; i < 123456789L; i += 4L) { quaterPi += 1.0d / i - 1.0d / (i + 2L); } double Pi = quaterPi * 4.0d;
@holyshit922
@holyshit922 9 месяцев назад
Leibniz series is convergent very slow We can get rid of if statement by bitwise operator pi += (1 - 2*(i&1))/den
@mrdouble
@mrdouble 3 года назад
Ok, I've always through pi was kinda boring,more of an Euler guy I guess but this is creepy creepy creepy. Thanks for the great vid
@RupertBruce
@RupertBruce 3 года назад
Use rational numbers instead of floating point. Most math libraries provide a Rational class.
@luczeiler2317
@luczeiler2317 2 года назад
coding challange 140! sooo close to 141 as in first 3 digets of pi. but still amazing video
@soejrd24978
@soejrd24978 5 лет назад
I was told there would be cake..
@krizzgamer8049
@krizzgamer8049 3 года назад
This series is given by madhawa an indian astrologer not liebniz
@toastyPredicament
@toastyPredicament 2 года назад
Sorry about the "this this dot" it was an emergency
@MinisBett
@MinisBett 5 лет назад
I did the same calculation you did at 5:04 but I get 3.525099011 after 40,000 iterations
@SimplyProd98
@SimplyProd98 5 лет назад
Instead of doing an if statement you could have done it with pow(-1, k). Great video !
@wandersonrodrigues123
@wandersonrodrigues123 5 лет назад
I am here because of the exercise 5 of chapter 15 of book Programming Principles and Practice Using C++ 2nd Edition by Bjarne Stroustrup.
@kdmq
@kdmq 5 лет назад
You could have just put div.html(pi*4) instead of putting 4 everywhere there was a 1.
@oblivionronin
@oblivionronin 4 года назад
For Leibniz technically you dont start negative. if you consider -1/3 being -1 * 1/3 the first term 1 is a positive 1/1 . Therefore you can simplify a lot of this by doing a for loop that will start you numerator at 1, multiply your numerator by -1 every loop and increment the denominator by 2 and always adding. so (1 * 1/1 = 1) + ( -1 * 1/3 = -1/3) + ( 1 * 1/5 = 1/5 ) which woudl translate to 1 - 1/3 + 1/5. looking at it this way will eliminate the need for if statement and multiplication of the denominator.
@michalbotor
@michalbotor 5 лет назад
i believe that we can improve the rate of convergence of this method if we accept the pi(n) to be pi(n) = (Leibniz(n) + Leibniz(n-1)) / 2, where Leibniz(0) := 0, instead of Leibniz(n).
@chromosoze
@chromosoze 5 лет назад
This guy is sitting here wondering how to cure cancer, while i am here being annoyed because in two minutes, the history list would be 7200 items long, which means that in two minutes, the computer would have to sift through 7200 items every 1/60th of a second. I recommend you to remove the history list altogether. There is another way to make it act similar to that without the list.
@doongi2001
@doongi2001 5 лет назад
I have a suggestion for a future coding challenge (I don’t know if you accept suggestions from youtube comments or at all, but if you do and this isn’t the right place for a suggestion then let me know where to put it): I found this thing called a swinging Atwood’s machine (en.m.wikipedia.org/wiki/Swinging_Atwood's_machine) and I’ve tried to make a simulation of it but I kinda bit off more than I could chew and just gave up out of confusion. Could you make one in a future coding challenge?
@TheCodingTrain
@TheCodingTrain 5 лет назад
Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues
@djxfade90
@djxfade90 5 лет назад
Javascript already has a native BigInt datatype developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
@TheCodingTrain
@TheCodingTrain 5 лет назад
Oh, thanks for this info!
@arukimedesu
@arukimedesu 4 года назад
I don't always insist on the pi, but I want to ask one reason why the angle is divisible by 360 °
@jdmeesey
@jdmeesey 5 лет назад
I was trying to build an Apollonian Gasket for my professor a while back but I ran into a problem with my method of circle inheritance. Pi, along with many other interesting patterns, is present in the Apollonian Gasket and it’d be really cool to extract that and other sequences from it.
@gedelaavima5005
@gedelaavima5005 3 года назад
sir where did you write coding?
@AniketSingh-zv8sm
@AniketSingh-zv8sm 5 лет назад
did anyone notice one of formulas was from Ramanujam sir.....
@1996Pinocchio
@1996Pinocchio 5 лет назад
Yes
@grainfrizz
@grainfrizz 5 лет назад
Amazing content, Dan, as always!
@ruler255
@ruler255 5 лет назад
Dan, you’re in my favourite youtubers list. It is *REALLY* hard to get in my favourite youtubers list.
@nagahumanbeingzooofparticl8836
.
@amaanmohammed6131
@amaanmohammed6131 4 года назад
I have never seen anyone this excited about math LMAO!
@paulhaupt5507
@paulhaupt5507 5 лет назад
Couldnt you use max(history) and min(history) for mapping the graph?
@ammaribrahim5756
@ammaribrahim5756 5 лет назад
How and when did you teach yourself coding?....I am a mechanical engineer grad and love ur work
@DrSpooglemon
@DrSpooglemon Год назад
How do we actually know what pi is in order to test the accuracy of an algorithm for calculating pi?
@rizzwan-42069
@rizzwan-42069 2 месяца назад
google
@mr_wormhole
@mr_wormhole 5 лет назад
Imagine if you had him as a calculus instructor in your university 😎 99 out of 10 would be better than most of trash talking instructors
@jellylovecz5475
@jellylovecz5475 5 лет назад
How about calculating PI by creating vertex unit circle, and Théb measuring its circuit :/
@DarkRedman31
@DarkRedman31 5 лет назад
I wonder if we use this graph and turn it into a sound if we get a snare or a simple bleep.
@mirlamontano6640
@mirlamontano6640 Год назад
awesome video as always!!
@alirazi9198
@alirazi9198 4 года назад
I made this yesterday and it showed up in my feed today suspicious
@PhilippeBaucour
@PhilippeBaucour 5 лет назад
I usually teach while loop in Python with this formula... Have a look to the Plouffe formula or Machina formula. One interesting thing to do is to use the recurrent version of such processes.
@anantmishra9813
@anantmishra9813 5 лет назад
Having too much 3B1B does this. 😛
@Pembolog
@Pembolog 5 лет назад
God forbid you don't do a video Brady hasn't done first
@Crainage1056
@Crainage1056 5 лет назад
CHALLENGE: MUNSELL COLOR SPACE. Every block is a different color because of the equation and so are all their positions in the 3d space. I have done this for my Math and Computer Graphics class and it looked very beautiful and was worth the Final Project for a student like me at the time. This was a group project and we all completed our assigned roles. I don't remember much but it was very interesting researching about how it worked. I'd love to see you complete this.
@TheCodingTrain
@TheCodingTrain 5 лет назад
Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues
@woutuuur
@woutuuur 5 лет назад
Lol I wrote this in Python for school
@amar2042
@amar2042 5 лет назад
From 2015 to 2019 lol u have got old
@Gamiboi612
@Gamiboi612 5 лет назад
Omg, someone did exactly the same thing I did on this year’s pi day!
@michaellonchar6863
@michaellonchar6863 5 лет назад
Do you ever think you'll do a series of Max/msp? I started using it recently and it's hard to find good tutorials like the ones you make for p5.js
@TheCodingTrain
@TheCodingTrain 5 лет назад
Check out ru-vid.com/show-UCHen0AQzqOMaPbpjYBhfsTA
@azyfloof
@azyfloof 5 лет назад
I vaguely remember years ago a method for calculating Pi based on Tan, or arc Tan? I'd love to see that done :D
@indiging8330
@indiging8330 5 лет назад
Azy this is it
@trygve741
@trygve741 5 лет назад
You're probably thinking of the Machin-like formula! Combining the Taylor series for arctan with Machin's formula one can approximate Pi fairly easily! en.wikipedia.org/wiki/Machin-like_formula
@PotatoKaboom
@PotatoKaboom 5 лет назад
Ohne das Internet aus der Dose wäre das Leben ein Irrtum.
@PS3centere
@PS3centere 5 лет назад
im sorry but thats silly. to get the odd numbers start the loop at i = 1 then for the next odd use 2i-1. to get the plus/minus use -1^(i-1)
@TheCodingTrain
@TheCodingTrain 5 лет назад
Yes, much better than what I did!
@akshaypratap2010
@akshaypratap2010 5 лет назад
Love you sir ji. You are a great tutor
@JE-cf5rk
@JE-cf5rk 2 года назад
Awesome
@axeleblaze6691
@axeleblaze6691 5 лет назад
I was waiting for you to do this !!!!!!!!! Thanks a lot
@dariuszwojcik9006
@dariuszwojcik9006 5 лет назад
Hey! You should implement the Shanks transformation to this series. It would be interesting and fun!
@TheCodingTrain
@TheCodingTrain 5 лет назад
Oh, great suggestion!
@BoringExtrovert
@BoringExtrovert 5 лет назад
This video is 13:04 long. Not pi but looks like pi enough for me
@HakanTheUltimateHoca
@HakanTheUltimateHoca 5 лет назад
It's -approximately- π+9.9
@soejrd24978
@soejrd24978 5 лет назад
Could u put the big decimal link in the description?
@TheCodingTrain
@TheCodingTrain 5 лет назад
This is what I've been using with Java. Let me try to make a Processing example with it and add soon! docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html
@Reynevan94
@Reynevan94 5 лет назад
I’d love to see how you sum natural numbers and get closer to -1/12.
@incredulity
@incredulity 5 лет назад
lmao
@johnrachidy5252
@johnrachidy5252 5 лет назад
lol you can't get closer to -1/12, it's the limit of the zeta function evaluated in -1
@Reynevan94
@Reynevan94 5 лет назад
John Rachidy That’s a joke, of course you are correct and besides, the sum of all natural numbers is divergent series and partial sums make no sense in getting closer to -1/12, because this limit cannot be calculated that way :)
@leram3198
@leram3198 5 лет назад
Hello! Do you have a video about basics in JavaScript?
@TheCodingTrain
@TheCodingTrain 5 лет назад
Try these! ru-vid.com/group/PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
@leram3198
@leram3198 5 лет назад
@@TheCodingTrain thank you very much
@freeshavaacadooo1095
@freeshavaacadooo1095 5 лет назад
Why didn't you just multiply the fraction by -1 to the power of i or i+1 to have it alternate between even and odd lol, then you could have avoided that if statement and not use modulus XD.
@TheCodingTrain
@TheCodingTrain 5 лет назад
Yes indeed, I should have done that!
@giorgosd3624
@giorgosd3624 5 лет назад
U can avoid modulus with a power of 2 by bitwise & (AND). e.g. N%8 == N&7 All muliples of 8, in binary representation end with 3 zeros (8=2^3), so by AND-ing with 7 (binary ..0111) u keep only the last 3 digits which are the modulus of that number. In general N%m = N&(m-1) when m is a power of two. Why would u want to do this? Division is slower than bitwise AND, however compilers already know those tricks and u wont get an extra benefit. Now to avoid that if-else branch, based on modulo operation, u can of course use pow(-1,k). But this requires an extra function call (assuming for this case, that the compiler doesnt optimize it). To avoid this, by looking at the code we see that when k is even or odd we want negative or positive sign respectively. k%2==0 ? We want -1 k%2==1 ? We want +1 By looking at the graph of the function we want, its easy to see its the line y=2*x-1, so instead of pow(-1,k) we can write 2*(k%2)-1.
@freeshavaacadooo1095
@freeshavaacadooo1095 5 лет назад
@@TheCodingTrain OMG YOU REPLIED TO MY COMMENT! DUDE, I JUST WANNA SAY I FREAKING LOVE YOUR VIDEOS, YOUR VIDEOS ON FIREBASE SAVED MY ASS AT A HACKATHON AND MY TEAM WON FIRST PLACE! THANK YOU SO DAMN MUCH!
@Nyamistaya
@Nyamistaya 5 лет назад
Very cool
@imagineexistance4538
@imagineexistance4538 5 лет назад
Try log(-1)/i
@ayatidubey8128
@ayatidubey8128 5 лет назад
Great as usual👍
@Dr.Waffles
@Dr.Waffles 5 лет назад
This channel so underrated
@1996Pinocchio
@1996Pinocchio 5 лет назад
is it?
@vivek3861
@vivek3861 5 лет назад
Cool !
@lorforlinux
@lorforlinux 5 лет назад
Awesome 😍
@ashiq3269
@ashiq3269 5 лет назад
yay
@tomnewton3553
@tomnewton3553 5 лет назад
You should do this on 22/7 (22nd of July) because 22 over 7.... never mind i just heard you say it.... xD
@fumui9386
@fumui9386 5 лет назад
Try to use ternary operator
@DaveBriccetti
@DaveBriccetti 5 лет назад
There is one and only operator with three inputs: the conditional operator. Calling it the ternary operator is like calling an octopus the octopod creature. Yes, I know. Everyone does it.
@sprajapati566
@sprajapati566 5 лет назад
You can store big numbers in string format, and treat them as an array or something, it's easy that way...!
@ChazyK
@ChazyK 5 лет назад
well you must than define all the calculations, like multiplication, addition or division.
@12kenbutsuri
@12kenbutsuri 3 года назад
Great vid, but this is more like 90%math 10% coding.
@lassenrbjerg8795
@lassenrbjerg8795 5 лет назад
Wow, I literally just wrote this in Python yesterday, now I guess I can see what I could do better
@fresnik
@fresnik 5 лет назад
Don't you mean PI-thon? :D
@MaxMustermann-pb3ny
@MaxMustermann-pb3ny 5 лет назад
I did that too
Далее
Researchers thought this was a bug (Borwein integrals)
17:26
Watermelon magic box! #shorts by Leisi Crazy
00:20
Просмотров 28 млн
50m Small Bike vs Car FastChallenge
00:22
Просмотров 4,1 млн
Coding Challenge 95: Approximating the Value of Pi
27:32
Leibniz Formula for pi, using the series of ln(1+z)
19:07
Coding Challenge 180: Falling Sand
23:00
Просмотров 938 тыс.
Calculating π by hand: the Chudnovsky algorithm
16:55
Просмотров 489 тыс.
Coding Challenge #90: Floyd-Steinberg Dithering
28:51
Просмотров 437 тыс.
Watermelon magic box! #shorts by Leisi Crazy
00:20
Просмотров 28 млн