Advanced cow farm
Description:
History
Farmer-programmer John, who has not worked in his specialty for a long time, faced the problem
that there are too many cows on his farm and it became almost impossible to distinguish them.
So a plan matured in his head - to write a program that will encode information into a unique image for each cow on his farm
which will store all the necessary information.
John had been thinking over the generation algorithm for days, and after he finished, he realized that he had forgotten how to write code...
Task
Write a function that will generate an image based on data object and return it in base64 format.
Cow information format
{
/**
* Cow id — a string of small and large
* latin letters and numbers, strictly 10 characters
*/
id: 'string';
/**
* Flag with information about whether a cow is purchased or not(true || false)
*/
isPurchased: 'boolean';
/**
* Cow name — a string of small and large
* latin letters and spaces (from 0 to 10 characters)
*/
name: 'string';
/**
* Cow's birthday - date in YYYY-MM-DD HH:MM format(ex. 2019-06-11 10:10)
*/
dateOfBirth: 'string';
}
Image
Image has a fixed size — 156 by 164 pixels. There is a 10px wide white border around the perimeter of the barcode. Inside the frames is the barcode content, consisting of 18 lines of 17 black or white squares per line. The size of each square is 8 by 8 pixels. White squares in the content encode 0, black squares encode 1.
Algorithm
At the intersection of the first row and the first column of content, a square is drawn encoding information about whether it is a purchased cow or not. The value false is encoded by zero (white color), true - by one (black color).
Next, a string of the form <id><name><dateOfBirth> is formed from the fields - id, name, dateOfBirth. The name field is padded with spaces at the end of up to 10 characters.
The resulting string is converted into a byte array — each character of the string is assigned a corresponding ASCII code (a number from 0 to 255).
Then each element of the resulting array is translated into binary notation (eight characters 0 or 1) and encoded with a sequence of eight squares (0 is a white square, 1 is a black square). Squares are drawn in the barcode content sequentially and line by line.
The last line of the content contains the benchmark information
Algorithm of calculating benchmark information
Each square in the benchmark information row determines the parity of the sum of the content values in the corresponding column. If the sum of zeros and ones in the column is even, then a white square is drawn in the control information, otherwise — black.
Example
For this object:
{
id: '3h13A8dH39';
isPurchased: true;
name: 'Candle-Fly';
dateOfBirth: '2019-06-11 13:23';
}
the result will be:
Similar Kata:
Stats:
Created | Oct 10, 2022 |
Published | Oct 11, 2022 |
Warriors Trained | 21 |
Total Skips | 0 |
Total Code Submissions | 48 |
Total Times Completed | 8 |
JavaScript Completions | 8 |
Total Stars | 4 |
% of votes with a positive feedback rating | 50% of 3 |
Total "Very Satisfied" Votes | 1 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 3 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |