PyMath #4 - The Curious 2019 AIME 1 Problem 1 Exercise!

  Рет қаралды 8,721

Flammable Maths

Flammable Maths

Күн бұрын

Пікірлер: 108
@NPCooking69
@NPCooking69 3 жыл бұрын
*Make sure to check out the providers of the best Christmas present this year! :D **brilliant.org/FlammableMaths* Also, Christmas Merch :00000000 teespring.com/new-merry-christmath-golden-ra
@misterg3tr3kt11
@misterg3tr3kt11 3 жыл бұрын
how is this comment 4 hours old? 4 hours < 4 seconds?🤔🤔🤔
@angelmendez-rivera351
@angelmendez-rivera351 3 жыл бұрын
@@misterg3tr3kt11 The video could've been unlisted.
@misterg3tr3kt11
@misterg3tr3kt11 3 жыл бұрын
@@angelmendez-rivera351 yeah
@latefoolstalk676
@latefoolstalk676 3 жыл бұрын
Loving those nines that look like "g" because everyone knows π2 = 9 = g
@oferzilberman5049
@oferzilberman5049 3 жыл бұрын
If we say π=3 Then π²=9=g
@michaelempeigne3519
@michaelempeigne3519 3 жыл бұрын
pi squared does not = g
@michaelempeigne3519
@michaelempeigne3519 3 жыл бұрын
( 16*arctan( 1 / 5 ) - 4*arctan(1 / 239 ) )^2 is not equal to g
@minh9545
@minh9545 3 жыл бұрын
@@michaelempeigne3519 is this a joke? If it is not, you are clearly missing the point here.
@abcxyz4207
@abcxyz4207 3 жыл бұрын
Im so sick of hearing this
@OlliWilkman
@OlliWilkman 3 жыл бұрын
The main way to improve the Python code would be to loop over the characters of the string ("for digit in x"), that way you don't need to make a list nor use the range function. The most "pythonic" way to write that function would probably be the one-liner "return sum(int(digit) for digit in x)", which is short and also easy to see what it does immediately.
@OlliWilkman
@OlliWilkman 3 жыл бұрын
Another trick to help build big number strings like that is that you can multiply a string by an integer, so 321*"9" gives you a string of 321 nines.
@АлександрКовалев-о7я
@АлександрКовалев-о7я 3 жыл бұрын
Me: "Monkey Panic"
@АлександрКовалев-о7я
@АлександрКовалев-о7я 3 жыл бұрын
@@OlliWilkman kzbin.info/www/bejne/rmSpg6Stgqtpaq8 I wish you a happy watching
@mortadhaalaa5907
@mortadhaalaa5907 3 жыл бұрын
print(sum( int(d) for d in str(sum( int(k*'9') for k in range(1, 322)) ) ))
@gudmundurjonsson4357
@gudmundurjonsson4357 3 жыл бұрын
nice
@a-rod6336
@a-rod6336 3 жыл бұрын
You don't actually need to write range(1,322), range(322) does that by default
@mortadhaalaa5907
@mortadhaalaa5907 3 жыл бұрын
@@a-rod6336 if you run it, it gives an error because range(322) starts at zero and int(0*'9') is undefined
@a-rod6336
@a-rod6336 3 жыл бұрын
@@mortadhaalaa5907 that's right lol I suppose you would need to add 1 to k
@angelmendez-rivera351
@angelmendez-rivera351 3 жыл бұрын
Note 2: Let a = floor[ln(n)/ln(10)] + 1, and let 0 < n < m. If 10^a | m, then digitsum(n + m) = digitsum(n) + digitsum(m). However, in the video, this was not possible to use, because -321 < 0.
@adonisnunez6078
@adonisnunez6078 3 жыл бұрын
Here is my solution by using map() and a lambda funtion: suma = sum(list(map(lambda x: 10**x, list(range(1, 322))))) - 321 suma_digitos = 0 for d in str(suma): suma_digitos += int(d) print(suma_digitos) Greetings from Dominican Rupublic, I really like this chanel.
@gudmundurjonsson4357
@gudmundurjonsson4357 3 жыл бұрын
Tried optimising my own code with the tips from Olli Wilkman's comment: def digisum(x): s = sum([int(digit) for digit in str(x)]) return s number = 0 for i in range(1,321+1): number += 10**i - 1 print(digisum(number))
@OlliWilkman
@OlliWilkman 3 жыл бұрын
The square brackets around the for expression aren’t necessary. They create a list which you never use again and the sum function works with just the generator expression. Also why assign it to a variable rather than just returning it?
@OlliWilkman
@OlliWilkman 3 жыл бұрын
You could also write that second part as “number = sum(10**(i+1) for i in range(321))” if you want to be terse. If your loop is just doing one addition to an accumulator variable, you can usually replace it with a sum function with a loop expression.
@OlliWilkman
@OlliWilkman 3 жыл бұрын
Personally I’d create the number with number = int(321 * ”9”), which is a slightly cheeky way I feel.
@paulmoat7047
@paulmoat7047 3 жыл бұрын
slightly smaller code def digsum(x): return sum(map(int, list(str(x)))) print(digsum(sum((10**(i+1)-1) for i in range(321))))
@copperfield42
@copperfield42 3 жыл бұрын
13:17 flammy, you can iterate over the list itself, no need for this range thing (tho technically correct, is ugly as sin), or even over characters on the string, and a string is kind like a list of characters, so like this: def digsum(x): dig = 0 a = list(x) for n in a: dig += int(n) return dig but if you can call list on x, that mean you can iterate over it, so put it directly in the for loop: def digsum(x): dig = 0 for n in x: dig += int(n) return dig and that is the long way, the short way is using list comprehension method along side the sum function def digsum(x): return sum( int(n) for n in x ) and to eliminate the need to call str into your input beforehand, you can include into the function itself, in either of the versions def digsum(x): dig = 0 for n in str(x): dig += int(n) return dig def digsum(x): return sum( int(n) for n in str(x) )
@PapaFlammy69
@PapaFlammy69 3 жыл бұрын
Thank you David!!
@DatKid321
@DatKid321 3 жыл бұрын
Gave my own coding skills a go def digitsum(x): return(sum([int(digit) for digit in str(x)])) n = len(str(321)) print(321 - n + (n*10 - digitsum(321)))
@monkerud2108
@monkerud2108 3 жыл бұрын
i played you on lichess, big jens. this channel is still great
@angelmendez-rivera351
@angelmendez-rivera351 3 жыл бұрын
Consider N(n) = 9 + 99 + ••• + 9•••9, with the last summand having n digits, all digits being 9. Hence N(n) = (10^1 - 1) + ••• + (10^n - 1) = 1•••10 - n, where 1•••10 has n + 1 digits, with n digits being 1. Now, this is equal to 1•••10•••0 + (1•••10 - n), where 1•••10•••0 has x digits being 1, and y digits being 0, with x + y = n + 1, and 1•••10 has y - 1 digits being 1, with y - 1 being equal to the number of digits of n. Therefore, digitsum[N(n)] = n - floor[ln(n)/ln(10)] - 1 + digitsum(1•••10 - n). 1•••10 can be written as 10 + ••• + 10^(floor[ln(n)/ln(10)] + 1), since floor[ln(n)/ln(10)] + 1 is the number of digits of n. This is also equal to 10·(1 + ••• + 10^floor[ln(n)/ln(10)])= [10^(floor[ln(n)/ln(10)] + 2) - 10]/9. Therefore, digitsum[N(n)] = n - floor[ln(n)/ln(10)] - 1 + digitsum([10^(floor[ln(n)/ln(10)] + 2) - 10]/9 - n). This is the closed form for digitsum[N(n)]. In the special case of n = 321, the results of this video arise.
@angelmendez-rivera351
@angelmendez-rivera351 3 жыл бұрын
Note: the digital root of a number is not the same as the digit sum of a number. The digital root of N is 9, trivially, because the digital root is defined by iterating the digit sum function as many times as necessary until the output is a single-digit number. However, the digit sum merely adds the digits.
@Skrownia
@Skrownia 3 жыл бұрын
I see some people have mentioned the sum function, but I would also like to recommend looking into the map function it will make you able to calculate the digit sum like so "sum(map(int, x))" where x is your number as a string.
@niki3352
@niki3352 3 жыл бұрын
the digsum function can be a oneliner: def digsum(x): return sum(int(y) for y in x)
@gudmundurjonsson4357
@gudmundurjonsson4357 3 жыл бұрын
think you need int(x) but yeah, thats the nices way to do it i think
@TheMazyProduction
@TheMazyProduction 3 жыл бұрын
The whole program can be one line of code
@gudmundurjonsson4357
@gudmundurjonsson4357 3 жыл бұрын
@@TheMazyProduction doesnt look that nice tho
@maypiatt3766
@maypiatt3766 3 жыл бұрын
I think this is an AIME problem!! Except there just weren’t as many terms
@PapaFlammy69
@PapaFlammy69 3 жыл бұрын
Oh really? :0
@maypiatt3766
@maypiatt3766 3 жыл бұрын
@@PapaFlammy69 this is the AIME I 2019 problem 1
@maypiatt3766
@maypiatt3766 3 жыл бұрын
@@PapaFlammy69 oh and it actually was 321 terms too
@rupachakraborty3681
@rupachakraborty3681 3 жыл бұрын
Great video. Btw, which IDE were you using?(You are using black theme. I see, you are a man of culture as well.)
@dizmat.mp3
@dizmat.mp3 3 жыл бұрын
Bruh lmao is that an anime mousepad
@HAL-oj4jb
@HAL-oj4jb 3 жыл бұрын
Seems you're new to the channel lol
@zvxcvxcz
@zvxcvxcz 3 жыл бұрын
Python actually is appropriate here because of arbitrary length integers... It may be less trivial to code in other languages.
@path_selector
@path_selector 3 жыл бұрын
great video. combines 2 of my favorite things! math and programming :)
@PapaFlammy69
@PapaFlammy69 3 жыл бұрын
:)
@AlexandrBorschchev
@AlexandrBorschchev 3 жыл бұрын
you should create a recursive function too for fun
@dado070998
@dado070998 3 жыл бұрын
Yo papa what is that figure on your desk? Looks epic.
@dozzco2827
@dozzco2827 3 жыл бұрын
God I've been missing these videos!, Brilliant Python Math Problem! 👍
@devincustodio2258
@devincustodio2258 3 жыл бұрын
Hey have you thought about a recursive implementation for digsum? That would be kind of cool to write
@copperfield42
@copperfield42 3 жыл бұрын
you want it recursive? yeah sure, that is easy here you go: def digsum_r(n): if 0
@devincustodio2258
@devincustodio2258 3 жыл бұрын
@@copperfield42 that's what I wrote too
@bbblaesing
@bbblaesing 3 жыл бұрын
I posted a really stupid response earlier and realized I was summing 9^n for the sum of 1 to 223. I fixed it: def summer(n,g=9): gs=0 for i in range(n): nummer=0 for j in range(i+1): nummer += g*10**j gs += nummer return gs
@bbblaesing
@bbblaesing 3 жыл бұрын
answer = summer(223)
@robertstorlind2302
@robertstorlind2302 3 жыл бұрын
And we can use the theorem of the digit sum being congruent to the number mod 9 as a sanity check of the answer 342, right?
@HAL-oj4jb
@HAL-oj4jb 3 жыл бұрын
PyCharm is really a charm, my favourite IDE
@korigamik
@korigamik 3 жыл бұрын
Try thonny
@thaihm
@thaihm 3 жыл бұрын
Loved the lecture! 👍🏽
@mathssolverpoint6059
@mathssolverpoint6059 3 жыл бұрын
I solved this question in my head in 2 minutes
@Pneuma7
@Pneuma7 3 жыл бұрын
just what I needed, love u papa
@maxwellsequation4887
@maxwellsequation4887 3 жыл бұрын
Christmas = SIR ISAAC NEWTON's birthday Ophence
@bisheshadhikari6508
@bisheshadhikari6508 3 жыл бұрын
Awesome video!! Really enjoyed it.
@devinwoods641
@devinwoods641 3 жыл бұрын
If I’m looking to start learning more beyond highschool math where should I start with your videos?
@akshat9282
@akshat9282 3 жыл бұрын
isn't a digit dum supposed to be a single digit aur recursively doing the process on the number. I'm probably wrong but that's what I heard. calculating that would be really easy. take 9 common from the original number. you'll be left with (1+11+...1...1). since you took 9 common, the number is a multiple of 9 and so the digit sum is 9. also, you can use a very basic python one liner for what you did. this wasn't a v nice program daddy but still appreciated ❤️
@angelmendez-rivera351
@angelmendez-rivera351 3 жыл бұрын
No, that is a different function. What you are referencing is the digital root function, which is not the same as the digit sum function.
@Evan-ne5bu
@Evan-ne5bu 3 жыл бұрын
Man wtf, I've never been so early
@michaelempeigne3519
@michaelempeigne3519 3 жыл бұрын
sum of digits of a multiple of 9, will yield a digital sum of 9; so wouldn't it make sense that it be 9 regardless of length ?
@angelmendez-rivera351
@angelmendez-rivera351 3 жыл бұрын
The statement you wrote is incorrect. 99 is a multiple of 9, because 99 = 9·11, but digitsum(99) = 9 + 9 = 18, not 9. In this video, digitsum(N) = 342, not 9.
@michaelempeigne3519
@michaelempeigne3519 3 жыл бұрын
@@angelmendez-rivera351 but the digital root of those numbers are 9
@angelmendez-rivera351
@angelmendez-rivera351 3 жыл бұрын
@@michaelempeigne3519 The digitsum function and the digital root function are not the same. The digit root of these numbers is 9, but not the digit sum. So you are still incorrect per my comment.
@mehulborad2400
@mehulborad2400 3 жыл бұрын
10:09 Programmers be like : it and IDE not a EDITOR for God's sake
@chicken2896
@chicken2896 3 жыл бұрын
where did you buy your blackboard and for how much?
@PapaFlammy69
@PapaFlammy69 3 жыл бұрын
some 1.5k from some german manufacturer ^^'
@chicken2896
@chicken2896 3 жыл бұрын
@@PapaFlammy69 Thanks 🐐
@roeesi-personal
@roeesi-personal 3 жыл бұрын
I know this video is old but one liners are always nice so I want to share mine with everyone who will see this comment. sum(int(d) for d in str(sum(int('9'*j) for j in range(1, 322)))) It's not very efficient, but it's a simple python one liner, what did you expect?
@gapdragon01
@gapdragon01 3 жыл бұрын
"Three hundred twenty FIRST power"!!!!!!
@PapaFlammy69
@PapaFlammy69 3 жыл бұрын
:^D
@Chr0nalis
@Chr0nalis 3 жыл бұрын
Try out the visual studio code dark plus colorscheme for Pycharm. Nicest looking one that I've used so far. Darkula sucks balls.
@raiymshuak
@raiymshuak 3 жыл бұрын
I think I saw this in the AIME one of the last years
@matron9936
@matron9936 3 жыл бұрын
Hey saw ya doing it in discord, nice lemme watch dat video see if I solved it right.
@a_llama
@a_llama 3 жыл бұрын
I saw this problem on mu prime math!
@alwysrite
@alwysrite 3 жыл бұрын
please post more python videos
@69erthx1138
@69erthx1138 3 жыл бұрын
If this vid doesn't PROVE that arithmetic is the most difficult kind of mathematics, I don't know what does?
@angelmendez-rivera351
@angelmendez-rivera351 3 жыл бұрын
...it doesn't prove that. This exercise was surprisingly easy to solve.
@69erthx1138
@69erthx1138 3 жыл бұрын
@@angelmendez-rivera351 My post was a joke😁.
@brettstafford9665
@brettstafford9665 3 жыл бұрын
I solved this in like 3 minutes.
@ricardoparada5375
@ricardoparada5375 3 жыл бұрын
Relatable meme lmao
@MrRyanroberson1
@MrRyanroberson1 3 жыл бұрын
ok wtf youtube unsubscribed me from your channel??
@PapaFlammy69
@PapaFlammy69 3 жыл бұрын
wtf? why does it do that? ;_;
@MrRyanroberson1
@MrRyanroberson1 3 жыл бұрын
​@@PapaFlammy69 i don't even know! i noticed was because it was suggesting your vids to me... as a "new channel" to check out for some reason. honestly though i'm afraid for the channels i didn't notice...
@PapaFlammy69
@PapaFlammy69 3 жыл бұрын
well...
@djcoolvibes
@djcoolvibes 3 жыл бұрын
And if you keep applying digitsum, you will always end up with 9
@angel-ig
@angel-ig 3 жыл бұрын
Yeah, because "infinite" digit sum of n is n mod 9
@ezras7997
@ezras7997 3 жыл бұрын
Can you do tjis?!
@АлександрКовалев-о7я
@АлександрКовалев-о7я 3 жыл бұрын
def censored_sum(n): ---> s = 0 while n != 0: --2> s += n % 10 n //= 10
@АлександрКовалев-о7я
@АлександрКовалев-о7я 3 жыл бұрын
if I understand your problem it right
@Observer_detector
@Observer_detector 3 жыл бұрын
dude is that Putnam problem? intersting
@PapaFlammy69
@PapaFlammy69 3 жыл бұрын
Seems to be an AIME Problem! :)
@АлександрКовалев-о7я
@АлександрКовалев-о7я 3 жыл бұрын
Maybe, they not understand, that you solve the genial challenges, as Mathmann, but in our "world" we can solve ones another way?
@АлександрКовалев-о7я
@АлександрКовалев-о7я 3 жыл бұрын
10:50
@maxmusterman3371
@maxmusterman3371 3 жыл бұрын
daim i just cant watch your videos without headset because the cringe amount is too high in the first 30 seconds
@devan2604
@devan2604 3 жыл бұрын
first
отомстил?
00:56
История одного вокалиста
Рет қаралды 6 МЛН
Поветкин заставил себя уважать!
01:00
МИНУС БАЛЛ
Рет қаралды 6 МЛН
I run untested, viewer-submitted code on my 500-LED christmas tree.
45:17
Irish Math Olympiad | 2009 Question 3
20:14
Michael Penn
Рет қаралды 116 М.
Can you Measure the Speed of Light using Chocolate?
15:37
Flammable Maths
Рет қаралды 25 М.
New Breakthrough on a 90-year-old Telephone Question
28:45
Eric Rowland
Рет қаралды 110 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 49 М.
Solving one of the logic puzzles of all time!
20:34
Sheafification of G
Рет қаралды 17 М.
Solving An Insanely Hard Problem For High School Students
7:27
MindYourDecisions
Рет қаралды 3,5 МЛН
Exact Solution of the Nonlinear Pendulum [No Approximations, engis gtfo]
26:16
Solving the hardest question of a British Mathematical Olympiad
11:26
MindYourDecisions
Рет қаралды 695 М.