Dapianokid said his took 11 seconds to compute the 42nd prime palindrome, but from the conversation, he may have a much more efficient algorithm for larger values. I think his was also running at 150MHz, so I am not sure.
Has anybody set any benchmarks for other languages?
So, I am curious, too, with what Runer is asking. For example, in TI-BASIC, although we could make a program to handle arbitrary precision, can we safely assume that we will only be using up to 14-digit numbers?
Spoiler For My Current Results:
(TI-BASIC, TI-84+SE) Currently, my program can find the following values in the following time: 42:prgmPALPREM , 23 seconds, returns 18181 100:prgmPALPREM , 88 seconds, returns 94049 290:prgmPALPREM , 682 seconds, returns 1958591
These are big improvements over previous versions: 42 : 44→40→30→27→23 100: 280→199→135→101→88 290: 4700→2256→1375→732→682
So it has been getting a lot faster for larger numbers, but it still takes 12.2 minutes to compute the 290th term I have only been modifying the prime testing routine each time, but maybe if I can make the palindrome generating routine faster, I can get better times o.o EDIT: Updated stats with version 5
Inspired by Round 2 of the 2013 TI-Concours BASIC category, I made this assembly program to test if a number is digisible. A number is digisible if every digit of the number divides the whole number evenly. Since you cannot divide by 0, every number with a 0 in it is automatically not digisible. So the input is a positive integer, and the output is text drawn to the screen where 0 = not digisible, 1=digisible.
So here is what I was wondering: How fast or small can you make a program like this in assembly? My version takes a string input, so long as it fits in RAM and properly outputs a result. It is also 140 bytes on the calculator, so I am thinking it could be made a bit smaller (I think it is 122 bytes of code).
Hopefully I will remember to convert the code to readable source code, later. My approach is to keep track of which digits are in the sequence while finding the value of the string mod 2520 (every digit 1~9 divides 2520). Then, check to see if each present digit divides that value. At the same time, if any value appears that is not 1~9, it returns 0, so this takes care of non-integers and integers with a 0 in their digit expansion.
Aha, nice! The way you used A for two purposes is clever. You can also use 'xor a' or 'sub a' as a clever way of setting A=0. It saves a byte, among other things.
ld hl,plotSScreen ld bc,768 Loop: ld (hl),0 inc hl dec bc ;test if bc=0 ld a,b or c jr nz,Loop ret That is a routine that has a lot of optimising that can be done to it, but it might be easier to follow than some of the following.
;alter the above code, saving 2300 t-states ld hl,plotSScreen ld bc,300h ;300h = 768. So C=0, B=3 ld a,c Loop: ld (hl),a ;1 byte, 7 cycles, compared to 'ld (hl),0' which is 2 bytes, 10 cycles inc hl dec bc ;test if bc=0 ld a,b or c jr nz,Loop ret
;alter the above code to replace everything after 'inc hl' ;saves 7675 t-states, so 9975 t-states saved in all so far. Also a few bytes smaller. ld hl,plotSScreen ld bc,300h ;300h = 768. So C=0, B=3 ld a,c Loop: ld (hl),a cpi ;not using it for its inteaded use. Still, increments HL, decrements BC, checks if BC is 0 jp pe,Loop ret ;25378 t-states, 14 bytes Here is a different approach:
ld hl,plotSScreen ld bc,3 ;768 = 300h, but here we load 3 into C, 0 in B sub a ;set A=0, more optimised than 'ld a,0' Loop: ld (hl),a inc hl djnz Loop dec c jr nz,Loop ret ;15 bytes, 19789 t-states
Wow, that looks pretty nice o.o I have very little knowledge in dithering stuff, but you will definitely find people here with assembly knowledge! So, what are you working on?
I am not sure if this is a problem that was introduced or something else, but when I compile the code and click 'download', I am redirected to http://clrhome.org/lib/404.php
The first time I did this, I lost my code (but I remembered it all, so I recovered it quickly).
EDIT: Actually, it seems to be doing the same for quite a few in-site links.
I am not familiar with matlab, but does it allow for the following:
Vector Addition/Subtraction and indirection
-or-
Matrix row operations
I would assume it had some way to do these. I did a quick search and you could probably do something like this:
First, review the following matrix rows of the form [[D1,H1,H2,H3,V1,V2,V3,D2]] [a]=[[1,1,0,0,1,0,0,0]] [b]=[[0,1,0,0,0,1,0,0]] [c]=[[0,1,0,0,0,0,1,1]] [d]=[[0,0,1,0,1,0,0,0]] [e]=[[1,0,1,0,0,1,0,1]] [f]=[[0,0,1,0,0,0,1,0]] [g]=[[0,0,0,1,1,0,0,1]] [h]=[[0,0,0,1,0,1,0,0]] [i]=[[1,0,0,1,0,0,1,0]] Then in MatLab you will want to define your matrix like this (from what I saw):
A = [1,1,0,0,1,0,0,0; 0,1,0,0,0,1,0,0; 0,1,0,0,0,0,1,1; 0,0,1,0,1,0,0,0; 1,0,1,0,0,1,0,1; 0,0,1,0,0,0,1,0; 0,0,0,1,1,0,0,1; 0,0,0,1,0,1,0,0; 1,0,0,1,0,0,1,0; 0,0,0,0,0,0,0,0] Notice that the last row is comprised of all zeros. This is the row holding all of the information about the moves taken in the game. From here, I cannot help much more (this is my first experience with MatLab), but from what I see, if the user selects a position a,b,c,d,e,f,g,h,i, that corresponds to rows 1,2,3,4,5,6,7,8,9 in the matrix. Where B is 1 or -1 depending on the turn (X or O) and C is the row:
A(C,1) = .5 I have no clue if that works, but I was trying to set the first element in the row to .5. That way, you can just check if the first element is .5.
I have no clue what easy tricks or methods there are to test if an element in the last row is 2,-2, 3, or -3. In TI-BASIC, we can simply extract the last row as a list, then do something like '2=L1' and it returns a list of boolean values, 1 means the list element is 2, 0 means it wasn't. We could do sum(2=L1) and it will return 0 if no elements are 2, some other positive integer otherwise. I have no clue if anything like this can be done in MatLab, sorry
EDIT: Also, I would like to point out that you registered at 11:23:53. If that last digit was an 8, that would have been rather awesome o.o
Another method that you might be interested in works like this: Say you have 10 different tiles and numbers are stored with 14 digits of precision. You can then store each map layer with the nth digit in the number. To access the map in TI-BASIC code:
10fPart(10^-N[A] If you aren't familiar with TI-BASIC, fPart( simply grabs the decimal part of a number (leaving off the integer part). If the language you are using doesn't have that, there is probably some equivalent to a floor() function (round down to the nearest integer) and you would essentially do #-floor(#).
If you have M different tiles, you can theoretically store up to floor(14/log(M)) different maps in a single matrix element, this way. However, I would go with 1 less than that to avoid precision problems. Your code for extracting a given matrix would be to replace the 10 in the above code with M.
I hope to see more ideas Encoding data with primes and properties of numbers can have some pretty interesting effects.
That's a very interesting method! There are only two small downsides it really has: one is being limited to a maximum of 10 features before it reduces your storage capability by half. But when you use two decimal places for each tile instead of 1 you can store as many as 100(!) different tiles, allowing you to store maps that are more artistic, while still reducing your storage by a factor of 6 (I take 12 decimal places as the limit just to make sure I don't go over it, otherwise the factor would be 7 (14/2)). The second is that this storage method is far less efficient when you use it with maps that don't need 10 different features, but even so it is more efficient than my method since it allows for up to 13 maps to be stored in a single matrix as opposed to my 12 maps which is only in the best-case-scenario of using only 1 terrain feature.
Hmmm... I think I might change the first post a bit to make this thread more of a discussion for different methods to compress maps, and perhaps even to simply 'compression methods' if the need to discuss compression for data other than maps arises.
If you use the method explained a little later, you can use a map with something like 5 features and get 20 maps in one matrix. With only 2 features, you can get 46 maps in one matrix because 14/log(2) is about 46.5. I used 10 as an example because it would be easier to think of each layer as a digit in base 10 instead of a digit in base M If you wanted to use up to 30 tiles, you could get floor(14/log(30))=9 maps.
But I did think of another way to get a few more maps, just now. Floating Point numbers usually have a separate bit to store whether it is negative or positive, so you actually probably have 2*1014-1 numbers to work with. That is how it works on the TI calculators, anyway (1014-1 negative numbers, 1014-1 positive numbers, and 0).
Ooh, I just had an idea for quickly checking (with your method). For example, a 4-feature map will use 2,3 for the first layer, 5,7 for the second, and so on. Then to check layer 1, simply use gcd() of the matrix element and 6. The second layer, use the matrix element and 35 and so on. Then you just check if the value is {1,2,3,6} or {1,5,7,35} et cetera, corresponding to the tile.
Another neat method for storing maps is to use dynamic tiles that change based on the tiles it is in contact with. For example, a trick I used in TI-BASIC for storing map data for a maze was to store to a picture (black and white) the map. When drawing a tile, it would test the corresponding pixel, then check above, below, and to either side to see precisely which tile was needed. In this way, you could store a tilemap using a single bit for each tile, using 16 tiles, which is a rather crazy level of compression. In normal circumstances, you need at least 4 bits for each tile if you have 16 tiles (2^4=16). When I took remade it in assembly, it compressed a 32*32 map (1024 tiles) to 128 bytes, using 16 unique tiles. In pure TI-BASIC I think the best compression I could get would be using a 19-element list (a little over 171 bytes).
Here is a screenshot of one of the many offshoots I made using this technique:
Instead, i'll probably go for a new programming language. I really like the idea of making it real-time. But it's quite a challenge, since parsing & executing at the same time eats some cycles. I'm curious to see how fast it can be (compared to ti-basic)...
Already, asmdream could be converted into a powerful language on its own. If you take out the compiling menu stuff and simply run through the source code throwing in bonus functions like for drawing, output/input, and loops, it doesn't matter if it is slower. It would still be a very powerful language with how versatile you have made macros.