Jump to content

Bogosort on AutoIt


DavidLago
 Share

Recommended Posts

Hey.

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

Useless, but fun.

Global $Var1, $Var2, $Var3, $Var4, $Var5, $Var6, $count = ""
Global $Value = $Var1 + $Var2 + $Var3 + $Var4 + $Var5 + $Var6
Global $Number = 10000
Global $Flag = False

While Not $Flag = True
    $count = $count + 1
    $Var1 = Random(0, 2000, 1)
    $Var2 = Random(0, 2000, 1)
    $Var3 = Random(0, 2000, 1)
    $Var4 = Random(0, 2000, 1)
    $Var5 = Random(0, 2000, 1)
    $Var6 = Random(0, 2000, 1)
    $Value = $Var1 + $Var2 + $Var3 + $Var4 + $Var5 + $Var6
    If $Value = $Number Then $Flag = True
WEnd
MsgBox(64, "Bogosort", "Bogosort took " & $count & " tries to guess 6 numbers!")

Is anyone able to improve it in any way?

Edited by DavidLago
Link to comment
Share on other sites

Hi DavidLago, welcome to the General Chat forum. :)

If you are asking for improvements to code, then really this topic should be in Examples or GH&S. ;)

Most of us come here to escape from code ... fun though your finished code might be. :D

Or perhaps even the Scripting & Development section of the forum, in Developer General Discussion

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Hi, not asking for anything :)

Just showing up a really fun code, and if someone else wants to have fun, adding some stupid stuff in the code within the topic, that would be even more fun :D

If you think it would fit better there, could you move it?

 

Link to comment
Share on other sites

32 minutes ago, DavidLago said:

Hi, not asking for anything :)

Just showing up a really fun code, and if someone else wants to have fun, adding some stupid stuff in the code within the topic, that would be even more fun :D

The original description of the Chat Forum, used to say no code, and as far as I know, that still stands.

To get around that, you could perhaps talk about Bogosort here, and provide a link to your code at wherever it gets relocated to.

Quote

If you think it would fit better there, could you move it?

Report the topic and ask, as it requires a MOD to do it.

Or just take up my suggestion and split your code off.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

5 hours ago, DavidLago said:

Is anyone able to improve it in any way?

#include <MsgBoxConstants.au3>

Global Const $NUMBER_TO_SORT = 10000
Global Const $DIFFICULTY = 2000
Global Const $NO_OF_ITERATIONS = 6

Global $iCount = 0
Global $iSum = 0

Do
    $iSum = 0
    $iCount = $iCount + 1
    For $i = 1 To $NO_OF_ITERATIONS
        $iSum += Random(0, $DIFFICULTY, 1)
    Next
Until $iSum = $NUMBER_TO_SORT

MsgBox($MB_OK + $MB_ICONINFORMATION, "Bogosort", "Bogosort took " & $iCount & " tries to guess " & $NUMBER_TO_SORT & " out of " & $NO_OF_ITERATIONS & " randomly added up numbers (each not exceeding " & $DIFFICULTY & ')')

:)

P.S Its not AutoIT, Its AutoIt

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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