Discuss and collaborate on GML scripts

You are not logged in.

- Topics: Active | Unanswered

pow = string_length(string_digits(frac(number)))

There's nothing in that line that turns number into a string. It'd also probably be faster and more accurate to multiply by 2 (and by more accurate I mean the rational result will be exact insofar as the double data type is concerned).

I guess I missed seeing this. This script could actually be used to reduce large powers of some number module another. Euler's theorem states the following:

a^phi(m) === 1 (mod m)

if GCD(a, m) = 1.

That is, a to the phi(m) is congruent to 1 (mod m) where phi is Euler's totient function. For example:

Find the last two digits of 3^39 in base 10. Well, phi(100) = 40, so 3^40 === 1 (mod 100), so 3^-1 * 3^40 === 3^-1 (mod 100). So, we need only find the multiplicative inverse of 3 mod 100. 3*33 === -1 (mod 100) => 3*(-33) === 1 (mod 100) => 3*67 === 1 (mod 100), so the last two digits of 3^39 are 67.

Similarly the last two digits of the following are:

3^40 = 01

3^41 = 03

3^42 = 09...

Yes, both a real and a string can be stored in a record simultaneously. However, I don't know why that's useful since you'd only be able to access one from GM. Additionally, the type identifier might cause it to only load the correct type and just ignore the other.

One thing you could do is transform a bunch of lists into a grid or vice-versa where each list is a column. It also allows you to quickly slice lists and change them between stacks and queues. However, I think some people used that trick a long time ago (but just supplying the entire string into the read function of a different data structure, rather than reformatting it).

It's almost a straight memory dump but in hex. Here's a little text file I cooked up back when I decided to figure the format out for use from a DLL. It's quite a verbose format, which is why I'd prefer base 64.

All of GM's data structure's seem to output what is essentially a hex encoded memory dump of the

data structure. This means that all integers and doubles are encoded in little-endian format.---------------------------------------------------------------------------------------------------

list, stack, queue:

Offset Size (b) Information

0x00 4 DS identifier (see below)

0x04 4 (int) number of elements in structure

Element record

{

0x00 4 Indicates whether element is a string (1) or real (0)

0x04 8 IEEE 754 double

0x0C 4 (int) Length of following string field (0 if not present)

[0x10 (0x0C) bytes contained in string (only present if previous field != 0)]

}

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

map, pqueue:

Offset Size (b) Information

0x00 4 DS identifier (see below)

0x04 4 (int) number of elements in structure

Key/Priority record

{

0x00 4 Indicates whether element is a string (1) or real (0)

0x04 8 IEEE 754 double

0x0C 4 (int) Length of following string field (0 if not present)

[0x10 (0x0C) bytes contained in string (only present if previous field != 0)]

}

Value record

{

Same as above

}Maps store their keys in order first. Then the values are recorded in order. For keys, real

values come before strings. Priority queues are similar in that the priorities are stored before

their associated values, however the priorities are unsorted and show up in the order that they

were added to the queue.

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

grid:

Offset Size (b) Information

0x00 4 (0x59020000)

0x04 4 (int) width

0x08 4 (int) height

Element record

{

0x00 4 Indicates whether element is a string (1) or real (0)

0x04 8 IEEE 754 double

0x0C 4 (int) Length of following string field (0 if not present)

[0x10 (0x0C) bytes contained in string (only present if previous field != 0)]

}Elements are stored in column-major order.

===================================================================================================

Identifers:

list: 0x2D010000

stack: 0x65000000

queue: 0xC9000000map: 0x91010000

pqueue: 0xF5010000grid: 0x59020000

No, I haven't tested its speed at all. I don't know what you mean about accuracy, though. This won't lose any accuracy.

I really wish GM used Base64 instead of Hexadecimal for these strings, though. Hexadecimal is too big.

What is?

**Yourself**- Replies: 8

```
{
var l1, l2, s1, s2, sr, n, hex;
hex = "0123456789ABCDEF";
l1 = argument0; l2 = argument1;
s1 = ds_list_write(l1); s2 = ds_list_write(l2);
sr = string_copy(s1, 1, 8);
n = ds_list_size(l1) + ds_list_size(l2);
repeat (4) {
sr += string_copy(hex, ((n & $f0) >> 4) + 1, 1)
+ string_copy(hex, (n & $0f) + 1, 1);
n = n >> 8;
}
sr += string_delete(s1, 1, 16) + string_delete(s2, 1, 16);
ds_list_read(l1, sr);
return l1;
}
```

Takes two lists as arguments and appends the contents of the second list to the first.

Yes, that's the system I'm using. The system does cache the images as well.

My server already had dvips and such installed, I just had to install the PHP scripts and such for the editor and renderer.

I still haven't integrated it to the extent that I want to. I'd like to be able to use a WYSIWYG editor with an equation button. Behind the scenes I have an FCK Editor plugin for Wordpress installed, but getting all this to work is kind of a headache. Ultimately I think I'd like a little WYSIWYG editor for the comments as well so people can do their own equations.

**Yourself**- Replies: 5

http://blog.ultimatepronoun.com/

Yeah, I suck.

I always use "they" for that.

Keep in mind GM is for beginners.

What does that have to do with anything? You don't have to make a bad language to make one that's easy to learn or use. Python is a clear example of this. It's easy to learn and use but still very powerful.

It's like hating playdough for not being as good as proper modeling plasticine.

What a stupid analogy. Both substances are meant for completely different purposes and have little in common with a programming language. Do beginning sculptors use play-doh? No. Besides, play-doh doesn't have any real shortcomings. It does exactly what it's meant to do and it does it very well. GML does what it was meant to do, but it doesn't do it well. Big difference.

Have you ever fooled with PyGame?

I've looked at it, but never actually done anything with it.

I hate GML. As a language it's just very poor. If GM just used Python...

repeat(4)

width+=file_bin_read_byte(file);

For one, that's not how little-endian 32-bit integers work. You can't just add the byte values together. Just like how 1111 doesn't have the value "4". You're completely ignoring place value.

This would be much faster:

```
var a, p, m;
a[1] = 2; a[3] = 4; a[5] = 2; a[7] = 2; a[9] = 2;
if (argument0 mod 2 == 0) return false;
if (argument0 mod 3 == 0) return false;
p = 5;
m = sqrt(argument0);
while (p < m) {
if (argument0 mod p == 0) return false;
p += a[p mod 10];
}
return true;
```

That one took me a few minutes to come up with. I had to recover from being stunned first.

the sum of N identically independentally distributed random variables, subtract the mean from each

By definition of the mean that sum would be 0.