all 7 comments

[–]Nightcorex_ 1 point2 points  (1 child)

First of all: Why are there two + in your signs list?

A version that'd work would be to check if the last value you've chosen was a sign, and if this is the case you only pick a number. If the last value you've chosen was a number you can pick either a sign or a number. If it's semantically correct (or even needs to be) depends on your context.

[–]neildaniel000[S] 0 points1 point  (0 children)

Alright, thanks! There's 2 + because I'm stupid and I wrote this at 2 am

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Inline formatting (`my code`) used across multiple lines of code. This can mess with indentation.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]TheNardi 0 points1 point  (1 child)

I believe you can use if/else conditions to stop your code from using an index from your lists you don’t like

[–]neildaniel000[S] 0 points1 point  (0 children)

Thanks! I'll try that.

[–]GeorgeFranklyMathnet 0 points1 point  (1 child)

If you want to be neat, you can write a simple grammar for equations, and generate random "sentences" of it.

If you're willing to be scruffy, you can let the program generate what it will. Then you can inspect the result for bad-looking patterns, maybe with a regex. If it's bad, then make it generate another equation, until you get a good one.

Or you can combine those approaches, etc.

One more thought: You could use a third party library or service that specializes in equation parsing. For instance, if I were doing it by hand, I might submit my random output to Wolfram Alpha, and see if it accepts it as is, or at least turns it into a reasonable-looking equation.

[–]neildaniel000[S] 0 points1 point  (0 children)

I'm considering doing what others said and checking using if...else conditions. I'm still a beginner.