[Solved] Convert any file to binary string and from binary to file [closed]

Finally, I discovered that the problem was in the code. Just small mistake using substr func. So, the correct code is: $buffer = file_get_contents(“image.png”); $length = filesize(“image.png”); if (!$buffer || !$length) { die(“Reading error\n”); } $_buffer=””; for ($i = 0; $i < $length; $i++) { $_buffer .= sprintf(“%08b”, ord($buffer[$i])); } echo $_buffer.”<br>”; $nb = “”; … Read more

[Solved] D-lang being faster than C++? [closed]

find() seems to be heavily used and they are very different in D and C++ implementations: int find(int x) { return ds[x] = (x == ds[x] ? x: find(ds[x])); } vs: long long find(long long node) { if(parents[node] == node)return node; else return find(parents[node]); } find() in D modifies array (looks like some kind of … Read more

[Solved] Need help understanding some parts of “15 Puzzle Game” in C++ [closed]

A. The board is being shuffled, so 1000 means ‘a lot, but not that much that you really have to start waiting for the board being shuffled’ B. getCandidates() returns the candidates by filling them in the vector, v.clear() resets the vector for new candidates. C. Here 1,2,4,8 just means up,down,left,right (not in particular order). … Read more

[Solved] Finding the n-th prime number that is palindrome in base K

Solution: change palindrome to int palindrome ( int n,int base) { int isTrue = 1; int digitCount = digitCountBase(n,base); int power = intPow(base,digitCount-1); int original = n; while (n>0&& digitCount >0) { if (n%base != (original/power) % base &&digitCount!=1) { isTrue =0; return 0; } n=n/base; power = power /base; digitCount=digitCount-2; } return isTrue; } … Read more

[Solved] Counting the number of unival subtrees in a binary tree [closed]

int countUniVals(node* head, bool* unival) { if (!node) { *unival = true; return 0; } bool uniL,uniR; int sum = countUniVals(head->l, &uniL) + countUniVals(head->r, &uniR); if (uniL && uniR && (!head->l || head->l->val == head->val) && (!head->r || head->r->val == head->val)) { sum++; *unival = true; } return sum; } 0 solved Counting the number … Read more

[Solved] Moving chars in String while ignore Numbers

You can try swaping first and last char value like below. =========================================== String s = “asd321tre2”; char[] charr = s.toCharArray(); int end = 0; for (int i = s.length(); i <= 0; i–) { if (Character.isLetter(charr[i])) { end = i; } } String output = charReplace(end, charr); } private static String charReplace(int end, char[] ch) … Read more