Discuss Scratch

BookOwl
Scratcher
1000+ posts

Math Brain Teasers

I recently solved the Alien abduction brain teaser from Khan Academy. Does anybody know of any other sites with math puzzles/brain teaser?

who needs signatures
NoMod-Programming
Scratcher
1000+ posts

Math Brain Teasers

BookOwl wrote:

I recently solved the Alien abduction brain teaser from Khan Academy. Does anybody know of any other sites with math puzzles/brain teaser?
http://www.braingle.com/Math.html try there

Long-since moved on from Scratch, if you need to find all my posts, search this in google: 3499447a51c01fc4dc1e8c3b8182b41cb0e88c67
Hamish752
Scratcher
1000+ posts

Math Brain Teasers

BookOwl wrote:

I recently solved the Alien abduction brain teaser from Khan Academy. Does anybody know of any other sites with math puzzles/brain teaser?
Not the right forum. Try the reading/playing or maybe making/creating.

DigiTechs
Scratcher
500+ posts

Math Brain Teasers

Hamish752 wrote:

BookOwl wrote:

I recently solved the Alien abduction brain teaser from Khan Academy. Does anybody know of any other sites with math puzzles/brain teaser?
Not the right forum. Try the reading/playing or maybe making/creating.
This is totally on-topic though.

Math(s) comes under programming and is an advanced topic.

I do, in fact, have my own site; it's here.
I'm also working on a thing called Fetch. Look at it here!
@thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain.
gtoal
Scratcher
1000+ posts

Math Brain Teasers

BookOwl wrote:

I recently solved the Alien abduction brain teaser from Khan Academy. Does anybody know of any other sites with math puzzles/brain teaser?
https://projecteuler.net/
SuperDoom
Scratcher
1000+ posts

Math Brain Teasers

7/2*10-10(100-2*5*4)
-565 or -599.65?

WARNING: Anything I post is either stupid, sarcastic, or ironic. I am not to be taken seriously. Feel free to make fun of me for anything I say.
“Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety.”
essentiallibertyisfreedomofspeech~Benjamin Franklin (This is my motto for replying to suggestions.)
As of 83G1NN1NG/0F/71M3, I use color #322F31 for my posts. If it's a link, I use #1AA0D8.
CLICK THIS LINK TO INSTANTLY CRASH THE SERVERS
Alexa, play Space Invaders.
300035004000
As of November 7th, 2019, I have my computer back.
I'm awake from 11:00 AM to 11:30 PM CST (12:00 PM to 12:30 AM EST). Please be more active during that time.
I've moved to -THENEXT_LEVEL-.
BookOwl
Scratcher
1000+ posts

Math Brain Teasers

SuperDoom wrote:

7/2*10-10(100-2*5*4)
-565 or -599.65?
-599.65

who needs signatures
ev3coolexit987654
Scratcher
1000+ posts

Math Brain Teasers

SuperDoom wrote:

7/2*10-10(100-2*5*4)
-565 or -599.65?
-250
gtoal
Scratcher
1000+ posts

Math Brain Teasers

SuperDoom wrote:

7/2*10-10(100-2*5*4)
-565 or -599.65?

               -565
/ \
/ \
/ \
/ \
/ 600
/ / \
/ / 60
/ / / \
35 / / 40
/ \ / / / \
3.5 \ / / 10 \
/ \ \ / / / \ \
7 / 2 * 10 - 10 (100 - 2 * 5 * 4)

/ and * are at the same priority level and are handled left to right.

Last edited by gtoal (Aug. 1, 2015 04:40:00)

gtoal
Scratcher
1000+ posts

Math Brain Teasers

gtoal wrote:

SuperDoom wrote:

7/2*10-10(100-2*5*4)
-565 or -599.65?

               -565
/ \
/ \
/ \
/ \
/ 600
/ / \
/ / 60
/ / / \
35 / / 40
/ \ / / / \
3.5 \ / / 10 \
/ \ \ / / / \ \
7 / 2 * 10 - 10 (100 - 2 * 5 * 4)

/ and * are at the same priority level and are handled left to right.

Hey, project idea: parse expressions and draw the parse tree….

Last edited by gtoal (Aug. 1, 2015 04:42:10)

DigiTechs
Scratcher
500+ posts

Math Brain Teasers

gtoal wrote:

gtoal wrote:

SuperDoom wrote:

7/2*10-10(100-2*5*4)
-565 or -599.65?

               -565
/ \
/ \
/ \
/ \
/ 600
/ / \
/ / 60
/ / / \
35 / / 40
/ \ / / / \
3.5 \ / / 10 \
/ \ \ / / / \ \
7 / 2 * 10 - 10 (100 - 2 * 5 * 4)

/ and * are at the same priority level and are handled left to right.

Hey, project idea: parse expressions and draw the parse tree….


That would be pretty easy assuming you didn't follow basic order of operation rules It would still be pretty cool though.

I do, in fact, have my own site; it's here.
I'm also working on a thing called Fetch. Look at it here!
@thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain.
gtoal
Scratcher
1000+ posts

Math Brain Teasers

DigiTechs wrote:

gtoal wrote:

Hey, project idea: parse expressions and draw the parse tree….

That would be pretty easy assuming you didn't follow basic order of operation rules It would still be pretty cool though.

Handling operator precedence is where the fun is in that project! It's not actually very hard, for example here's a really simple algorithm:

Let's assume that you have an expression parser which works, but assumes left to right associativity and does not understand operator precedence. This will allow you to trivially add parentheses to that expression so that it is fully parenthesised and therefore correctly reflects operator precedence. You can just about implement this with a macro-processor, even, or a trivial filter on input.

First, write down your operators in order of precedence:
^
* /
+ -
Now, redefine each operator as a number of closing parentheses followed by the original operator followed by the same number of opening parentheses. The highest priority operator gets one level of parentheses, and subsequent levels get more, respectively:
^        ") ^ (" 
* / ")) * ((" and ")) / (("
+ - "))) + (((" and "))) - ((("
Here's the algorithm:

Before you copy any items from the input to the output, print a number of opening parentheses which is one larger than the largest string above i.e. “((((”

Take your input expression string one item at a time, from left to right.

For each item, if it is a terminal (eg a variable or a constant) just output it; if it is an operator, output the replacement string above.

Finally, output a matching set of closing parentheses, i.e. “))))”.

Let's take a test string, and apply this algorithm:
a*b+c^d/e
First to be output is the enclosing parentheses and the first token:
((((a
Next is “*” which is replaced by “)) * ((”, followed by the next token:
((((a)) * ((b
repeat for all remaining tokens…
((((a)) * ((b))) + (((c) ^ (d)) / ((e
and finally after the last token, the closing “))))” …
((((a)) * ((b))) + (((c) ^ (d)) / ((e))))
Now if you parse this with a simple grammar, you'll find it correctly reflects operator precedence!

We can check this by manually removing redundant parentheses:
((((a)) * ((b))) + (((c) ^ (d)) / ((e))))
((( a ) * ( b )) + (( c ^ d ) / ( e )))
(( a * b ) + (( c ^ d ) / e ))
( a * b ) + (( c ^ d ) / e )
i.e. the final expression is “(a*b) + ((c^d)/e)” which is indeed correct. The fully-parenthesised expression can be trivially parsed by a recursive descent parser.

This algorithm is congruent with Dijkstra's “shunting yard” operator precedence algorithm; copying a “(” to the output before a terminal is equivalent to switching the tracks so that the next item is pushed on the stack, and outputting a “)” is the same as popping off the stack.

Here is some C code to parenthesise (but not evaluate) an expression:
#include <stdio.h>
char *intable[] = { NULL, "^", "*", "/", "+", "-", "" };
char *outtable[] = { "))))\n", ")^(", "))*((", "))/((", ")))+(((", ")))-(((", "((((" };
int main(int argc, char **argv)
{
int i, tab;
for (argv[i=0]=""; i <= argc; i++) {
for (tab = 0; tab < (sizeof(outtable)/sizeof(char *)); tab += 1) {
if ((!argv[i]) || (tab && !strcmp(argv[i], intable[tab]))) {
printf("%s", outtable[tab]); break;
} else if (tab && !*intable[tab]) printf("%s", argv[i]);
}
}
}
invoke it as:

$ cc -o parenthesise parenthesise.c
$ ./parenthesise a \* b + c ^ d / e
((((a))*((b)))+(((c)^(d))/((e))))

Last edited by gtoal (Aug. 2, 2015 02:54:50)

liam48D
Scratcher
1000+ posts

Math Brain Teasers

That is pretty awesome. Pretty awesome indeed.

202e-202e-202e-202e-202e UNI-CODE~~~~~
nerdy3211
Scratcher
1 post

Math Brain Teasers

hello
liam48D
Scratcher
1000+ posts

Math Brain Teasers

nerdy3211 wrote:

hello
Um, what does that have to do with brain teasers..?

Please try to keep your posts on-topc on the forums. Also, just so you know, don't post on things that haven/t been posted on for months (that's called necroposting) unless you have a really good thing to add to the discussion..

202e-202e-202e-202e-202e UNI-CODE~~~~~
__init__
Scratcher
1000+ posts

Math Brain Teasers

liam48D wrote:

nerdy3211 wrote:

hello
Um, what does that have to do with brain teasers..?

Please try to keep your posts on-topc on the forums. Also, just so you know, don't post on things that haven/t been posted on for months (that's called necroposting) unless you have a really good thing to add to the discussion..
This wasn't a necropost…

thisandagain pls explain
liam48D
Scratcher
1000+ posts

Math Brain Teasers

__init__ wrote:

liam48D wrote:

nerdy3211 wrote:

hello
Um, what does that have to do with brain teasers..?

Please try to keep your posts on-topc on the forums. Also, just so you know, don't post on things that haven/t been posted on for months (that's called necroposting) unless you have a really good thing to add to the discussion..
This wasn't a necropost…
I know but I assume they're new to the forums so I decided to tell them about necro-ing.

202e-202e-202e-202e-202e UNI-CODE~~~~~

Powered by DjangoBB

Standard | Mobile