Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - rickclark58

Pages: [1] 2
1
Programs / Re: Code Breaker
« on: September 21, 2021, 06:23:45 pm »
The Mastermind game has a number of algorithms associated with it that might be of use. https://en.wikipedia.org/wiki/Mastermind_(board_game)

2
QB64 Discussion / Re: Free Data Structures and Algorithms Book
« on: September 21, 2021, 01:13:52 pm »
I came across this list of books. Quite a bit there. https://github.com/RbkGh/Free-Algorithm-Books

3
QB64 Discussion / Re: A Question on Sorting
« on: September 19, 2021, 09:00:57 pm »
The indexes contain key values like an account number. When you save the record, the account number is inserted into the index tree in the proper order. So if the account number is 100 it would be inserted into the tree right after 99. Normally, the records are contained in a block, say 100 records per block. The location of the record in the block is recorded with the account number. So, when you need to load account 100 again, the program looks through the index and finds 100, and then retrieves the location of the record within the block. It would then seek to that location and load the record.

Typically records have a header and the start of the header is actually what is stored in the index. The header is a fixed length, so the program knows how much data to read. After reading the header, the file pointer would be sitting at the beginning of the record. The program would read the record header to find out how long the record is and then load the record based on the length in the header. That way you can have variable length records which will save space and makes it faster to retrieve data.

This is a very simplified explanation and this isn't something that you would code yourself. You could use SQL Lite for instance, and simply query the database for account number 100. Using a database, you can get 1 record or 100 with a simple query, which makes it much easier to manipulate this kind of data. You can do something like "Select * from customers where account_number = 100". If the record is there, it will return it to the program where you can access the data within the record. The star means to grab all the fields in the record. Customers would be a table that contains the data. You can also do things like join multiple tables and return the information as if it were one table. It is quite handy when you get the hang of it and very powerful.

It was quite straightforward to load a database with preexisting data too as there are built-in commands to do such a thing. It is actually quite common in many businesses.  When I worked for Ford Motor Finance, we would get a daily dump from the mainframe that we would load into the Oracle database every day. Once you set it up, it is an automatic process. I am not suggesting you use a database for your data, as I don't really know what you are doing with it. Managing datasets has always been a problem, which is why almost everyone uses a database if they are working with a lot of data. It is just easier.

4
QB64 Discussion / Free Data Structures and Algorithms Book
« on: September 19, 2021, 12:05:50 pm »
Since I have not coded consistently in quite a while I wanted a refresher course on data structures and algorithms and I found a good free textbook on the subject. The book uses pseudocode and explains each topic quite well. This is an introductory textbook so it isn't all that math-heavy but it does explain the Big O notation and how it relates to relevant topics. I would definitely rate it a 4 out of 5 stars for an intro course. Here is the link if you are interested. It is free and in PDF format. https://open.umn.edu/opentextbooks/textbooks/171.

5
QB64 Discussion / Re: A Question on Sorting
« on: September 19, 2021, 11:32:22 am »
Just to add a bit more to the discussion in relation to sequential files. I am not saying this applies to your problem, but this problem has been around since the beginning. Back in the day, most data was stored as sequential files and as the number of records (an individual line in a sequential file) grew so did the time required to access them. Sequential files are linear so have a big O of O(n). The process was to load a record into memory, search it for the needed data, process it, and then load the next record into memory, and so on. The best case is to find the searched element on the first lookup and the worst case is to find the element on the last lookup, or not at all. The average would be in the middle. This doesn't sound bad unless you have millions of records to search through or very large sequential files. Since these files usually reside on disk, you are having to go through the IO process of the disk (or tape back in the day) so the processing time became quite significant. What was needed was a good way to look up the data in a manner that skipped most of the record on disk and could pull the needed information directly from the record on disk. They came up with indexes.

Indexes are sorted lists of the data in the record with the lookup item as a key and the location of that item on the disk. Since the list is sorted, you can do a binary search on the list. A binary search is O(log n) which is significantly faster than O(n). The difference is "In contrast to O(N) which takes an additional step for each data element, O(log N) means that the algorithm takes an additional step each time the data doubles." -Introduction to Big O Notation.

Most indexes are actually stored as tree structures and you just have to walk down the tree to the needed item if it exists. Trees are actually an implementation of a binary search in reverse so when you traverse a tree you are doing a binary search on the data. Indexes significantly improved data access and even today, every database creates indexes on the data for fast retrieval. If you have a lot of sequential files to go through, building indexes will significantly increase access time. However, there are many free open source databases that you can use via ODBC or dedicated libraries so there is no sense in reinventing the wheel nowadays. Using a local database is the way to go now if you need to process large data sets.

6
QB64 Discussion / Re: A Question on Sorting
« on: September 18, 2021, 08:03:49 pm »
For every sorting algorithm, there is a best-case and a worst-case. Generally, the average is a good rule of thumb to go by for general-purpose sorts. They all take a finite amount of time and what you use is largely dependant on the type and quantity of the data. You really need to fit the sort to the data for the best results. https://www.geeksforgeeks.org/time-complexities-of-all-sorting-algorithms/

7
Programs / Re: Graphic Font Code
« on: September 18, 2021, 07:46:04 pm »
Ah yes, I have done that before. You can store all kinds of interesting stuff in a Data statement.

8
Programs / Re: Graphic Font Code
« on: September 18, 2021, 04:50:39 pm »
I case it isn't obvious, you can use this code for tilesets, as well as a graphic font. I used the templates to create tile sheets and that way I could reference each tile based on the code I had defined in the program. It is a very simple way to package graphics for a game and very simple to use.

9
Programs / Re: Graphic Font Code
« on: September 18, 2021, 10:31:57 am »
When I originally created this code I made some templates for GIMP and Paint.Net to make my own graphics. Here are the templates in case you want to use them in your own projects. Both GIMP and Paint.Net are free.

10
Programs / Re: Playing Card Code
« on: September 17, 2021, 06:33:17 pm »
Ah, that makes sense. Thank you. I saw the best answer option so I used that.

11
Programs / Re: Playing Card Code
« on: September 17, 2021, 03:05:47 pm »
I couldn't figure out how to modify the first post. Here is the updated version with the placeholders. 

12
Programs / Re: Playing Card Code
« on: September 17, 2021, 01:42:48 pm »
Sorry, I just realized I forgot the placeholders in the code. I will update it.

13
Programs / Playing Card Code
« on: September 17, 2021, 01:32:33 pm »
 
pc.png

I converted my FreeBasic playing card code over to QB64. I think it works alright from my testing. Let me know if you have any problems. Still learning QB64.

14
Programs / Re: Graphic Font Code
« on: September 17, 2021, 01:25:12 pm »
It is a 32-bit png with transparency with white letters so it is hard to see in explorer. It looks fine to me. I used Paint.Net to convert from BMP to PNG. I don't need rotated text or anything like that. This is to substitute for the built-in ASCII characters. This is the format Dwarf Fortress uses. I wasn't aware of the black transparency for BMP when I did this or I probably would have used that. They have a tile repository on the DF wiki: https://dwarffortresswiki.org/Tileset_repository They have several different sizes but the standard is a 16x16 character file. I just saw the font command in the wiki. I need to look at that more.

15
Programs / Re: Graphic Font Code
« on: September 16, 2021, 10:42:26 pm »
Very cool.

Pages: [1] 2