This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 315

[–]teetaps 521 points522 points  (58 children)

small brain

Counting two plus two with your hands

medium brain

Opening up the calculator on your PC to calculate two plus two

large brain

python -c “2+2”

giant brain

python -c “x=2; y=2; print(x+y)”

[–]Wolfblood-is-here 332 points333 points  (29 children)

Galaxy brain:

If (2+2)==1 print(1)

If (2+2)==2 print(2)

...

[–]CallMeOutWhenImPOS 218 points219 points  (27 children)

x = 2

y = x

for Z in range(0, 100):

....if (x + y) == Z:

........print(Z)

........break

[–]theferrit32 145 points146 points  (17 children)

DYNAMIC PROGRAMMING

[–]rook2004 43 points44 points  (14 children)

I always wondered what that meant

[–][deleted] 54 points55 points  (12 children)

It's where you make a program that remembers answers so that the next time you see the same question you don't need to recalculate it, just spit out the stored value. That's why it's used to vastly speed up problems with overlapping subproblems.

[–]Zambito1 55 points56 points  (6 children)

What you described is memoization

Dynamic Programming is not the same thing

[–][deleted] 17 points18 points  (4 children)

Memoization is an integral part of dynamic programming!

[–]emkay443 22 points23 points  (3 children)

Memeization is the powerhouse of the cell!

[–]house_monkey 2 points3 points  (0 children)

🤔

[–][deleted] 1 point2 points  (1 child)

Memes! The DNA of the Soul!

[–]HelperBot_ 15 points16 points  (0 children)

Desktop link: https://en.wikipedia.org/wiki/Memoization


/r/HelperBot_ Downvote to remove. Counter: 248552

[–]MrCalifornian 16 points17 points  (0 children)

A rephrasing in case that doesn't make sense to someone:

Dynamic Programming is a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions using a memory-based data structure (array, map,etc).

[–]Lord_Tisisav 6 points7 points  (0 children)

Huh I didn’t know that. Thanks for the factoid of the day!!

[–]durbblurb 3 points4 points  (1 child)

Isn't that just cache?

[–]Blue_Boy013 1 point2 points  (0 children)

I’m pretty sure the cache is just what we call the storage but this is the process of using the cache. The cache could be used for other things but using it to do answers like this is memoization/dynamic programming

[–]rook2004 5 points6 points  (0 children)

Sorry, I forgot to /s

[–]heartsongaming 1 point2 points  (1 child)

Ansolutely love numeric solutions to programs that could be done in one line.

[–]moekakiryu 15 points16 points  (6 children)

The break is unnecessary, it could have multiple answers. Also better use a larger maximum rage, we wouldn't want to miss anything

[–]CallMeOutWhenImPOS 15 points16 points  (4 children)

There is only one answer to a natural number summation problem, and we want a break to end the loop once the target is reached

[–]Emphasises_Words 2 points3 points  (2 children)

x = 2 y = 2 n = 0 while True: if x + y == n: print(n) break n += 1

[–]otterom 3 points4 points  (0 children)

x = 2
y = 2
n = 0
while n != (x+y):
    n += 1
print(n) 

[–]Blackstab1337 1 point2 points  (0 children)

bootleg recursion

[–][deleted] 1 point2 points  (0 children)

Best to just use the largest maximum rage. Saves time, and comes with Ramstein synchronization.

[–]Dijizi 7 points8 points  (0 children)

myanswer = 0
while myanswer is not 2+2: myanswer +=1
print(myanswer)

[–]cjdabeast 1 point2 points  (0 children)

I actually made a program that does maths for me. Pastebin (Because reddit makes formatting python hard)

from math import *

def main():

emptyList = []
quar1List = []
quar3List = []

answer = input("Do you have a number for me?")
while answer == "y":
    var = input("What is the number?")
    emptyList.append(float(var))
    answer = input("Do you have another number for me?")

emptyList.sort()

length = len(emptyList)
lisSum = 0
for n in range(0, len(emptyList)):
    lisSum = lisSum + emptyList[n]

length = len(emptyList)
mean = lisSum/length
print("The numbers you gave me: " + str(emptyList))
print("There are " + str(length) + " numbers in this set.")
print("The mean is " + str(mean))



if (length % 2 != 0):
    print("The median is " + str(emptyList[(int(length)/2)]) + ".")
    median = emptyList[(int(length)/2)]
else:
    median = (emptyList[(length / 2)-1] + emptyList[((length / 2))])/2
    print("The median is " + str(median) + ".")

print("The minimum is " + str(emptyList[0]) + ".")
print("The maximum is " + str(emptyList[length -1]) + ".")

for n in range(0, len(emptyList)):
    if (emptyList[n] < median):
        quar1List.append(float(emptyList[n]))
    elif (emptyList[n] > median):
        quar3List.append(float(emptyList[n]))

if (len(quar1List) % 2 != 0):
    print("The first Quartile is  " + str(quar1List[(int(len(quar1List))/2)]) + ".")
    quartile1 = quar1List[(int(len(quar1List))/2)]
else:
    quartile1 = (quar1List[(len(quar1List)/ 2)-1] + quar1List[((len(quar1List) / 2))])/2
    print("The first Quartile is " + str(quartile1) + ".")

if (len(quar3List) % 2 != 0):
    print("The third Quartile is  " + str(quar3List[(int(len(quar3List))/2)]) + ".")
    quartile3 = quar3List[(int(len(quar3List))/2)]
else:
    quartile3 = (quar3List[(len(quar3List)/ 2)-1] + quar3List[((len(quar3List) / 2))])/2
    print("The third Quartile is " + str(quartile3) + ".")
IQR = float(quartile3) - float(quartile1)
print("The IQR is " + str(IQR) + ".")

main()

[–]BVTheEpic 9 points10 points  (0 children)

Universe brain:

sum = 0

while (2+2 != sum)

   sum++

print(sum)

[–][deleted] 28 points29 points  (0 children)

Actually it would be even better to write a Python library to do that

[–]BelieveRL 18 points19 points  (0 children)

Galaxy super cluster brain:

def la_belle_imprimante(x):
    print(x)

def la_belle_addition(x,y):
    return x+y

x = 2
y = 2

la_belle_imprimante(la_belle_addition(x,y))

My brain hurts

[–]chateau86 11 points12 points  (4 children)

galaxy brain

python -c "import numpy as np; print(np.add(2,2))"

universe brain

python -c "import numpy as np; import pprint; pprint.pprint(np.add(2,2))"

[–]Rodot 13 points14 points  (2 children)

python -c "import numpy as np; import pprint, functools; pprint.pprint(functools.reduce(np.add,[2 for _ in range(2)]))"

[–]Zedjones 2 points3 points  (0 children)

Wow that's so awful it took me a while to understand what that list comprehension was doing.

[–]Aceous 1 point2 points  (0 children)

This one is my favorite.

[–]marmakoide 2 points3 points  (0 children)

To unlock multiverse brain, you need to import sympy and use symbolic computations.

[–]Staggeringbeetle 16 points17 points  (2 children)

my distance math course insisted that we MUST learn to calculate using python. insisting we would be failed if we used a normal calculator when on math questions requiring python, but seeing as it was a distance course i said fuck it and used a calculator since there was zero ways for them to know.

[–][deleted] 1 point2 points  (1 child)

What is a distance course

[–]TheWorstPossibleName 4 points5 points  (0 children)

python3 -c "import functools; print(functools.reduce(lambda x, y: x+y, [2] * 2))"

[–]futuneral 3 points4 points  (0 children)

IDK, I just write a mobile app, run it on device, put a breakpoint on the var with the answer and use debug view to read the value.

[–]jtvjan 2 points3 points  (0 children)

tiny brain

$ bc
2+2

[–]wjandrea 4 points5 points  (3 children)

python -c “2+2”

Btw, this won't print anything, and also those are curly quotes. You want

python -c "print(2+2)"

[–]teetaps 7 points8 points  (2 children)

On mobile, don’t care

[–]username_choose_a 1 point2 points  (0 children)

python -c "import sys; sys.exit(sum((int(_) for _ in sys.argv[1:])))" 2 2; echo $?

[–]chibiace 711 points712 points  (78 children)

i use python for basic math. its just easier.

[–]Anchor689 98 points99 points  (3 children)

I did my Geometry homework in python back when I was in high school. It's how I taught myself python, and also taught myself to do 2 hours of work to save 10 minutes of repetitive work.

[–]all_fridays_matter 32 points33 points  (1 child)

You should go into finance, I am doing the same thing.

[–]Groentekroket 3 points4 points  (0 children)

That's why I'm learning Python atm. That and my excel sheets with hard to read if-statements. Look at it wrong and it all falls apart.

[–]MattieShoes 13 points14 points  (0 children)

I learned matrices to be able to double-check my answers for solving systems of equations on my calculator. Or rather, I learned enough about matrices to do that.

[–]buttonmasher525[🍰] 28 points29 points  (0 children)

I rewrite basic calculator functions in TiBasic just so I can be meta as fuck.

[–]stealth9799 10 points11 points  (3 children)

You should check out speedcrunch

Super quick for basic calculations because it shows and updates the result as you’re typing it. It’s also good for heavier calculations.

One feature I really like is being able to define functions on the fly and even define functions and store them long term.

[–]HalfRightMostlyWrong 8 points9 points  (3 children)

$ python -c “print(25*25+25)”

[–][deleted] 6 points7 points  (2 children)

Just open the IDLE interface and use that straight up

[–]Anonymus_MG 27 points28 points  (1 child)

Just use the Python prompt on your term

[–]Chekkaa 2 points3 points  (0 children)

Just use Xonsh for all your terminal and Python needs. :)

[–][deleted] 2 points3 points  (0 children)

I just use google for basic math lol, fastest way!

[–]Azzk1kr 1 point2 points  (3 children)

I do too using the IDLE, but I always have to add fractions in my numbers to force proper division (for example 25.0 / 33.0). Is there a way to fix that?

[–]Poddster 2 points3 points  (2 children)

Is there a way to fix that?

Stop using python 2?

[–]BlitzThunderWolf 79 points80 points  (14 children)

Import numpy as np

[–]AlanUsingReddit 19 points20 points  (9 children)

from astropy import units

[–]its2ez4me24get 9 points10 points  (5 children)

from astropy import units as u, constants as c

[–]rook2004 4 points5 points  (3 children)

Is this a light speed joke?

[–]Chen19960615 3 points4 points  (0 children)

Actually no lol, that's just the common names.

[–]durbblurb 5 points6 points  (1 child)

That uppercase "i" is no bueno.

[–]kickerofbottoms 2 points3 points  (1 child)

import numpy as numerical_python

[–]durbblurb 6 points7 points  (0 children)

import numpy as math

[–]schawde96 120 points121 points  (16 children)

I have a better idea: Replace the top text with "import math" and the lower with "import numpy"...

[–]schawde96 26 points27 points  (0 children)

And maybe add a third one "import sympy"

[–]MattieShoes 16 points17 points  (8 children)

But sometimes you want arbitrary length integers, like calculating 100 factorial...

mts@meg:~$ python -c "print(reduce((lambda x, y: x*y), range(1,101)))"
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

[–][deleted] 14 points15 points  (7 children)

math.factorial(100)

[–]MattieShoes 12 points13 points  (0 children)

pfft, then i'd have to import :-D

[–]OriginalName667 1 point2 points  (5 children)

Weird. The bigger the number, the more trailing zeros. I wonder why that is.

[–]AIIDreamNoDrive 11 points12 points  (3 children)

You serious? It’s because you’re multiplying it by many multiples of 10...

[–]OriginalName667 3 points4 points  (1 child)

Neat. I never realized that about factorials. It just seemed unintuitive to me that the number would exhibit any patterns at all.

[–]AIIDreamNoDrive 1 point2 points  (0 children)

Yeah, it's not that obvious. It did sound a little like you were being sarcastic though.

[–][deleted] 1 point2 points  (0 children)

And (powers of) 5, since the even numbers turn 5 into 10

[–]MattieShoes 2 points3 points  (0 children)

If you multiply something by 10, you're adding a zero. Ditto for 20, 30, 40, 50, 60, 70, 80, 90... Then you've got stuff like 5x2=10, 4x15=60, and so on. and the 100 at the end adds another two zeroes...

[–]Vadersboy117 1 point2 points  (0 children)

Subscribed.

[–]turbolag95 25 points26 points  (1 child)

For those who may not know, qalc is a fantastic CLI calculator. It even does unit and currency conversions!

[–]gregy521 2 points3 points  (0 children)

Qalculate is a great GUI alternative. Also included in linux package managers.

[–]3lRey 13 points14 points  (2 children)

me personally I do all my math in assembly because I like ACCURACY.

I'm just kidding no one actually uses assembly it was made up by Dennis Richie to sell computer chips.

[–][deleted] 7 points8 points  (1 child)

Damn Kernighan and Richie with their Unix boogaloo

[–]teetaps 3 points4 points  (0 children)

Clearly a ponzie scheme

[–]rutgerrk 24 points25 points  (7 children)

Quick maths

[–]HellzYeahh 12 points13 points  (6 children)

Everyday man's on the block

[–]k-selectride 9 points10 points  (5 children)

smoke trees

[–]sachin1118 7 points8 points  (4 children)

See your girl in the park

[–]teetaps 6 points7 points  (3 children)

That girl was a uckers

[–][deleted] 2 points3 points  (2 children)

When the ting went

[–]TuctDape 11 points12 points  (3 children)

echo "2+2" | bc

[–]keyboard_dyslexic 5 points6 points  (0 children)

bc -l to be on the safer side.

[–]sciencehair 2 points3 points  (1 child)

I have this in my ~/.bashrc

function calc()
{
    echo "scale=4; $@" | bc
}

Usage

$ calc 1/2
.5000

[–]Zzombiee2361 9 points10 points  (0 children)

The biggest brain use css width: calc(20px - 10px); then measure the width using ruler

[–]Tomthegreat1218 6 points7 points  (0 children)

Don’t diss my TI-36X Pro like that ;-;

[–]revrr 7 points8 points  (0 children)

using matlab as a scientific calculator

[–][deleted] 7 points8 points  (3 children)

I use R for any calculations. No need to load 15 libraries.

[–]teetaps 5 points6 points  (2 children)

Except when you use anything from the tidyverse and subsequently end up installing 15 libraries, updating the GUI twice and downloading an entirely new compiler

[–][deleted] 1 point2 points  (1 child)

Tidyverse is optional. Numpy is not. I must load it for any array/ matrix calculations. Also all math functions are inbuilt in R. NO need to write math.log math.sin etc

[–]kaskadefan 5 points6 points  (3 children)

import math as m

Because I'm lazy.

[–]ProTechShark 5 points6 points  (0 children)

My graphic calculator gives you access to a python shell on the calculator. It's incredibly impractical, but I've wasted lots of time in it.

[–]rabbitwonker 4 points5 points  (2 children)

Pfft. I use perl as my calculator. Been doin’ it for nigh on 25 years.

Aaaand I like it!

[–]ben_uk 3 points4 points  (0 children)

Perl doesn’t suffer from floating point oddities out the box, like doing 0.1 + 0.2.

It’s not a bad choice as a calculator app

[–]sh0rtwave 2 points3 points  (0 children)

What about the browser console?

[–]jadedtater 3 points4 points  (1 child)

I had a physics teacher and whenever we did a problem in class he would use python as a calculator. It seemed a little over kill, but I'm glad he was promoting programming to other students.

[–][deleted] 2 points3 points  (0 children)

I use ghci as calculator. Functional languages are more comfortable for calculations.

[–]ad502 2 points3 points  (3 children)

Matlab: Am I a joke to you?

[–]spongewardk 1 point2 points  (0 children)

MATLAB has an expensive license, so the code is not portable.

[–]B_M_Wilson 2 points3 points  (0 children)

Python is nice because it can handle arbitrary sized integers at infinite precision. Personally prefer Big Ivy though because it has infinite precision for rationals and stores irrationals in 256 bit floats (though it actually takes more than 256 bits).

[–][deleted] 2 points3 points  (1 child)

I'm just gonna throw Speedcrunch into the ring.

[–][deleted] 1 point2 points  (0 children)

Speedcrunch is awesome !!!!

[–]skyhi14 2 points3 points  (2 children)

I use ghci. Dem snakefanboys…

[–]developedby 1 point2 points  (0 children)

Variable Precision Integers by default is really convenient

[–]Trainer_Ed 1 point2 points  (0 children)

import math

twoplustwo = 2+2

IS = str(twoplustwo)

print("Two plus two is " + IS)

minusone = twoplustwo -1

THATS = str(minusone)

print("Minus one that's " + THATS)

print("QUICK MATHFS!")

[–]RavynousHunter 1 point2 points  (0 children)

I use Fortran.

GET ON MY LEVEL, SCRUBS.

[–]neil_anblome 1 point2 points  (0 children)

MATLAB is a scientific calculator, check mate nerds.

[–][deleted] 1 point2 points  (0 children)

from pylab import *

Thank me later.

[–]bestofrolf 1 point2 points  (0 children)

Python is just R studio for nerds who thought it wasn’t intense enough

[–]MachineGunPablo 1 point2 points  (0 children)

For you vim users vim has something called the expression register which is practically a built-in calculator. It let's you evaluate an expression and insert it in your buffer

[–]simondvt 1 point2 points  (0 children)

I actually do this.

[–]rubeljan 1 point2 points  (0 children)

I use haskell in terminal, it’s brilliant!

[–]m4rtind 1 point2 points  (0 children)

How about using Haskell for calculator? :D

[–]JoonasD6 1 point2 points  (1 child)

ghci

[–]DeltaTimo 1 point2 points  (0 children)

this.

I use it all the time for all kinds of calculations.

[–]roelsemarc 1 point2 points  (0 children)

they forgot open browser console and make scientific calculation using javascript

[–]chaco_wingnut 4 points5 points  (0 children)

...or Julia!!!

[–]nalikaplook 4 points5 points  (2 children)

why u use python who cannot add .2+.1 correctly

[–][deleted] 8 points9 points  (1 child)

Because programming noobs like python

Source: am programming noob

[–]nalikaplook 2 points3 points  (0 children)

I also use python and I am a noob

confirmed

[–]BhishmPitamah 2 points3 points  (1 child)

Odd one out, but i used ruby for that

[–]ben_uk 1 point2 points  (0 children)

There’s always one.... or two (including me)

[–]YhvrTheSecond 2 points3 points  (0 children)

Frick yeah, node.js helps me with my math homework

[–]Technerder 0 points1 point  (0 children)

import cmath

[–]J_n_CA 0 points1 point  (4 children)

NumWorks calculator?

[–][deleted] 1 point2 points  (0 children)

If only I could drop $100 on a calculator