Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by madpower2000. 07/22/26 14:01
ZorroGPT
by TipmyPip. 07/21/26 17:54
New Zorro version 3.11
by jcl. 07/21/26 13:42
Lapsa's very own thread
by Lapsa. 07/18/26 13:40
Purchase A8 full licence version
by ukgamer. 07/17/26 05:52
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (NorbertSz, 1 invisible), 4,775 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Ephraim, Student_64151
19223 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 4 1 2 3 4
Re: coding contest [Re: mk_1] #74739
06/08/06 17:49
06/08/06 17:49
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
well, maybe you're right, so i'll post another task. btw i think he meant odd numbers.
here's my approach, implementing the "sieve of erathostenes" (i think it's spelled like that) in assembler:

Code:
// ASMTest.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//

#include "stdafx.h"

#include <iostream>
#include <iomanip>

typedef unsigned __int32 DWORD;

int _tmain(int argc, _TCHAR* argv[])
{
DWORD a[32768];// = (*)(new DWORD[300]);
DWORD arr_length = sizeof(a) / sizeof(DWORD), upper_bound = (arr_length / 2);
DWORD m_ex;

for (int b = 0; b < arr_length; b ++)
a[b] = 0xFFFFFFFF;

__asm {
; go through all dwords up to AT LEAST the half count
; note on div
; edx:eax / [ecx|ebx] goes to eax (quotient)
; edx:eax % [ecx|ebx] goes to edx (rest)


; here comes the loop
mov ecx, 00h
loop_dword00:
; current value
;mov eax, a[ecx*4]
; push counter for the inner loop
push ecx

; loop through all bits of current dword
mov ecx, 00h
mov ebx, 01h
loop_bits00:
; get dword counter
pop edx
push edx

mov eax, a[edx*4]
mov edx, eax
and edx, ebx

; if bit is 0 move on to next bit
jz ignore00

; calculate bit position to pass as argument
; get dword counter
pop edx
push edx

; push current value & inner counter, bit pattern
;push eax
push ebx
push ecx

; dword counter * 32 + bit counter
mov eax, edx
mov edx, 20h
mul edx
add eax, ecx
add eax, 01h

; call function clearbits only
; if bit position is greater 1
cmp eax, 01h
jbe ignore02

; debug
;cmp eax, 02h
;ja finish

; argument 1
mov m_ex[00h], eax
call clearbits


ignore02:

; restore current value & inner counter, bit pattern
pop ecx
pop ebx
;pop eax
ignore00:

shl ebx, 01h

inc ecx
cmp ecx, 20h
jb loop_bits00


; pop counter
pop ecx

inc ecx
cmp ecx, upper_bound
jbe loop_dword00

; don't execute functions
jmp finish

; clears all bits that are multiples of eax
clearbits:
; argument 1
mov eax, m_ex[00h]

; calculate dword and bit offset
mov edx, 00h
mov ebx, 20h
div ebx

; here comes the loop
mov ecx, eax
mov ebx, edx
loop_dword01:
; calculate new dword and bit offset
push ebx

mov eax, m_ex[00h]
mov edx, 00h
mov ebx, 20h
div ebx

pop ebx

; dword position
add ecx, eax

; bit offset
add ebx, edx

cmp ebx, 20h
jbe ignore01
add ecx, 01h
sub ebx, 20h
ignore01:

cmp ecx, arr_length
jae return01
; current value
mov eax, a[ecx*4]

; ecx is now dword offset
; ebx bit offset, so clear this bit
push ecx

mov cl, bl
sub cl, 01h
mov edx, 01h ; 00000001
shl edx, cl ; 00001000
or eax, edx
xor eax, edx

pop ecx
; store current value
mov a[ecx*4], eax

jmp loop_dword01
return01:
ret

finish:
}

DWORD mask, count = -1;

for (int b = 0; b < arr_length; b ++) {
mask = 0x00000001;
std::cout << "a[" << std::setw(4) << std::setfill('0') << b << "] = [;
for (int i = 0; i < 32; i ++) {
std::cout << (( a[b] & mask) ? (++count, "1") : "0");
mask <<= 1;
}
std::cout << "]" << std::endl;
}
std::cout << "E = " << count << std::endl;

return 0;
}



output is a bit weird, and i haven't measured time, though i think that simply by the use of this algrithm it's faster than the brute-force approach.

ok, here's your next task

you've got an ip, consisting of four bytes (integer values from 0 to 255). example: 225.152.3.34.
what you should do is paste an algorithm, that transforms this number in a string consisting of letters (only minuscles such as 'a', 'b', not 'A') and numbers from '0' to '9'. the one with the shortest string for all ip's that exist wins the contest.

note that the algorithm has to be reversible!

example for 225.152.3.34: your string that your algorithm gives out is 'gb2sl35b1', that makes 9 characters. your algorithm must be able to transform this back to 225.152.3.34.

i'll post my approach later on.

greetings, joey.

Re: coding contest [Re: Joey] #74740
06/08/06 19:57
06/08/06 19:57
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
5 letters without compression and I don't think compression is possible...

Last edited by mk_1; 06/08/06 20:01.

Follow me on twitter
Re: coding contest [Re: mk_1] #74741
06/09/06 11:08
06/09/06 11:08
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
5 letters? wow, that's good. my best one was 7 characters. i just take 0xffffffff and transform this digit into 1z141z3 to base 36, though i think that there's some space wasted. but 5? you've got to prove it

good work!

joey.

Re: coding contest [Re: Joey] #74742
06/09/06 13:09
06/09/06 13:09
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
hm... i came to the conclusion that 4 bytes can be encoded into 6 of the letters you mentioned after thinking about it for a minute. still some space wasted but i don't know how to use that space.

Re: coding contest [Re: ventilator] #74743
06/09/06 15:14
06/09/06 15:14
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
you've got to explain that to me... how do you store 4 8 bit values into 6 ~5 bit spaces?

Re: coding contest [Re: Joey] #74744
06/09/06 15:42
06/09/06 15:42
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
i didn't think about it long enough previously. actually you are right. i don't think it's possible under 7 so please prove it mk_1! i don't quite get the point of this contest though since the outcome always is quite clear anyway. i don't think anyone will find new unknown algorithms for anything here.

Re: coding contest [Re: mk_1] #74745
08/09/06 04:47
08/09/06 04:47
Joined: Dec 2003
Posts: 1,220
Just down the road from Raven
BlueBeast Offline
Serious User
BlueBeast  Offline
Serious User

Joined: Dec 2003
Posts: 1,220
Just down the road from Raven
Quote:

Programmers are - unlike most other game designers - always working.




Did you keep a straight face when writing that one? LOL




Jason


Gamestudio Pro 6.4
Pentium 4 3.0 GHz 800MHz BUS
AtiRadeon 9800 pro 256Mb 21" Monitor
1 Gig DDR RAM
36 Gig RAPTOR SATA+ 120 Gig SATA
SB Audigy 2 w/ 450 watt Logitech Z680 5.1

www.nordicepitaph.com
Re: coding contest [Re: BlueBeast] #74746
08/10/06 09:26
08/10/06 09:26
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
I'm sorry. I think it's 6 characters

Quote:

Did you keep a straight face when writing that one? LOL



Yes. Programmers never really have time to create a script "just for fun" or for a portfolio ... unlike modelers


Follow me on twitter
Re: coding contest [Re: mk_1] #74747
08/10/06 10:42
08/10/06 10:42
Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
Machinery_Frank Offline
Senior Expert
Machinery_Frank  Offline
Senior Expert

Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
That is not true. Every programmer plays around with commands and functions in the beginning and creates useless code just to look how the code works. The same is what an artist does.

Programmers offer little code samples or small games as a portfolio like modellers do with their models. I do not see big differences since I am a programmer here in my office at day and try to be an artist at home in the evenings. It is all the same: hard work, trial and error, learning, practicing and improving. Art has the big advantage that you are more free and can be more creative because there is no syntax that downsizes your comprehension. With tools like ZBrush, with normalmaps and a decent mesh you can do whatever you can imagine. Programmers often have a more constraint job. You cannot easily write an AI. That is hard work even when you can imagine every detail clear in your head.

But at the end it is all the same hard work to do and there is no need to start a war between programmers or artists.


Models, Textures and Games from Dexsoft
Re: coding contest [Re: Machinery_Frank] #74748
08/10/06 12:52
08/10/06 12:52
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
There's a difference. You can stop working on a model and work on another fun out of pure joy. But you can't stop working on a big code and continue another one. At least not as easy as for models, music, etc. because this is basically art and as long as you come up with new ideas you can continue. Programming is math and logical solutions and you can't divide either of them in small parts.


Follow me on twitter
Page 2 of 4 1 2 3 4

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1