+ 123
*DAILY CHALLENGE* : Given a positive number Write a code that calculates all 'quark-pairs' from 1 .. n!
NEW CHALLENGE HERE: https://www.sololearn.com/discuss/626739/?ref=app ---> WINNER IS YSRAELCON: https://code.sololearn.com/W9GYDCnBW7Bq/?ref=app TASK: A 'quark-pair' is an integer pair. First you have to convert a number x into binary and count the 1's. Now multiply the number of 1's with x and store the product. We call two numbers a 'quark-pair' if their products are equal! HAVE FUN !!!
176 Antworten
+ 24
WOW. YOU ALL DID A VERY GOOD JOB!!! CONGRATULATION TO YOU ALL AND THANKS FOR #COTD! I'M GLAD THAT YOU LIKE THE CHALLENGES. HOPE I'LL SEE YOU AGAIN IN THE NEXT CHALLENGE:
https://www.sololearn.com/discuss/626739/?ref=app
+ 28
me too, here my try: https://code.sololearn.com/W9GYDCnBW7Bq/?ref=app
testing time on phone with 1 up to:
5000 in a trice.
10000 in a blink.
20000 in a breath.
thanks to @Maz and @Garikai, which gave me an idea for my try. And @Vari93 that encourage me for save the place in my answer meanwhile I was resolving it ☺. And @Ready for notify me that could make it a bit faster. And @VcC for a improved version .👍
+ 25
python. lists all pairs up to given value.
can do up to about n=5000 before it starts to time out. fun challenge ☺
https://code.sololearn.com/c9HK4CazDwxT/?ref=app
+ 18
Here's my try
(Web version)
https://code.sololearn.com/W25d6BU6Eb38/?ref=app
I gave it my best shot ^^
+ 16
Here is mine. Optimized & using a reverse table for quicker results. No time limit for n=4000. See also my quark2 version working up to n=8000.
https://code.sololearn.com/c0OQHJSeKVuF/?ref=app
+ 12
Although not any such pairs info found on google, but tried the coding as told. see it. (CLEARLY INTERPRETABLE)...perhaps
https://code.sololearn.com/cSIvNjiFSF7P/?ref=app
+ 12
include <iostream.h>
using namespace std;
int solution ( int num) {
int i,count=0;
for (i=0;i < (sizeof (int)*8 -1);i++) {
if ( num<<i & 1 ) {
count++;
}
}
return num*count;
}
void main (){
int n,m;
cin>>n;
cin>>m;
if ( solution (n) == solution (m) ) {
cout <<" yes";
} else {
cout <<" no";
}
}
+ 10
Here we go. Skipped exception handling for concision
https://code.sololearn.com/cWxF5EOpiz2F/?ref=app
+ 10
My attempt:-
https://code.sololearn.com/cm9LlMid1703/?ref=app
+ 10
I knw this is late but....
https://code.sololearn.com/cF25UDxkFQkZ/?ref=app
+ 9
here is working code in c
online link of this program :
https://pastebin.com/tAd0Cuqc
#include<stdio.h>
int bin(int );
int bin(int n) //this fn returns product
{
int i=0,j,n1,t,arr[100],count=0;
t=n;
while(n!=0)
{
n1=n%2;
n=n/2;
arr[i++]=n1;
}
for(j=i-1;j>=0;j--)
{
if(arr[j]==1)
count=count+1;
}
return count*t;
}
int main()
{
int n,i,j,y,z;
printf("Enter value of n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
y=bin(i);
for(j=i+1;j<=n;j++)
{
z=bin(j);
if(y==z)
{
printf("Quarks pair: %d %d\n" ,i,j);
}
}
}
}
+ 9
I think SL challenges should be like this only and not the quizzes. 🤔🤔
+ 9
Will I ever reach a point to solve such challenges
+ 9
Here's my try:
https://code.sololearn.com/c2BTCUYiOX0Z/?ref=app
+ 9
https://code.sololearn.com/crBC39X9oXbj/?ref=app
+ 8
Here is my java code for finding Quark pairs.. Upvote if you like...
https://code.sololearn.com/cjoMsHtxhKYu/?ref=app
+ 8
Check out this code
https://code.sololearn.com/c1bWl176SKsA/?ref=app
+ 7
Here is mine. For some reason, I get time limit exceeded on very low numbers, like 33, but I have tested this on my computer, and it definitely runs fairly quickly, ran on 5000 in under a second, 10000 in just over a second, and 1000000 in about 6 or 7 seconds. The code playground is highly, highly inefficient lol. But this does work, and it checks for valid input.
https://code.sololearn.com/c942sw8xFP1X/?ref=app