Wikipedia:Reference desk/Archives/Computing/2021 February 16

From Wikipedia, the free encyclopedia
Computing desk
< February 15 << Jan | February | Mar >> February 17 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


February 16[edit]

C++[edit]

I wrote the following code in order to conform to the requirement. Although the code appears to have met the requirement, I feel it inefficient because I don't expect to write a lot of case when the array size grows to 100 or more, i.e. storage[100]. So I would like to ask if any Wikipedian knows about the more efficient way to approach such requirement? Thanks a lot! :D Stringent Checker (talk) 14:49, 16 February 2021 (UTC)[reply]

/*
 Write a program that searches an array of ten integers for duplicate values. 
 Have the program display each duplicate found.
*/

#include <iostream>
#include <cstring>
using namespace std;

int main() {

	int input;

	int storage[10];

	cout << "Insert 10 integers and the program will check if there are duplicate integers in the array. \n";

	for (int i = 0; i < 10; i++)
	{
		switch (i) {
		
		case 0:
			cout << "Now, insert the first number.\n";
			cin >> input;
			storage[0] = input;
			break;
		case 1:
			cout << "Now, insert the No." << i + 1 << " number.\n" ;
			cin >> input;
			storage[1] = input;
			break;
		case 2:
			cout << "Now insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[i] = input;
			break;
		case 3: 
			cout << "Now, insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[i] = input;
			break;
		case 4:
			cout << "Now, insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[i] = input;
			break;
		case 5:
			cout << "Now, insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[i] = input;
			break;
		case 6: 
			cout << "Now, insert the No." << i + 1 << " number.\n";
			cin >> input; 
			storage[i] = input; 
			break;
		case 7:
			cout << "Now, insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[i] = input;
			break;
		case 8: 
			cout << "Now, insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[i] = input;
			break;
		case 9:
			cout << "Now, insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[i] = input;
			break;		
		}

	}

	for (int i = 0; i < 10; i++)
	{
		for (int j = 10 - 1; j >= 0; j--) {

			if (j == i) continue;

			if (storage[i] == storage[j] && i < j) cout << "Duplicate found: " << storage[i] << "\n";
		}
	}

	cout << "The 10 numbers you inserted: ";
	for (int i = 0; i < 10; i++)
	{
		cout << storage[i];
	}

	return 0;

}
The simplest improvement would be to replace the whole switch statement with a simple if statement that asks if (i > 0) do your current case 2 ( ask for number i+1 and store it as storage[i] ) else do your current case 0 — GhostInTheMachine talk to me 16:53, 16 February 2021 (UTC)[reply]
Another option would be to keep the switch and maybe have case 1: say cout << "Now, insert the second number.\n" ;, then replace all cases from 2 to the end with a single defaultGhostInTheMachine talk to me 16:53, 16 February 2021 (UTC)[reply]
Thank you for enlightening me!--Stringent Checker (talk) 17:10, 18 February 2021 (UTC)[reply]
Note that the assignment does not ask for coding the process of interactively inputting the numbers, and also not for displaying all values afterwards. My general advice is not to code more than explicitly required – except perhaps for such things as input validation or catching exceptions. As to the core of the code, if you let index j run up instead of down, starting from j = i+1, you can omit the two tests j == i (always false) and i < j (always true); moreover, you more than halve the number of comparisons storage[i] == storage[j]. Note that if all 10 numbers are the same, the code will produce 45 lines of found duplicates.  --Lambiam 18:27, 16 February 2021 (UTC)[reply]
Thank you for your enlightment! --Stringent Checker (talk) 17:10, 18 February 2021 (UTC)[reply]

The code after the community's nurture[edit]

The code now looks like this, seems to be more clear and concise. As to My general advice is not to code more than explicitly required – except perhaps for such things as input validation or catching exceptions. I have taken notes about this and will mind this insightful point going forwards. Any further advice is greatly appreciated! Thanks for the community's generosity in upbringing the next generation. I will keep this Wikipedian culture! Stringent Checker (talk) 17:37, 18 February 2021 (UTC)[reply]

You could delete case 1 and the four following lines, since they are identical to the default case. CodeTalker (talk) 17:09, 19 February 2021 (UTC)[reply]
Thanks for being in my corner!! ^__^ Stringent Checker (talk) 06:56, 20 February 2021 (UTC)[reply]
/*
 Write a program that searches an array of ten integers for duplicate values.
 Have the program display each duplicate found.
*/

#include <iostream>
#include <cstring>
using namespace std;

int main() {

	int input;

	int storage[20];

	cout << "Insert 20 integers and the program will check if there are duplicate integers in the array. \n";

	for (int i = 0; i < 20; i++)
	{
		switch (i) {

		case 0:
			cout << "Now, insert the first number.\n";
			cin >> input;
			storage[0] = input;
			break;
		case 1:
			cout << "Now, insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[1] = input;
			break;
		default:
			cout << "Now insert the No." << i + 1 << " number.\n";
			cin >> input;
			storage[i] = input;
		}

	}

	cout << "Duplicate found: ";

	for (int i = 0; i < 20; i++)
	{
		for (int j = i + 1; j < 20; j++) {

			if (storage[i] == storage[j] ) cout << storage[i];
		}
	}

	cout << "\n" << "The 20 numbers you inserted: ";
	for (int i = 0; i < 20; i++)
	{
		cout << storage[i];
	}

	return 0;

}

Data recovery service for Nosql databases.[edit]

There are a lot of data recovery services for things like damaged hard drives or tape or flash storage.
But in my case, I got a software fault in my RocksDB database which corrupted data or it’s masked crc32 checsum on a single key (less than 1 Mb) thereby preventing the built in Snappy compression (managed by Rocksdb libraries) from decompressing.

While the data is public and available through many third party services for free, it’s access as a database is not, and rebulding it using OpenEthereum (full archival node) is a year long operation (using the current cpu providing the best per thread performance because otherwise it can be way longer) because of single thread performance constraints (OpenEthereum suffer from synchronisation issues which limits the overall number of threads which can work at the same time and the required work around increasing io worker threads parallelism was never attempted so far). This also mean that I’m not interested in extracting the damaged data, but instead really need the database to no longer crash OpenEthereum.
Of course, from the around 2000 OpenEtherem full archival node in the world, I did not find a company willing to share a backup for fixing the broken part of my database or I didn’t received an answer.

This also means that it should be possible to delete all the blocs which where added at the end after the broken block (since data are stored in block based sst) along their matching data inside the 6 other columns. This can be done using the DeleteRange function provided by RocksDB, but requires a deep understanding of the binary format used for key numbers. So a data recovery service with knowlwedgde about database repair is enough and there’s no need of Rocksdb specification though it might be a safer to replace the damaged key manually as attempting to rebuild the file through OpenEthereum might results in a 64Mb sst file not containing the same number of blocks as the original one. 2A01:CB05:8FEA:C600:D2E9:BABF:3376:10BD (talk) 19:14, 16 February 2021 (UTC)[reply]

I know it might be off topic to ask that here but I’ve really no idea about where to ask for a recovery company which might help me in that kind of case.

I ended up having to do something like that by hand a while back. There just weren't any decent tools. That wasn't for RocksDB but basically I ended up writing python scripts that scanned the db files for stuff that looked like application data, and that was able to get back most of what was needed. It is really weird that it's so hard to rebuild the archive: isn't the whole point of a blockchain supposed to be that you can check every transaction without being part of a special elite? If the thread synchronization issues are a software problem, maybe they are fixable. At least a few years ago, the whole Bitcoin blockchain filled a few hundred GB of disk space, so with good connectivity you could download it without too much hassle. Data recovery services are usually quite expensive so you probably don't want to pay for one. 2601:648:8200:970:0:0:0:C942 (talk) 22:32, 18 February 2021 (UTC)[reply]
In the case of Ethereum, checking past transactions automatically applies to transactions, but not states which Bitcoin doesn t have. The uncompressed database is currently 15Tb large growing 10% every months requiring cuting edge single level cell nvme ssd in terms of random 4K write performance and durabiliy (I didn t mentionned it also requires writing a little less than 120Pb to disk as each added block is treated as the latest one). As I said, I don t care about extracting the data but only about bringing back the database online. I saw multiple sql database recovery services but which don t do Nosql.
Increasing the exisiting parallelism neverless would be a very human ressource intensive task. So much that the company maintaining the software divested from it. So while it wasn t attempted yet, it s neverless unlikely to be ever done. And some recent maintnance commit removed some parallelization parts.
Just Google for full Ethereum archival node. While they are several type of software for running such kind of nodes, in my case, I need to check the result of transactions on past states in the mempool before they are mined in order to know if frontrunning a specific trade worth it. A feature called Parity trace, now part of OpenEthereum. 2A01:CB05:8FEA:C600:2198:8EE0:850E:2251 (talk) 11:37, 19 February 2021 (UTC)[reply]

The corrupt sst file is here. 2A01:CB05:8FEA:C600:D5DB:E26D:D19B:C6C3 (talk) 15:19, 21 February 2021 (UTC)[reply]

Outlook is bleak[edit]

I have a Hotmail account, but decided to create an Outlook one. However, whenever I try to log into Outlook, it automatically opens my Hotmail account. How can I access my new email account? Clarityfiend (talk) 20:25, 16 February 2021 (UTC)[reply]

If you log into Outlook using your *****@outlook.com address and send an email, does the message identify your *****@hotmail.com address as the sender's?  --Lambiam 05:35, 17 February 2021 (UTC)[reply]
The problem is that it won't let me log in with my Outlook account. In any case, I found a solution: I used a different browser. Clarityfiend (talk) 04:20, 22 February 2021 (UTC)[reply]
Resolved