Jump to content
DSP Gaming

Cool Coding Tricks


Guest

Recommended Posts

I was looking at some things regarding coding, and learned some cool stuff, so I decided to mess around with it, (specifically in Python). This thread is just for posting simple but interesting programming syntax, (and better if you explain it), but just for fun, nothing too complicated or serious.

So with this one, you can estimate π with basically a number randomizer and by applying a formula after recounting the numbers. The idea is that if you randomize dots in a semi-uniform manner inside an overlapped & centered square & circle that have the same diameter/edge length, the dots that fall within the circle divided by the ones that fall in total, (so inside the square, and therefore inside the circle), should approximate (π/4), without you needing to input π at all.

If you run this in Python, it should give you the estimate, with obviously a different result each time, and more accurate to the number the more iterations you give it, (here I put 1000000 times):

import random
def approx_pi(z):
    dot_in_circle = 0
    dot_in_total = 0
    for _ in range(z):
        x = random.uniform(0,1)
        y = random.uniform(0,1)
        rad = x**2 + y**2
        if rad <= 1:
            dot_in_circle += 1
        dot_in_total += 1
        
    return 4 * dot_in_circle/dot_in_total

print(approx_pi(1000000))

I didn't know about this until recently, I think it's pretty cool.

Edited by MoraMoria
Link to comment
Share on other sites

1 hour ago, GuessWhat said:

Cool. I didn't know you were into programing.

Just a bit.

8 hours ago, babymngaming456 said:

There's actually simple math behind it.

The point of this is to estimate π with a randomizer between numbers [0 and 1, included], and then applying a formula after recounting.

You have to do it without having π, or the area of an already existing circle or square, (or circumference), that's why you use the randomizer. In your equation, you already have either of those, so it's pointless, you already have the solution.

Your highlighted equation at the bottom of the image is already in the return statement, but "A_circle" was calculated with the help of the randomizer.

Link to comment
Share on other sites

This is something I did a while ago, but is related to programming.

You can actually make an encoder & decoder of ciphertexts in Microsoft Excel, although it's not going to look super fancy. The one I did that's shown here, just encodes the plaintexts to Beaufort & Vigenère, and below it, a decoder of those two as well. You just enter the plaintext & key, (the only thing you do in this version is enter the data in the green-cells).

It works by assigning a number to each letter of the alphabet, (made it for English), and then you just apply a formula to add or substract them & output the corresponding letter, depending on the cipher. But because it's Excel, you have to take a lot of things into consideration if you want to make it work, like making sure that the key loops correctly regardless of its length, and that the output for the result also assigns the correct letter no matter the length of the string, (with a limit for the one I made).

One day I'll try it with a programming language instead of Excel, and I'm sure that some parts will be easier.

Crypto.thumb.png.e70a1e99a830a265e4c3ff4cdb59ee4a.png

Edited by MoraMoria
Link to comment
Share on other sites

  • 3 weeks later...

I've done a bunch of things in Excel that I want to do with a programming language.

Like with this, it basically shows a letter-frequency-analysis of the English language, (in the: "% English" row, according to some sources), and in the top one it counts the specific letters of the text you input, and colours it, according to its frequency. The result shows that the colours seem to match fairly well, so the text should have a decent chance of being written in English.

So if I make this a bit more complex, it might work good with Caesar-Ciphertexts as well:

TextAnalysisEX.thumb.png.084f740db61a65e3c0833b48cf9421c4.png

Link to comment
Share on other sites

  • 4 months later...
3 minutes ago, GuessWhat said:

It's just suppose to send the user to the url site?

Yes, with that tag the user will be redirected to: https://thekingofhate.com/forums/ after 0 seconds, and you can change the 0 to the number you want.


It's just a "trick" that would be used sometimes, instead of the alternatives. It's decently explained on Wikipedia in a brief manner:

https://en.wikipedia.org/wiki/Meta_refresh

Link to comment
Share on other sites

30 minutes ago, MoraMoria said:

Yes, with that tag the user will be redirected to: https://thekingofhate.com/forums/ after 0 seconds, and you can change the 0 to the number you want.


It's just a "trick" that would be used sometimes, instead of the alternatives. It's decently explained on Wikipedia in a brief manner:

https://en.wikipedia.org/wiki/Meta_refresh

Nice, I was just making sure I somewhat understood what the hell was happening. LOL , I wasn't trying to sound like an ass or anything.

Link to comment
Share on other sites

21 minutes ago, GuessWhat said:

Nice, I was just making sure I somewhat understood what the hell was happening. LOL , I wasn't trying to sound like an ass or anything.

Oh yeah, don't worry.

I'm also learning about it, in this case you'd just put the <meta> tag inside the <head> of your HTML document.

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 3 months later...

I did a simple simulation of the "Monty Hall" problem on Excel, (that's the best quality I can give it, apparently).

If I did it correctly, it should be calculating the percentage of wins the contestant gets, based on whether they stay, or swap the door. It calculates each scenario based on 8999 simulations.

datdadatda1.thumb.gif.47cfc18a44398bbcf0c599069db5496f.gif

Link to comment
Share on other sites

  • 3 weeks later...

I did a mini-battle-simulator like Pokémon on Excel by using basic knowledge of VBA, (Visual Basic for Applications). You can roll the health/attack/defense/type as random, or by giving a range to it. You can also randomize the moves if you want.

I made it so that there's types affectiveness, (Fire, Ghost, Normal, Earth, Water, Wind, Light, Bug, Electric), & side-effects for moves, (Attack/Defense/Accuracy decrease, flinch, burn, freeze, paralyze, sleep, curse, exhaust).

It's kind of simple, but it's like an RPG battle where you just click on the attack you want. This is all within an Excel document.

BatSIM.thumb.png.b18aa0ee7a525a0502a7fe7f8b77d3b1.png

Link to comment
Share on other sites

On 9/17/2021 at 8:59 PM, MoraMoria said:

I did a mini-battle-simulator like Pokémon on Excel by using basic knowledge of VBA, (Visual Basic for Applications). You can roll the health/attack/defense/type as random, or by giving a range to it. You can also randomize the moves if you want.

I made it so that there's types affectiveness, (Fire, Ghost, Normal, Earth, Water, Wind, Light, Bug, Electric), & side-effects for moves, (Attack/Defense/Accuracy decrease, flinch, burn, freeze, paralyze, sleep, curse, exhaust).

It's kind of simple, but it's like an RPG battle where you just click on the attack you want. This is all within an Excel document.

BatSIM.thumb.png.b18aa0ee7a525a0502a7fe7f8b77d3b1.png

Wow! That is really cool stuff you did there MoraMoria.

Edited by musicboy
Link to comment
Share on other sites

  • 9 months later...
1 hour ago, MDCFAN101 said:

Unfortunately no he is isn't.  He told me a while ago that he was leaving the forums.  I don't know why, he never really gave me his reasons as to why he was leaving.

He was always DMing me asking questions about Phil. Also noticed he was messing with forum code and spamming thousands of DMs every week.

Had a second account too that was a secret. Ever time I pried for more information he would get hostile like I was snooping in his business.

No strong feelings about the guy but there was some weird shit with him.

Link to comment
Share on other sites

23 minutes ago, KGhaleon said:

He was always DMing me asking questions about Phil. Also noticed he was messing with forum code and spamming thousands of DMs every week.

Had a second account too that was a secret. Ever time I pried for more information he would get hostile like I was snooping in his business.

No strong feelings about the guy but there was some weird shit with him.

TBH, I felt the same way too about him, but he never gave me any trouble.

Link to comment
Share on other sites

  • 2 weeks later...
On 7/2/2022 at 9:01 PM, MDCFAN101 said:

Unfortunately no he is isn't.  He told me a while ago that he was leaving the forums.  I don't know why, he never really gave me his reasons as to why he was leaving.

Thanks for that info bro.

 

On 7/2/2022 at 9:01 PM, MDCFAN101 said:

He told me a while ago that he was leaving the forums.  I don't know why, he never really gave me his reasons as to why he was leaving.

That is quite strange. I hope everything is alright with him.

Edited by musicboy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...