Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ok, then: Obfuscation anyone?
#1
Ok, you asked for it:
The eight-line iterative quicksort (minus the array creation and printing).

Code:
'initialize an array.
a.max% = 50: DIM array1(a.max%) AS INTEGER

'generate random numbers
RANDOMIZE TIMER
CLS : FOR i% = 1 TO a.max%: array1(i%) = INT(RND * 5000) + 1: NEXT i%

1 DIM g2%(a.max% / 2), h2%(a.max% / 2), g3%(a.max% / 2), h3%(a.max% / 2): e% = 1: f% = 0: g2%(1) = 0: h2%(1) = a.max%
2 FOR d% = 1 TO e%: g% = g2%(d%): h% = h2%(d%): i% = 0: j% = 0: k% = 0: IF g% >= h% THEN GOTO 8 ELSE IF h% > g% THEN GOTO 3: IF array1(g%) <= array1(h%) THEN GOTO 3: SWAP array1(g%), array1(h%): GOTO 8
3 SWAP array1(h%), array1(INT(RND * (h% - g% + 1)) + g%): k% = array1(h%)
4 i% = g%: j% = h%
5 IF i% < j% AND array1(i%) <= k% THEN i% = i% + 1: GOTO 5
6 IF j% > i% AND array1(j%) >= k% THEN j% = j% - 1: GOTO 6 ELSE IF i% < j% THEN SWAP array1(i%), array1(j%): GOTO 4 ELSE SWAP array1(i%), array1(h%)
7 IF i% + i% - g% < h% THEN f% = f% + 1: g3%(f%) = g%: h3%(f%) = i% - 1: f% = f% + 1: g3%(f%) = i% + 1: h3%(f%) = h% ELSE f% = f% + 1: g3%(f%) = i% + 1: h3%(f%) = h%: f% = f% + 1: g3%(f%) = g%: h3%(f%) = i% - 1
8 NEXT d%: FOR i% = 1 TO f%: g2%(i%) = g3%(i%): h2%(i%) = h3%(i%): NEXT i%: e% = f%: f% = 0: IF e% <> 0 THEN GOTO 2

'print it
PRINT "Final sorted array: ": PRINT
FOR i% = 1 TO a.max%: PRINT array1(i%); : NEXT i%

ph34r mY l33t c0|)iNG 5KiLL5!
:rotfl: :rotfl:
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#2
I thought this might be more useful for anyone actually wanting to use this. (It IS 5 times faster in QB than recursive quicksort..) It preserves the identity of each number. Both the value of each array index and the index itself is swapped.

Code:
'initialize an array.
a.max% = 50:  DIM array1(a.max%) AS INTEGER, array2(a.max%) AS INTEGER

'generate random numbers
RANDOMIZE TIMER
CLS : FOR i% = 1 TO a.max%: array1(i%) = INT(RND * 5000) + 1: NEXT i%

FOR i% = 1 TO a.max%: array2(i%) = i%: NEXT i%

1 DIM g2%(a.max% / 2), h2%(a.max% / 2), g3%(a.max% / 2), h3%(a.max% / 2): e% = 1: f% = 0: g2%(1) = 0: h2%(1) = a.max%
2 FOR d% = 1 TO e%: g% = g2%(d%): h% = h2%(d%): i% = 0: j% = 0: k% = 0: IF g% >= h% THEN GOTO 8 ELSE IF h% > g% THEN GOTO 3: IF array1(g%) <= array1(h%) THEN GOTO 3: SWAP array2(g%), array2(h%): SWAP array1(g%), array1(h%): GOTO 8
3 r% = INT(RND * (h% - g% + 1)) + g%: SWAP array1(h%), array1(r%): SWAP array2(h%), array2(r%): k% = array1(h%)
4 i% = g%: j% = h%
5 IF i% < j% AND array1(i%) <= k% THEN i% = i% + 1: GOTO 5
6 IF j% > i% AND array1(j%) >= k% THEN j% = j% - 1: GOTO 6 ELSE IF i% < j% THEN SWAP array2(i%), array2(j%): SWAP array1(i%), array1(j%): GOTO 4 ELSE SWAP array1(i%), array1(h%): SWAP array2(i%), array2(h%)
7 IF i% + i% - g% < h% THEN f% = f% + 1: g3%(f%) = g%: h3%(f%) = i% - 1: f% = f% + 1: g3%(f%) = i% + 1: h3%(f%) = h% ELSE f% = f% + 1: g3%(f%) = i% + 1: h3%(f%) = h%: f% = f% + 1: g3%(f%) = g%: h3%(f%) = i% - 1
8 NEXT d%: FOR i% = 1 TO f%: g2%(i%) = g3%(i%): h2%(i%) = h3%(i%): NEXT i%: e% = f%: f% = 0: IF e% <> 0 THEN GOTO 2

'print it
PRINT "Final sorted array: ": PRINT
FOR i% = 1 TO a.max%: PRINT array1(i%); : NEXT i%
FOR i% = 1 TO a.max%: PRINT array2(i%); : NEXT i%
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
I killed this Forum, didn't I? :normal:
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#4
*shoots agamemnus* fair game!

i dont know, maybe this would be more popular if we when the abc routine and made a bunch of challenges with no time limit. then people could work on whatever they liked.

i recall neozone's always doing well, and it had a monthly call to programming arms, so that might be a good route too. i like the former method better though.

we'll see. i'll play with some obsu-whatever code, but i might just end up turning in one of my real programs Smile whatever.

a fun challenge i once say was some guy on the chat room giving out c programs where it took an input and did a simple task, but you had to guess the input that would crash the program. it's easier to do that in c because there arent so many babysitting safeguards like there are in qb but it could be worth a try if anyone can come up with any...
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#5
How about this for a challenge:

Design a program which performs a trivial task, but which people have to guess what it does *without* actually running it.

And just to stop cheaters from simply running it, you also have to explain how the program does it and why it's so hard to read.
Reply
#6
Hmmm... :???:.
Code:
A% = 26 * 5 / 10: B% = &H9FFF: SCREEN A%: DEF SEG = B% + 1: DO WHILE NOT C& = ((7999.375) * 8) + 5: D& = (COS(270) * 4) - SIN(180) + SIN(180): POKE C&, D&: C& = C& + (2 - ((2 * 2) - 3)): LOOP
Reply
#7
A% = 26 * 5 / 10
' A% = 26 * 1/2
' A% = 13
B% = &H9FFF
SCREEN A%
' SCREEN 13
DEF SEG = B% + 1
' B% + 1 = &H9FFF + 1 = &HA000, screen 13 segment.
DO WHILE NOT C& = ( (7999.375) * 8 ) + 5
' 7999.375 * 8 = 6395
' 63995 + 5 = 64000, number of pixels in screen 13, 320x200.
D& = (COS(270) * 4) - SIN(180) + SIN(180)
' COS(270) = .98. COS(270) * 4 = 3.94, or 4 as integer.
' SIN(180) + SIN(180) = 0, 3.94 + 0 = 3.94.
POKE C&, D&
' C& = offset, D& = 3.94, which is interpreted as 4, red,
' since POKE takes integer arguements.
C& = C& + (2 - ((2 * 2) - 3))
' 2 * 2 = 4
' 4 - 3 = 1
' 2 - 1 = 1
' C& = C& + 1
LOOP

So it sets screen 13, points to video memory, loops thru every pixel and plots a red dot, making all the screen red.

There you go Wink
Reply
#8
Great Big Grin.
Reply
#9
Here's a more difficult one Big Grin...:roll:.
Code:
SCREEN &HF - 2
A$="16171819202122232425262728293031161718192021222324252627282930311617181920212223242526272829303116171819202122232425262728293031161718192021222324252627282930311617181920212223242526272829303116171819202122232425262728293031161718192021222324252627282930311617181920212223242526272829303116171819202122232425262728293031"
: DO: FOR D% = 0 TO 9: FOR C% = 0 TO 15: IF B% = &HFE + 1 THEN B% = 0
LINE (C% * (10 + (5 + (2 * 2) + 1)), D% * (10 + (5 + (2 * 2) + 1)))-((C% * (10 + (5 + (2 * 2) + 1))) + 19, (D% * (10 + (5 + (2 * 2) + 1))) + 19), B% + VAL(MID$(A$, ((D% * 2) * (4 * 4)) + (C% * (4 - 2)) + 1, (-4 + 6))), BF: NEXT C%, D%: WAIT &H3DA, 8: B% = B% - (4 - 5): LOOP
Reply
#10
You wanna have an obfuscating one? :-D

HAR 13h++
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)