Three travelers need to cross a river. Each traveler has a certain amount of gold coins kept in his bag.
Traveler A has 1000 gold coins
Traveler B has 700 gold coins
Traveler C has 300 gold coins
')
It can be seen that there is a boat on the boat. If you are a traveler, then you’ll run away from there. It is a rule that it applies to travelers.
What strategy will ensure that?
You are in a rowing boat on a lake. A large heavy rock is also in the boat. You heave the rock overboard. It sinks to the bottom of the lake. What happens to the water level in the lake? Does it rise, fall or stay the same?
Write a method to check if there is a number of multiple of 3.
A copy of it is a program. A quine takes no input. File of the program. Quines are named after the American mathematician and logician Willard Van Orman Quine (1908–2000).
It can be slowed down.
/* The obvious approach to find minimum (involves branching) */ int min(int x, int y) { return (x < y) ? x : y }
Write a program to find out the minimum of two integers without branching.
/* The obvious approach to find minimum (involves branching) */ int min(int x, int y) { return (x < y) ? x : y }
0. (1000) (700) (300) ABC ---- 1. (1000) (300) AC ---- (700) B 2. (1000) (300) ABC ---- (700) 3. (1000) BC ---- (700) (300) A 4. (1000) ABC ---- (700) (300) 5. (1000) A ---- (700) (300) BC 6. (1000) (300) AC ---- (700) B 7. (300) C ---- (700) (1000) AB 8. (700) (300) BC ---- (1000) A 9. (700) (300) ---- (1000) ABC 10. (700) (300) A ---- (1000) BC 11. (700) ---- (300) (1000) ABC 12. (700) B ---- (300) (1000) AC 13. ---- (300) (1000) (700) ABC
// CPP program to check if n is a multiple of 3 #include<bits/stdc++.h> using namespace std; /* Function to check if n is a multiple of 3*/ int isMultipleOf3(int n) { int odd_count = 0; int even_count = 0; /* Make no positive if +n is multiple of 3 then is -n. We are doing this to avoid stack overflow in recursion*/ if(n < 0) n = -n; if(n == 0) return 1; if(n == 1) return 0; while(n) { /* If odd bit is set then increment odd counter */ if(n & 1) odd_count++; n = n>>1; /* If even bit is set then increment even counter */ if(n & 1) even_count++; n = n>>1; } return isMultipleOf3(abs(odd_count - even_count)); } /* Program to test function isMultipleOf3 */ int main() { int num = 24; if (isMultipleOf3(num)) printf("%d is multiple of 3", num); else printf("%d is not a multiple of 3", num); return 0; }
main(a){printf(a="main(a){printf(a=%c%s%c,34,a,34);}",34,a,34);}
y ^ ((x ^ y) & -(x < y))
Source: https://habr.com/ru/post/349268/
All Articles