Author Topic: How does this line of code work?  (Read 6380 times)

0 Members and 1 Guest are viewing this topic.

Offline holmes221b

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 282
  • Rating: +13/-1
  • RESISTANCE IS FUTILE.
    • View Profile
    • My Livejournal
Re: How does this line of code work?
« Reply #15 on: December 11, 2010, 02:44:42 pm »
So that's where the list comes from...

My mom just texted me to remind me about the specific part of that line of code that she was particularly confused by. She wants to know what "Ans=3" and "Ans=5" means.

Spoiler For "Projects":
Spoiler For "Because Everyone Else Is":
*Sigh*
can we keep this on topic? The topic is about what the big thing might be, NOT SEX

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: How does this line of code work?
« Reply #16 on: December 11, 2010, 02:45:25 pm »
wow you have a cool mom
mine never would do that
I'm not a nerd but I pretend:

Offline holmes221b

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 282
  • Rating: +13/-1
  • RESISTANCE IS FUTILE.
    • View Profile
    • My Livejournal
Re: How does this line of code work?
« Reply #17 on: December 11, 2010, 02:51:05 pm »
wow you have a cool mom
mine never would do that
She won't let me get a link cable unless I buy it with my own money or figure out how to make my own (again, with my own money), though.

Spoiler For "Projects":
Spoiler For "Because Everyone Else Is":
*Sigh*
can we keep this on topic? The topic is about what the big thing might be, NOT SEX

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: How does this line of code work?
« Reply #18 on: December 11, 2010, 04:32:58 pm »
When you have a list of numbers, say you had {1,2,3,4,5,6} and you do Ans=3, it would test if each element is 3 so you would get {0,0,1,0,0,0}.  2(Ans=3) would give: {0,0,2,0,0,0} since every element gets multiplied by 2.  4(Ans=5) would similarly give: {0,0,0,0,4,0}.  Adding each element together: {0,0,2,0,4,0} then doing a sum adds all the elements together so you'd end up with 6 as your answer.

Basically it is generating a random even number with a weird distribution where the average value is 6, minimum value is 0 and maximum value is 24.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline holmes221b

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 282
  • Rating: +13/-1
  • RESISTANCE IS FUTILE.
    • View Profile
    • My Livejournal
Re: How does this line of code work?
« Reply #19 on: December 11, 2010, 04:38:05 pm »
When you have a list of numbers, say you had {1,2,3,4,5,6} and you do Ans=3, it would test if each element is 3 so you would get {0,0,1,0,0,0}.  2(Ans=3) would give: {0,0,2,0,0,0} since every element gets multiplied by 2.  4(Ans=5) would similarly give: {0,0,0,0,4,0}.  Adding each element together: {0,0,2,0,4,0} then doing a sum adds all the elements together so you'd end up with 6 as your answer.
Basically it is generating a random even number with a weird distribution where the average value is 6, minimum value is 0 and maximum value is 24.
Oh wow, that's pretty cool.

And my mom says "thanks".

Spoiler For "Projects":
Spoiler For "Because Everyone Else Is":
*Sigh*
can we keep this on topic? The topic is about what the big thing might be, NOT SEX

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: How does this line of code work?
« Reply #20 on: December 11, 2010, 04:40:01 pm »
So that's where the list comes from...

My mom just texted me to remind me about the specific part of that line of code that she was particularly confused by. She wants to know what "Ans=3" and "Ans=5" means.

Ans=3 just returns 1 if the data in Ans is equal to 3 and 0 if it does not.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: How does this line of code work?
« Reply #21 on: December 11, 2010, 06:56:01 pm »
Ya, Quigibo got that explained perfectly. Anything with a = (equal) sign is a Boolean conditional in that it is tested to see if the statement is true or false. If the statement is true then it returns a one and if it is false then it returns zero. When that happens it can then be used in math (which is a good way of avoiding using a bunch of If statements).

As for randInt( it has always taken three arguments :P The first being the lowest number possible, the second being the highest number possible, and then the third is the number of times the the command runs (returning the answers in the form of a list). So randInt(1,10,5 could give an answer like {3,7,5,3,2}. In this case the list you get could be something like {1,3,3,6,5}. When you apply the sum( to it all your final answer would be eight.

Code: [Select]
sum(2({1,3,3,6,5}=3)+4({1,3,3,6,5}=5

sum(2{0,1,1,0,0}+4{0,0,0,0,1

sum({0,2,2,0,0}+{0,0,0,0,4

sum({0,2,2,0,4

8
« Last Edit: December 11, 2010, 06:58:31 pm by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)