Qbasicnews.com
May 29, 2020, 03:50:44 AM
 Pages: [1]
 Author Topic: Ok, then: Obfuscation anyone?  (Read 7783 times)
Agamemnus
x/ \z

Posts: 3491

 « on: March 07, 2003, 02:55:48 PM »

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:
 Logged

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.
Agamemnus
x/ \z

Posts: 3491

 « Reply #1 on: March 07, 2003, 03:24:41 PM »

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%
 Logged

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.
Agamemnus
x/ \z

Posts: 3491

 « Reply #2 on: March 15, 2003, 03:30:05 PM »

I killed this Forum, didn't I?  :normal:
 Logged

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.
toonski84
__/--\__

Posts: 2567

 « Reply #3 on: March 15, 2003, 03:50:02 PM »

*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  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...
 Logged

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
someone42
Member

Posts: 44

 « Reply #4 on: March 26, 2003, 06:37:45 AM »

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.
 Logged
BlueKeyboard
Wandering Guru

Posts: 337

 « Reply #5 on: March 26, 2003, 02:08:11 PM »

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
 Logged

Joakim
Senior Member

Posts: 230

 « Reply #6 on: March 26, 2003, 04:32:38 PM »

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
 Logged
BlueKeyboard
Wandering Guru

Posts: 337

 « Reply #7 on: March 26, 2003, 06:15:26 PM »

Great .
 Logged

BlueKeyboard
Wandering Guru

Posts: 337

 « Reply #8 on: March 27, 2003, 12:46:11 PM »

Here's a more difficult one ...: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
 Logged

Neo
Na_th_an

Posts: 2150

 « Reply #9 on: March 31, 2003, 06:42:18 AM »

You wanna have an obfuscating one? :-D

HAR 13h++
 Logged
Agamemnus
x/ \z

Posts: 3491

 « Reply #10 on: March 31, 2003, 10:14:04 AM »

Does it draw your letters? (name?), keyboard? Oh, er, I guess not errrrrr
 Logged

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.
BlueKeyboard
Wandering Guru

Posts: 337

 « Reply #11 on: March 31, 2003, 02:23:16 PM »

Hmmm..., let me give you a clue:
It's "moving"...
Hmmm, hard to tell without telling too much... .
 Logged

seph
Na_th_an

Posts: 1915

 « Reply #12 on: May 26, 2003, 04:52:08 PM »

Quote from: "BlueKeyboard"
Here's a more difficult one ...: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

Hmm, is this accurate?

Code:
SCREEN 13
A\$="16171819202122232425262728293031161718192021222324252627282930311617181920212223242526272829303116171819202122232425262728293031161718192021222324252627282930311617181920212223242526272829303116171819202122232425262728293031161718192021222324252627282930311617181920212223242526272829303116171819202122232425262728293031"
DO
FOR D% = 0 TO 9
FOR C% = 0 TO 15
IF B% = &HFE + 1 THEN B% = 0
LINE (C% * 20, D% * 20)-((C% * 20) + 19, (D% * 20) + 19), B% + VAL(MID\$(A\$, (D% * 32) + (C% * 2) + 1, 2)), BF
NEXT C%, D%
WAIT &H3DA, 8
B% = B% + 1
LOOP

Basically it will draw every colour from 16 to 31 over and over on the screen, and it will "scroll" them from right to left. You just kinda made the equations needlessly complicated LOL
 Logged

earn.
 Pages: [1]