‪@MikeBoyd‬

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ต.ค. 2022
  • The master of learning himself - ‪@MikeBoyd‬ - teaches me how to code in Python by writing a simple algorithm to find a sum of 3 cubes equal to the first 100 positive integers.
    The approach follows that of Miller and Woollett (1955). Read the paper explaining the method for yourself here: tomrocksmaths.files.wordpress...
    This video was recorded in Oxford when Mike came to visit to take a mock maths admissions interview. You can see how he did here: • Can I get into Oxford ...
    You can also watch Tom teach Mike how to pass the Oxford Maths Admissions Test (MAT) here: • How Hard is it to Get ...
    Learn more about Mike by watching him in an episode of ‘Maths Speed Dating’ with Tom here: • Maths Speed Dating wit...
    Thanks to Kim Boyd for filming.
    Produced by Dr Tom Crawford at the University of Oxford. Tom is an Early-Career Teaching and Outreach Fellow at St Edmund Hall: www.seh.ox.ac.uk/people/tom-c...
    For more maths content check out Tom's website
    tomrocksmaths.com/
    You can also follow Tom on Facebook, Twitter and Instagram @tomrocksmaths.
    / tomrocksmaths
    / tomrocksmaths
    / tomrocksmaths
    Get your Tom Rocks Maths merchandise here:
    beautifulequations.net/collec...

ความคิดเห็น • 107

  • @TomRocksMaths
    @TomRocksMaths  ปีที่แล้ว +14

    Learn more about Mike and his channel from his 'Maths Speed Dating' episode here: th-cam.com/video/BQnQsa-VDeg/w-d-xo.html

    • @nv1t
      @nv1t ปีที่แล้ว

      I find it really fascinating you never learned coding. It was standard in my math curriculum in uni as "Programming for Mathematicians" Coding in C/C++, Fortran and Python.

  • @mxlexrd
    @mxlexrd ปีที่แล้ว +261

    In Python, functions can read global variables by default. The global keyword allows you to write global variables.

    • @TiagoTiagoT
      @TiagoTiagoT ปีที่แล้ว +5

      Is that still the case in Processing's version of Python? I have a vague memory of something sorta like that being different in Processing; I'm not sure if it was exactly that though...

    • @mxlexrd
      @mxlexrd ปีที่แล้ว +4

      @@TiagoTiagoT I don't know, I've never used it personally. But in the video functions appeared to be able to access variables defined outside of their local scope.

    • @go-away-5555
      @go-away-5555 ปีที่แล้ว +2

      @@TiagoTiagoT It does, Processing uses Python 2.7.3 via the Jython interpreter but it should be able to do anything that "regular python" 2.7.3 can do

    • @go-away-5555
      @go-away-5555 ปีที่แล้ว +11

      For anyone wondering why you need the global keyword, it's because if you have a statement: "x = 123" Python doesn't know if you're trying to modify the global variable named x, or if you're trying to create a new local variable also named x. By default python assumes you want to create a new local variable, and the global keyword tells it otherwise. If you try to read the variable x and there is a local and global variable named x, Python will use the local variable. If no local variable exists it will use the global.

    • @Bobbias
      @Bobbias ปีที่แล้ว

      @@go-away-5555 there are other ways you could use to access the global variable x which don't use the global keyword (for example, you could examine the current stack frame, and access x through the dictionary containing the current stack frame's global variables) but they're almost universally a bad idea (and more work than just using the keyword).

  • @Subzerowins
    @Subzerowins ปีที่แล้ว +99

    This guy is the math friend we all needed but never had

  •  ปีที่แล้ว +45

    Around 25:00, the negative results (-100 to 100) are also OK, because you can simply reverse the sign of all three input values to find the positive version.

  • @tsuchan
    @tsuchan ปีที่แล้ว +9

    So glad you're doing this video. Thanks to you both. Really fascinating.

  • @ihave13digits
    @ihave13digits ปีที่แล้ว +13

    I hope you get into more code, it's basically a playground for math, and may even give you a deeper appreciation for it.

  • @mutaiib
    @mutaiib ปีที่แล้ว +2

    I loved the video!

  • @ryangatchel
    @ryangatchel ปีที่แล้ว +13

    Very cool video! Currently learning Python built a program that runs Collatz Conjecture. I shared the process.
    Hope you do more collaborations.

  • @Siopc
    @Siopc ปีที่แล้ว +7

    Two greats collaborating. 🙂

  • @martinshoosterman
    @martinshoosterman ปีที่แล้ว +70

    This has probably been pointed out before but the reason this code is so slow is because the draw function is only being called 30 times per second. The draw function is supposed to be drawing something on screen, it isn't supposed to be used as a while loop in the way you are using it. In a normal case you could probably run that function thousands if not tens of thousands of times per second.

    • @jonathanalvarez3063
      @jonathanalvarez3063 ปีที่แล้ว +1

      I am curious now. Do you know how to code that 'while' loop in the efficient way you said?
      No harm or sarcasm. I am just curious as to what your idea would look like, if you don't mind me asking.
      I hope you are having a good day.

    • @ThePayner1
      @ThePayner1 ปีที่แล้ว +1

      @@jonathanalvarez3063 you keep track of time and use that as the condition for the while loop. Little bit of math

    • @b1zzler
      @b1zzler ปีที่แล้ว

      @@ThePayner1 that's not even necessary, can just use an infinite while loop

    • @Jetpans
      @Jetpans ปีที่แล้ว +2

      @@jonathanalvarez3063 so the draw function is a processing specific function which is forced to loop 30 times a second (it's purpose is to draw a frame in 30fps), you usually don't use processing for computations.
      If you still wanted to use it for computation you would make your own while true loop inside which would run at "computer" speed and wouldn't let "draw" to run more than once.
      In general, it is weird to teach beginner coding in processing as it is meant for graphic visualisation which requires knowledge of basic looping and arithmetic.
      If you are trying to learn code, raw python is your best choice, just install python and use IDLE.

    • @jonathanalvarez3063
      @jonathanalvarez3063 ปีที่แล้ว

      @@Jetpans Thank you for the specific explanation. I appreciate it. :)

  • @IsYitzach
    @IsYitzach ปีที่แล้ว +6

    It ran at 12:07 because the variables were defined as global variables on the same level as draw() and setup().

  • @RandellP
    @RandellP ปีที่แล้ว +1

    Hay Doc Tom, Here in the Oregon US we have video poker and slot games in adult areas. Would you consider putting together lesson on the reality of this type of public gambling , how it works in maths and how it effects communities? I truly enjoy this activity. Help me understand the probability of the reality of this activity. Love and respect. Thanks.🙂🇺🇸🐟

  • @8o8inSquares
    @8o8inSquares ปีที่แล้ว +10

    As a software engineer, this put a smile to my face, well done!

  • @CorvanEssen
    @CorvanEssen ปีที่แล้ว +7

    I didn't know you could do Python in Processing, cool

  • @proshooters1
    @proshooters1 ปีที่แล้ว

    I would love to see you try the Leaving cert Higher Level Maths exam

  • @tlniec
    @tlniec ปีที่แล้ว

    I find it helps me a lot to pseudocode things prior to starting to write a script. Even Python can present some significant syntactic barriers to people who don't use it often!

    • @TomRocksMaths
      @TomRocksMaths  ปีที่แล้ว +1

      yes absolutely. I didn't do this, but I had thought about the maths beforehand so I knew what equations I needed to code etc.

  • @lilldiesel
    @lilldiesel ปีที่แล้ว +6

    Real teenager who has smoked weed once teaching how to do it to friends who haven't energy in this video.

  • @chrisgoodman1997
    @chrisgoodman1997 ปีที่แล้ว

    More learning Python with math challenges would be fantastic!

  • @Bobbias
    @Bobbias ปีที่แล้ว +6

    Watching you guys stumble on the xor/power syntax was funny. That's one of the silly gotchas. But on the bright side, Python actually has the ** operator rather than requiring you to call a function just to do simple exponentiation.

  • @go-away-5555
    @go-away-5555 ปีที่แล้ว +19

    To the folks complaining about globals, Processing doesn't allow the draw() function to take parameters, so you pretty much need to use globals.
    Technically you can manage your own draw loop using noloop() but your code will probably be less readable in the pursuit of trying to avoid globals.
    Globals can be bad code, and are often a sign of it. But there's nothing wrong with the way they're being used here.

  • @BirilliantSkyStar
    @BirilliantSkyStar ปีที่แล้ว

    Please also check out Nicomachu's theorem.

  • @Chris-fy1sm
    @Chris-fy1sm ปีที่แล้ว +3

    Slight problem with the code. On line 24 the variable r is being reset back down to 1 after finding any new cases. This causes the code to loop over the same set of numbers, and prevents it from finding any new ones. A simple removal of this line would fix it.

  • @enigma7791
    @enigma7791 ปีที่แล้ว +2

    Thing with coding of any sort is that you need to be doing it every day in your job or it all just goes or gets outdated very quickly. I worked in software dev before they off shored it all, now I would struggle to do anything. After 3 years away from that area it's all just gone.

  • @turboelephant6298
    @turboelephant6298 ปีที่แล้ว +3

    Good stuff, they both seem like lovely chaps, and one day because of Mike, I'm determined to do a wheelie. lol

  • @strafehelix
    @strafehelix ปีที่แล้ว

    im curious how you would perform in a Engineering exam, we have a maths unit im in my second year of BTEC studying Engineering (year 2) and some elements include product rule as an example. Just an ideas :)

  • @ANunes06
    @ANunes06 ปีที่แล้ว +1

    28:15 - Behold. Either the power of while/for loops or the horrible scourge of If/Else statements, depending on your point of view.
    See also: The Tsandere Simulator Conundrum.

  • @thrashshorts1703
    @thrashshorts1703 ปีที่แล้ว +1

    this dude is a math king and looks cool as fuck wtf i want be him

  • @yoyoyogames9527
    @yoyoyogames9527 ปีที่แล้ว +5

    theres some great numberphile videos about this problem, im pretty sure that numbers congruent to 4 and 5 mod 9 are impossible and its conjectured that every other number has infinitely many solutions, unproven though

    • @stephenbeck7222
      @stephenbeck7222 ปีที่แล้ว +1

      Right, surprised the numberphile videos and the effect that the channel’s exposure had on finding new solutions to this problem was not mentioned. Especially considering Tom has been on numberphile pretty frequently and you’d think he be familiar with the problem or at least the publications about it.

  • @JeanPhilippeMaquestiaux
    @JeanPhilippeMaquestiaux ปีที่แล้ว

    Can you share the final code ;)

  • @anshghatge2346
    @anshghatge2346 ปีที่แล้ว

    you should attempt an australian HSC level math exam prefferably the 4 unit math hsc

  • @dan_rad
    @dan_rad ปีที่แล้ว +4

    You picked this up so quickly! Congrats 👏
    Aside from the globals - I noticed you're printing out at the end 'l=', x, 'm=' etc - This can look a bit nicer if you use + to concatenate your string and int and remove the commas.
    E.g. x = 1
    print("The number is: " + x)
    Prints - "The number is: 1"

    • @logexpTommy
      @logexpTommy ปีที่แล้ว

      Can you concatenate a string and an integer tho? Shouldn't it be "The number is: " + str(x) ?

    • @paulyounger1190
      @paulyounger1190 ปีที่แล้ว +1

      ​@@logexpTommy When you try to print a variable in python it automatically calls the str( ) function on it, so they will all get stringified before they are concatenated.
      Also, even if you try to print out a variable whose class has no __str__ method defined then python will instead call the base object class' __str__ method, which will print out the memory address of the variable's instance, so worst case you would get a result like "The number is or something like that.

    • @karchkurrai4765
      @karchkurrai4765 ปีที่แล้ว +3

      I personally always use F-strings so something like print(f"The number is: {x}"). Makes my life easy with not needing to worry about concatenation or explicitly casting to a string.

    • @Essence1123
      @Essence1123 ปีที่แล้ว +1

      @@karchkurrai4765 except processing uses the long discontinued Python 2.7.3 (released 2012 FINALLY end of life 2020)

    • @TomRocksMaths
      @TomRocksMaths  ปีที่แล้ว +1

      Thanks for the tips!

  • @xelaxander
    @xelaxander ปีที่แล้ว +4

    2:00 Python has arbitrarily sized integers. You would be able to do it but it’ll be extremely slow.

    • @Bobbias
      @Bobbias ปีที่แล้ว

      There is an upcoming change which will add a default limit how many digits you can read from input or write to output as an integer (of course, you can disable that limit when necessary)

    • @xelaxander
      @xelaxander ปีที่แล้ว

      @@Bobbias I know. For numerical work it's ridiculously large, still.

  • @Ramon314
    @Ramon314 ปีที่แล้ว +3

    Keep in mind that also Mike is a beginner programmer. This might help him explain the concepts on a more basic level, though.

  • @yousufnoman7769
    @yousufnoman7769 ปีที่แล้ว

    Can you solve a mechanics paper from A level

  • @samsallee5924
    @samsallee5924 ปีที่แล้ว +3

    Very fun video!
    Wanted to clear one thing up. Around 24 minutes in you asked if you could write this line :
    else r=r+1, n=0, m=1:
    Mike told you that you can't, but you can although the syntax looks a little different. you could have written:
    else: r=r+1; n=0; m=1;
    So the colon comes directly after the else statement, and the operations are separated by semi colons instead of commas.
    However, DO NOT DO THIS. This is very bad practice even though possible. The only exception would be if your else statement is a single line, in which case you don't actually need the semi colon, so a line like:
    else: r +=1
    is generally acceptable but anything more than that becomes difficult to read

    • @Bobbias
      @Bobbias ปีที่แล้ว +3

      Yes, even though Python allows you to separate multiple statements on a single line with semicolons, there's almost no situations where that's reasonably acceptable.

    • @martinshoosterman
      @martinshoosterman ปีที่แล้ว +3

      can't you also write
      else:
      r, n, m = r+1, 0, 1

    • @samsallee5924
      @samsallee5924 ปีที่แล้ว +2

      @@martinshoosterman yes that's also valid. Python uses tuple packing and unpacking (there's probably an actual term for this).
      This means that internally, when you have:
      X = 1,2,3
      1,2,3 gets packaged into a tuple, and if you now print X you would get (1,2,3). Also if you print X[0] you would get 1. This is the tuple packing side.
      For unpacking, you could have something like this:
      myTuple = (1,2,3)
      X, y, z = myTuple
      Now x equals 1 and so on.
      When you put packing and unpacking together you can use:
      X,y,z = 1,2,3

  • @thermotronica
    @thermotronica ปีที่แล้ว

    there are dozens of us, Dozens!!

  • @mjustjeanette7026
    @mjustjeanette7026 ปีที่แล้ว +1

    Yes, I'd be yelling about globalisation too.

  • @scipio42
    @scipio42 ปีที่แล้ว

    I think I've never had to say "This is exactly why I hate python" as many times in the span of 10 minutes as when watching this video

  • @Bobbias
    @Bobbias ปีที่แล้ว +2

    Anyone complaining about global variables in a simple script like this has failed to think for themselves. In scripts of this size, global variables are fine. Not elegant, or any other nice descriptor, but acceptable nonetheless.

  • @dtri5592
    @dtri5592 ปีที่แล้ว

    great video, just one think i want to point out. i find it wierd for a mathematician to have 0 knowledge about programming nowadays. i mean he must have worked with matlab or atleast matematica at some point in his career.

    • @TomRocksMaths
      @TomRocksMaths  ปีที่แล้ว +1

      I did some very basic Matlab as an undergraduate but that was a while ago...

  • @paperclips1306
    @paperclips1306 ปีที่แล้ว

    I read the title as "my boyfriend teaches me how to code in python"

  • @cysliac
    @cysliac ปีที่แล้ว +1

    what IDE are are they using in this video?

    • @aquanomycena
      @aquanomycena ปีที่แล้ว +1

      It's called Processing. Mike mentioned it around 3:18.

    • @ajmash9745
      @ajmash9745 ปีที่แล้ว +8

      but for the love of god use vscode [works on all OS]

    • @cysliac
      @cysliac ปีที่แล้ว

      @@ajmash9745 i do use vs code personally but i just liked the ui of this one

    • @ajmash9745
      @ajmash9745 ปีที่แล้ว +2

      You can change eveything in vscode, literally. there ux modifies out there too.
      Plus you can write your own stuff using yo and typescript and it's so so simple it's scary.
      I've had been through 6 different IDEs in the last 15 years. Now theyve killed atom and the latest jetbrians offering and looks awful. Hot garabge. So this is the last nail in the coffin.
      Do yourself a favour. Make vscode your own. Your good for a long time.

    • @Omar-kl3xp
      @Omar-kl3xp ปีที่แล้ว

      Lol processing was my first IDE for Java I used back in my first year of University

  • @laalbujhakkar
    @laalbujhakkar ปีที่แล้ว +6

    16 min in and the code bro has not even started explaining the coding part. JTFC! Python was intended to be a scripting language. Just use it as such and code up a working solution, then you can do your code bro stuff

  • @noomade
    @noomade ปีที่แล้ว

    ... surely, Haskell...

  • @Bobbias
    @Bobbias ปีที่แล้ว +1

    I'm not furious you're using processing, I'm furious processing is using a hideously outdated version of Python.

  • @artr0x93
    @artr0x93 ปีที่แล้ว

    immediately teaches him to use globals 😬

  • @EduardoArena
    @EduardoArena ปีที่แล้ว

    PhD speedrun.

  • @jesse8521
    @jesse8521 ปีที่แล้ว +3

    All respect to my homeboy Mike but most of what he’s saying is not correct

    • @joshfriedman9775
      @joshfriedman9775 ปีที่แล้ว

      How so? Are you a computer programmer or coder

    • @jesse8521
      @jesse8521 ปีที่แล้ว

      @@joshfriedman9775 lol yeah

  • @davidplanet3919
    @davidplanet3919 ปีที่แล้ว

    You really need to think through the algorithm BEFORE you begin to code. It doesn’t really matter what language you choose for this simple code. Best practise once you have a working scrip is to throw it away and start again. But we’ll done for beginning to learn to code.

  • @warlord1981nl
    @warlord1981nl ปีที่แล้ว

    Loved the bit about "dont use global variables!!1!" haha, but my first advice would be: don't use python lol

  • @blender_wiki
    @blender_wiki ปีที่แล้ว

    You script in python you don't code in python. 😁😅😂😂

  • @thermotronica
    @thermotronica ปีที่แล้ว

    unnecessary observation. too much "tsking"

  • @Hyperserver
    @Hyperserver ปีที่แล้ว +11

    19:22: Did he really say "IF-LOOP"? and Mike answered "yes"? - i nearly fainted hearing that. "IF" is NOT a loop - it's a case decision (called "if-Statement"). Loops are "for...", "foreach", "while" .. and so on.
    It really hurts to hear "if-loop" - sorry (smile)

    • @ASOUE
      @ASOUE ปีที่แล้ว +1

      I thought it was pretty funny too lol. Mike wasn’t trying to help him
      Too much, he’s just letting him go
      Also Mike is pretty new to coding. Teaching helps you learn, Mike knows this very well lol

  • @talananiyiyaya8912
    @talananiyiyaya8912 ปีที่แล้ว +1

    Please erase this lesson from your mind and learn from a proper source Tom.

  • @philaskey9814
    @philaskey9814 ปีที่แล้ว

    Globals? That’s bad

  • @iWhacko
    @iWhacko ปีที่แล้ว

    Next time, get a highschooler who dissected a frog, teach you how to do heart surgery. get a proper teacher ffs

  • @signorducati8508
    @signorducati8508 ปีที่แล้ว

    and thats why i hate python

  • @mytube001
    @mytube001 ปีที่แล้ว

    So Python actually cares about white spaces!? That's inordinately stupid. And I thought it was supposed to be beginner friendly. I guess I'll avoid Python then.

    • @Omar-kl3xp
      @Omar-kl3xp ปีที่แล้ว

      Python is still beginner friendly ,I would still recommend it for beginners,my first programming language was Java for me,python is overall a lot easier compared to Java ,much less code .I would also recommend to learn Java too for Object oriented.

    • @mytube001
      @mytube001 ปีที่แล้ว

      @@Omar-kl3xp It's not if white spaces affect the code. That's just absolutely terrible. You should be able to format and indent (or not) however you want it, if that helps you read the code. It should in no way affect the functioning of the code!

    • @Omar-kl3xp
      @Omar-kl3xp ปีที่แล้ว

      @@mytube001 white spaces is not a big deal, as you learn python you will get used to it , it will became second nature , if you don’t want a programming language that care about white spaces learn Java .

    • @mytube001
      @mytube001 ปีที่แล้ว

      @@Omar-kl3xp This isn't about me. It's about the fact that Python is badly designed in that it cares about white spaces. That's unintuitive (as shown in the video above!) and less robust. If you move code as text from one place to another, white spaces could be handled differently, be altered or deleted, changing the entire code. That's not just bad, it's absolutely mind-numbingly stupid.

    • @ZombieBraintrust
      @ZombieBraintrust ปีที่แล้ว

      @@mytube001 I think the bigger problem is having large files and not using methods. Proper way to move code is to put it in a method and call the method. Not copy and paste. I am sure there are trade offs with white space. As a Java developer I am very strick about my indents. It makes the code easier to understand for myself. My secondary concern is how well the merge tool handles it. I suspect strict rules about whitespace works better with code merge.

  • @theoneandonly34
    @theoneandonly34 ปีที่แล้ว +1

    The IQ between these two much must be the highest in the world

  • @Devour_
    @Devour_ ปีที่แล้ว

    You need to chill with the Meth, my guy.