Jump to content

Simplifying question/challenge


Recommended Posts

Hello. I made an script for fun. All it does is combine elements of an array and comes up with an phrase. The phrase is just an meaningless insult meant to amuse you.

My question: Is there an way to create the array without adding 150 lines that doesn't involve using files that must be found at run time?

The challenge: Simplify this script as much as possible.

All i want from the challenge is to learn other ways i could have made this script simpler. Good luck and i hope to learn something ;)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#region populate $var
Dim $var[3][50]
$var[0][0] = 'artless'
$var[0][1] = 'bawdy'
$var[0][2] = 'beslubbering'
$var[0][3] = 'bootless'
$var[0][4] = 'churlish'
$var[0][5] = 'cockered'
$var[0][6] = 'clouted'
$var[0][7] = 'craven'
$var[0][8] = 'currish'
$var[0][9] = 'dankish'
$var[0][10] = 'dissembling'
$var[0][11] = 'droning'
$var[0][12] = 'errant'
$var[0][13] = 'fawning'
$var[0][14] = 'fobbing'
$var[0][15] = 'froward'
$var[0][16] = 'frothy'
$var[0][17] = 'gleeking'
$var[0][18] = 'goatish'
$var[0][19] = 'gorbellied'
$var[0][20] = 'impertinent'
$var[0][21] = 'infectious'
$var[0][22] = 'jarring'
$var[0][23] = 'loggerheaded'
$var[0][24] = 'lumpish'
$var[0][25] = 'mammering'
$var[0][26] = 'mangled'
$var[0][27] = 'mewling'
$var[0][28] = 'paunchy'
$var[0][29] = 'pribbling'
$var[0][30] = 'puking'
$var[0][31] = 'puny'
$var[0][32] = 'qualling'
$var[0][33] = 'rank'
$var[0][34] = 'reeky'
$var[0][35] = 'roguish'
$var[0][36] = 'ruttish'
$var[0][37] = 'saucy'
$var[0][38] = 'spleeny'
$var[0][39] = 'spongy'
$var[0][40] = 'surly'
$var[0][41] = 'tottering'
$var[0][42] = 'unmuzzled'
$var[0][43] = 'vain'
$var[0][44] = 'venomed'
$var[0][45] = 'villainous'
$var[0][46] = 'warped'
$var[0][47] = 'wayward'
$var[0][48] = 'weedy'
$var[0][49] = 'yeasty'
$var[1][0] = 'base-court'
$var[1][1] = 'bat-fowling'
$var[1][2] = 'beef-witted'
$var[1][3] = 'beetle-headed'
$var[1][4] = 'boil-brained'
$var[1][5] = 'clapper-clawed'
$var[1][6] = 'clay-brained'
$var[1][7] = 'common-kissing'
$var[1][8] = 'crook-pated'
$var[1][9] = 'dismal-dreaming'
$var[1][10] = 'dizzy-eyed'
$var[1][11] = 'doghearted'
$var[1][12] = 'dread-bolted'
$var[1][13] = 'earth-vexing'
$var[1][14] = 'elf-skinned'
$var[1][15] = 'fat-kidneyed'
$var[1][16] = 'fen-sucked'
$var[1][17] = 'flap-mouthed'
$var[1][18] = 'fly-bitten'
$var[1][19] = 'folly-fallen'
$var[1][20] = 'fool-born'
$var[1][21] = 'full-gorged'
$var[1][22] = 'guts-griping'
$var[1][23] = 'half-faced'
$var[1][24] = 'hasty-witted'
$var[1][25] = 'hedge-born'
$var[1][26] = 'hell-hated'
$var[1][27] = ''
$var[1][28] = 'ill-breeding'
$var[1][29] = 'ill-nurtured'
$var[1][30] = 'knotty-pated'
$var[1][31] = 'milk-livered'
$var[1][32] = 'motley-minded'
$var[1][33] = 'onion-eyed'
$var[1][34] = 'plume-plucked'
$var[1][35] = 'pottle-deep'
$var[1][36] = 'pox-marked'
$var[1][37] = 'reeling-ripe'
$var[1][38] = 'rough-hewn'
$var[1][39] = 'rude-growing'
$var[1][40] = 'rump-fed'
$var[1][41] = 'shard-borne'
$var[1][42] = 'sheep-biting'
$var[1][43] = 'spur-galled'
$var[1][44] = 'swag-bellied'
$var[1][45] = 'tardy-gaited'
$var[1][46] = 'tickle-brained'
$var[1][47] = 'toad-spotted'
$var[1][48] = 'unchin-snouted'
$var[1][49] = 'weather-bitten'
$var[2][0] = 'apple-john'
$var[2][1] = 'baggage'
$var[2][2] = 'barnacle'
$var[2][3] = 'bladder'
$var[2][4] = 'boar-pig'
$var[2][5] = 'bugbear'
$var[2][6] = 'bum-bailey'
$var[2][7] = 'canker-blossom'
$var[2][8] = 'clack-dish'
$var[2][9] = 'clotpole'
$var[2][10] = 'coxcomb'
$var[2][11] = 'codpiece'
$var[2][12] = 'death-token'
$var[2][13] = 'dewberry'
$var[2][14] = 'flap-dragon'
$var[2][15] = 'flax-wench'
$var[2][16] = 'flirt-gill'
$var[2][17] = 'foot-licker'
$var[2][18] = 'fustilarian'
$var[2][19] = 'giglet'
$var[2][20] = 'gudgeon'
$var[2][21] = 'haggard'
$var[2][22] = 'harpy'
$var[2][23] = 'hedge-pig'
$var[2][24] = 'horn-beast'
$var[2][25] = 'hugger-mugger'
$var[2][26] = 'joithead'
$var[2][27] = 'lewdster'
$var[2][28] = 'lout'
$var[2][29] = 'maggot-pie'
$var[2][30] = 'malt-worm'
$var[2][31] = 'mammet'
$var[2][32] = 'measle'
$var[2][33] = 'minnow'
$var[2][34] = 'miscreant'
$var[2][35] = 'moldwarp'
$var[2][36] = 'mumble-news'
$var[2][37] = 'nut-hook'
$var[2][38] = 'pigeon-egg'
$var[2][39] = 'pignut'
$var[2][40] = 'puttock'
$var[2][41] = 'pumpion'
$var[2][42] = 'ratsbane'
$var[2][43] = 'scut'
$var[2][44] = 'skainsmate'
$var[2][45] = 'strumpet'
$var[2][46] = 'varlot'
$var[2][47] = 'vassal'
$var[2][48] = 'whey-face'
$var[2][49] = 'wagtail'
#endregion populate $var

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Press the button", 409, 98, 386, 242)
$Button1 = GUICtrlCreateButton("Click Me", 160, 56, 75, 25)
$Input1 = GUICtrlCreateInput("", 8, 16, 393, 32, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY))
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
          Case $GUI_EVENT_CLOSE
               Exit
          Case $Button1
           $str = 'Thou '&$var[0][Random(0,49,1)]&' '&$var[1][Random(0,49,1)]&' '&$var[2][Random(0,49,1)]
           GUICtrlSetData($Input1, $str)
       EndSwitch
WEnd

[spoiler]My UDFs: Login UDF[/spoiler]

Link to post
Share on other sites

Hi pieeater,

you could go for a list and do a StringSplit().

If you use one instead of 3 lists, you can use the Random() function with different ranges.

$s_list = "a;b;c;d;e;f;g;h;i"
$a_list = StringSplit($s_list, ";")
$s_word1 = $a_list(Random(1, $a_list[0] / 3, 1)
$s_word2 = $a_list(Random($a_list[0] / 3, ($a_list[0] / 3) * 2, 1)
$s_word3 = $a_list(Random(($a_list[0] / 3) * 2, $a_list[0], 1)
Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to post
Share on other sites

;) I wrote this:

$string1 = "maheep is a good and a bad boy as well who likes computers and doesn't play games much often he rants a lot about programming in perl and autoit though he is a novice at python"
$string2 = "this is a pretty much bad example of expressing my ideas"
$string3 = "someone wrote a letter to a girl and he was an idiot"

$STRINGSPLIT1 = StringSplit($string1, " ")
$STRINGSPLIT2 = StringSplit($string2, " ")
$STRINGSPLIT3 = StringSplit($string3, " ")

Global $Array[3][50]
For $i = 1 to $STRINGSPLIT1[0]
$Array[0][$i] = $STRINGSPLIT1[$i]
Next
For $i = 1 to $STRINGSPLIT2[0]
$Array[1][$i] = $STRINGSPLIT2[$i]
Next
For $i = 1 to $STRINGSPLIT3[0]
$Array[2][$i] = $STRINGSPLIT3[$i]
Next
$mmk1 = Random(0,49,1)

$str = $Array[0][$mmk1]
$str1 = $Array[1][$mmk1]
$str2 = $Array[2][$mmk1]
msgbox(64, "", $str & ' ' & $str1 & ' ' & $str2)

Sometimes, it will give empty results because the no. of words in all the three strings is not the same.

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to post
Share on other sites

I finally resolved my example (just had a minor error!):

$string1 = "maheep is a good and a bad boy as well who likes computers and doesn't play games much often he rants a lot about programming in perl and autoit though he is a novice at python"
$string2 = "this is a pretty much bad example of expressing my ideas"
$string3 = "someone wrote a letter to a girl and he was an idiot"

$STRINGSPLIT1 = StringSplit($string1, " ")
$STRINGSPLIT2 = StringSplit($string2, " ")
$STRINGSPLIT3 = StringSplit($string3, " ")

Global $Array[3][50]
For $i = 1 to $STRINGSPLIT1[0]
$Array[0][$i] = $STRINGSPLIT1[$i]
Next
For $i = 1 to $STRINGSPLIT2[0]
$Array[1][$i] = $STRINGSPLIT2[$i]
Next
For $i = 1 to $STRINGSPLIT3[0]
$Array[2][$i] = $STRINGSPLIT3[$i]
Next


$str = $Array[0][Random(1, $STRINGSPLIT1[0],1)]
$str1 = $Array[1][Random(1, $STRINGSPLIT2[0],1)]
$str2 = $Array[2][Random(1, $STRINGSPLIT3[0],1)]
msgbox(64, "", $str & ' ' & $str1 & ' ' & $str2)

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to post
Share on other sites

Declaring an array.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $var[3][50]
$var[0][0] = 'artless'
$var[0][1] = 'bawdy'
$var[0][2] = 'beslubbering'
$var[0][3] = 'bootless'
$var[0][4] = 'churlish'
$var[0][5] = 'cockered'
$var[0][6] = 'clouted'
$var[0][7] = 'craven'
$var[0][8] = 'currish'
$var[0][9] = 'dankish'
$var[0][10] = 'dissembling'
$var[0][11] = 'droning'
$var[0][12] = 'errant'
$var[0][13] = 'fawning'
$var[0][14] = 'fobbing'
$var[0][15] = 'froward'
$var[0][16] = 'frothy'
$var[0][17] = 'gleeking'
$var[0][18] = 'goatish'
$var[0][19] = 'gorbellied'
$var[0][20] = 'impertinent'
$var[0][21] = 'infectious'
$var[0][22] = 'jarring'
$var[0][23] = 'loggerheaded'
$var[0][24] = 'lumpish'
$var[0][25] = 'mammering'
$var[0][26] = 'mangled'
$var[0][27] = 'mewling'
$var[0][28] = 'paunchy'
$var[0][29] = 'pribbling'
$var[0][30] = 'puking'
$var[0][31] = 'puny'
$var[0][32] = 'qualling'
$var[0][33] = 'rank'
$var[0][34] = 'reeky'
$var[0][35] = 'roguish'
$var[0][36] = 'ruttish'
$var[0][37] = 'saucy'
$var[0][38] = 'spleeny'
$var[0][39] = 'spongy'
$var[0][40] = 'surly'
$var[0][41] = 'tottering'
$var[0][42] = 'unmuzzled'
$var[0][43] = 'vain'
$var[0][44] = 'venomed'
$var[0][45] = 'villainous'
$var[0][46] = 'warped'
$var[0][47] = 'wayward'
$var[0][48] = 'weedy'
$var[0][49] = 'yeasty'
$var[1][0] = 'base-court'
$var[1][1] = 'bat-fowling'
$var[1][2] = 'beef-witted'
$var[1][3] = 'beetle-headed'
$var[1][4] = 'boil-brained'
$var[1][5] = 'clapper-clawed'
$var[1][6] = 'clay-brained'
$var[1][7] = 'common-kissing'
$var[1][8] = 'crook-pated'
$var[1][9] = 'dismal-dreaming'
$var[1][10] = 'dizzy-eyed'
$var[1][11] = 'doghearted'
$var[1][12] = 'dread-bolted'
$var[1][13] = 'earth-vexing'
$var[1][14] = 'elf-skinned'
$var[1][15] = 'fat-kidneyed'
$var[1][16] = 'fen-sucked'
$var[1][17] = 'flap-mouthed'
$var[1][18] = 'fly-bitten'
$var[1][19] = 'folly-fallen'
$var[1][20] = 'fool-born'
$var[1][21] = 'full-gorged'
$var[1][22] = 'guts-griping'
$var[1][23] = 'half-faced'
$var[1][24] = 'hasty-witted'
$var[1][25] = 'hedge-born'
$var[1][26] = 'hell-hated'
$var[1][27] = ''
$var[1][28] = 'ill-breeding'
$var[1][29] = 'ill-nurtured'
$var[1][30] = 'knotty-pated'
$var[1][31] = 'milk-livered'
$var[1][32] = 'motley-minded'
$var[1][33] = 'onion-eyed'
$var[1][34] = 'plume-plucked'
$var[1][35] = 'pottle-deep'
$var[1][36] = 'pox-marked'
$var[1][37] = 'reeling-ripe'
$var[1][38] = 'rough-hewn'
$var[1][39] = 'rude-growing'
$var[1][40] = 'rump-fed'
$var[1][41] = 'shard-borne'
$var[1][42] = 'sheep-biting'
$var[1][43] = 'spur-galled'
$var[1][44] = 'swag-bellied'
$var[1][45] = 'tardy-gaited'
$var[1][46] = 'tickle-brained'
$var[1][47] = 'toad-spotted'
$var[1][48] = 'unchin-snouted'
$var[1][49] = 'weather-bitten'
$var[2][0] = 'apple-john'
$var[2][1] = 'baggage'
$var[2][2] = 'barnacle'
$var[2][3] = 'bladder'
$var[2][4] = 'boar-pig'
$var[2][5] = 'bugbear'
$var[2][6] = 'bum-bailey'
$var[2][7] = 'canker-blossom'
$var[2][8] = 'clack-dish'
$var[2][9] = 'clotpole'
$var[2][10] = 'coxcomb'
$var[2][11] = 'codpiece'
$var[2][12] = 'death-token'
$var[2][13] = 'dewberry'
$var[2][14] = 'flap-dragon'
$var[2][15] = 'flax-wench'
$var[2][16] = 'flirt-gill'
$var[2][17] = 'foot-licker'
$var[2][18] = 'fustilarian'
$var[2][19] = 'giglet'
$var[2][20] = 'gudgeon'
$var[2][21] = 'haggard'
$var[2][22] = 'harpy'
$var[2][23] = 'hedge-pig'
$var[2][24] = 'horn-beast'
$var[2][25] = 'hugger-mugger'
$var[2][26] = 'joithead'
$var[2][27] = 'lewdster'
$var[2][28] = 'lout'
$var[2][29] = 'maggot-pie'
$var[2][30] = 'malt-worm'
$var[2][31] = 'mammet'
$var[2][32] = 'measle'
$var[2][33] = 'minnow'
$var[2][34] = 'miscreant'
$var[2][35] = 'moldwarp'
$var[2][36] = 'mumble-news'
$var[2][37] = 'nut-hook'
$var[2][38] = 'pigeon-egg'
$var[2][39] = 'pignut'
$var[2][40] = 'puttock'
$var[2][41] = 'pumpion'
$var[2][42] = 'ratsbane'
$var[2][43] = 'scut'
$var[2][44] = 'skainsmate'
$var[2][45] = 'strumpet'
$var[2][46] = 'varlot'
$var[2][47] = 'vassal'
$var[2][48] = 'whey-face'
$var[2][49] = 'wagtail'

; ---- Create array declaration from existing array -------
Local $sDeclar = "Local $aVar[" & UBound($var) & "][" & UBound($var, 2) & '] = ['
For $i = 0 To UBound($var) - 1
    $sDeclar &= '["'
    For $j = 0 To UBound($var, 2) - 1
        $sDeclar &= $var[$i][$j] & '", "'
    Next
    $sDeclar = StringTrimRight($sDeclar, 3) & '], _' & @CRLF & @TAB & @TAB ; New line.
Next
$sDeclar = StringTrimRight($sDeclar, 7) & ']'
ConsoleWrite($sDeclar & @LF)
; ----> End of Create array declaration from existing array -------


;-------------------------------- Erase down to here -------------------------------
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; This following declaration was copied from console.
Local $aVar[3][50] = [["artless", "bawdy", "beslubbering", "bootless", "churlish", "cockered", "clouted", "craven", "currish", "dankish", "dissembling", "droning", "errant", "fawning", "fobbing", "froward", "frothy", "gleeking", "goatish", "gorbellied", "impertinent", "infectious", "jarring", "loggerheaded", "lumpish", "mammering", "mangled", "mewling", "paunchy", "pribbling", "puking", "puny", "qualling", "rank", "reeky", "roguish", "ruttish", "saucy", "spleeny", "spongy", "surly", "tottering", "unmuzzled", "vain", "venomed", "villainous", "warped", "wayward", "weedy", "yeasty"], _
        ["base-court", "bat-fowling", "beef-witted", "beetle-headed", "boil-brained", "clapper-clawed", "clay-brained", "common-kissing", "crook-pated", "dismal-dreaming", "dizzy-eyed", "doghearted", "dread-bolted", "earth-vexing", "elf-skinned", "fat-kidneyed", "fen-sucked", "flap-mouthed", "fly-bitten", "folly-fallen", "fool-born", "full-gorged", "guts-griping", "half-faced", "hasty-witted", "hedge-born", "hell-hated", "", "ill-breeding", "ill-nurtured", "knotty-pated", "milk-livered", "motley-minded", "onion-eyed", "plume-plucked", "pottle-deep", "pox-marked", "reeling-ripe", "rough-hewn", "rude-growing", "rump-fed", "shard-borne", "sheep-biting", "spur-galled", "swag-bellied", "tardy-gaited", "tickle-brained", "toad-spotted", "unchin-snouted", "weather-bitten"], _
        ["apple-john", "baggage", "barnacle", "bladder", "boar-pig", "bugbear", "bum-bailey", "canker-blossom", "clack-dish", "clotpole", "coxcomb", "codpiece", "death-token", "dewberry", "flap-dragon", "flax-wench", "flirt-gill", "foot-licker", "fustilarian", "giglet", "gudgeon", "haggard", "harpy", "hedge-pig", "horn-beast", "hugger-mugger", "joithead", "lewdster", "lout", "maggot-pie", "malt-worm", "mammet", "measle", "minnow", "miscreant", "moldwarp", "mumble-news", "nut-hook", "pigeon-egg", "pignut", "puttock", "pumpion", "ratsbane", "scut", "skainsmate", "strumpet", "varlot", "vassal", "whey-face", "wagtail"]]

$Form1 = GUICreate("Press the button", 409, 98, 386, 242)
$Button1 = GUICtrlCreateButton("Click Me", 160, 56, 75, 25)
$Input1 = GUICtrlCreateInput("", 8, 16, 393, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY))
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $str = 'Thou ' & $aVar[0][Random(0, 49, 1)] & ' ' & $aVar[1][Random(0, 49, 1)] & ' ' & $aVar[2][Random(0, 49, 1)]
            GUICtrlSetData($Input1, $str)
    EndSwitch
WEnd
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...