Closed asl97 closed 10 months ago
Serializing is probably not the way to go, result of research and testing below.
Probably going to look into seeded random shuffle instead.
Highest Number in Card | 99 | 64 | 48 | 9 | 8 | 1 |
---|---|---|---|---|---|---|
Original | 50 | 50 | 50 | 25 | 25 | 25 |
Base64-Like | 28 | 28 | 28 | 14 | 14 | 14 |
Direct map from char | - | 25 | 25 | 25 | 25 | 25 |
Compact + Base64-Like* | 27 | 25 | 23 | 14 | 13 | 5 |
alphabet.indexOf
Bunch of code snipping used from testing
// Base on this stackoverflow answer from Rafael Lima
// Licensed CC BY-SA 4.0 (mentioned in share menu)
// https://stackoverflow.com/a/69549596/1986995
static alphabet = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
static to_radix = function(bigNum, radix=64) {
if(typeof bigNum != 'bigint')
bigNum = BigInt(bigNum);
radix = BigInt(Math.max(Math.min(radix, this.alphabet.length),0))
let result = '';
while (bigNum>0) {
let r = bigNum % radix;
result = this.alphabet[r] + result;
bigNum = bigNum / radix;
}
return result
}
// ------------------------------------------
to_card_id: (card)=>{
let data = '';
let numbers = [];
let max_number = 0n;
for (let row of card){
for (let number of row){
numbers.push(number);
if (number > max_number)
max_number = number;
}
}
let digits = Math.floor(Math.log10(max_number)) + 1;
for (let number of numbers){
data += number.toString().padStart(digits, '0');
}
return base_convert.to_radix(data);
},
compact: (card)=>{
let data = 0n;
let numbers = [];
let max_number = 0n;
for (let row of card){
for (let number of row){
number = BigInt(number);
numbers.push(number);
if (number > max_number)
max_number = number;
}
}
max_number += 1n
for (let number of numbers){
data = data * max_number + number;
}
return base_convert.to_radix(data)
},
Formatting with css and printing as page sucks, highly dependent on browser and device.
Looking into generating svg instead, hopefully system font for numbers behave more reasonable than symbols and we don't have to 'path' our own numbers
note to self, if a bingo card follows the 15 numbers per column, the numbers can be stored as an offset of 15s making each number taking 4 bits.
todo, look into if this would help reduce id length.
note to self, id 0001 is not equal to id 1
added some functions to generate barcode in svg 361f6f76ebcc9f7353bb2e706dc48f8243e9ac68
all is implemented by b8eeac07c858b972fe5bd7814ff281e602c776de
Individual printing, batch printing, with barcode for both. Loading from card ID and scanning of barcode using QuaggaJS
serialize card as binary number note:
2 digits 25 slot = 50 digits 3 digits 25 slot = 75 digits
turns out it's just dumb javascript float number issue, todo, figure out small representation