Welcome to קודגורו Sign in | Join | Faq

חידות

Started by CGX at 01-05-2006 13:46. Topic has 2 replies.

Print Search
Sort Posts:    
   01-05-2006, 13:46
CGX is not online. Last active: 5/13/2012 10:41:23 PM CGX

Top 10 Posts
Joined on 11-13-2005
Posts 252
כיצד ניתן לייעל את התוכנית?

התוכנית הבאה פותרת חידה.

int b,p,w;

int g(int d, int l)
{
 long long wa[ 6]={1<<1,1<<26,1<<3,1<<24,1<<9,1<<18};
 char sol[ 6]= {'e','w','s','n','d','u'};
 int ca[ 6]={0111111111,0444444444,0007007007,0700700700,0000000777,0777000000};

 do w=(w+2)%6; while (d--&1); if (++d) w^=1;
 do {p=p*wa[ w]%((1<<27)-1); if (p&(b|ca[ w])) return(0); b ^= p;} while (l--);
 return(sol[ w]);
}

void main()
{
 int s,i,d1,l=0x1298f; //b10010100110001111;
 long long d;
 char sol[17];

 for (s=1; s<3; s++)
  for (d=0; d<(long long)1<<34; d+=(long long)1<<(0<<1)) {
   for (b=p=s,d1=w=0,i=16; i>=0; i--)
    if (!(sol[ i]=g(d>>(i<<1)&3,l>>i&1))) break;
   if (i<0){for (i=17;i;) printf("%c",sol[--i]); putchar('\n');}
  }
}

ניתן לשפר אותה כך שתפתור את החידה הרבה יותר מהר.

כיצד ניתן לעשות זאת בשינוי מספר תווים מזערי?


   Report 
   04-21-2008, 6:59
yoav zilberman is not online. Last active: 3/17/2009 12:02:20 AM yoav zilberman

Top 10 Posts
Joined on 04-08-2008
Posts 53
Re: כיצד ניתן לייעל את התוכנית?
מישהוא יכול לתרגם לג'אווה אני לא מבין כלום....
   Report 
   04-22-2008, 12:34
CGX is not online. Last active: 5/13/2012 10:41:23 PM CGX

Top 10 Posts
Joined on 11-13-2005
Posts 252
Re: כיצד ניתן לייעל את התוכנית?

רצ"ב תרגום לג'אווה

public class Riddle {

static int b,p,w;

static char g(int d, int l)

{

int []wa = {1<<1,1<<26,1<<3,1<<24,1<<9,1<<18};

char[]sol= {'e','w','s','n','d','u'};

int []ca = {0111111111,0444444444,0007007007,0700700700,0000000777,0777000000};

do w=(w+2)%6; while ((d--&1)!=0); if (++d!=0) w^=1;

do {p=(int)(((long)(p)*wa[ w])%((1<<27)-1)); if ((p&(b|ca[ w]))!=0) return(0); b ^= p;} while (l--!=0);

return(sol[ w]);

}

public static void main(String[] args) {

int s,i,l=0x1298f; //b10010100110001111;

char[] sol=new char[17];

for (s=1; s<3; s++)

for (long d=0; d<(long)1<<34; d+=(long)1<<(0<<1)) {

b=s; p=s; w=0;

for (i=16; i>=0; --i)

if (0==(sol[ i]=g((int)((d>>(i<<1))&3),(l>>i)&1))) break;

if (i<0){for (i=17;i!=0;) System.out.print(sol[--i]); System.out.println();}

}

}

}


   Report 
קודגורו » פורומים » חידות » כיצד ניתן לייעל את התוכנית?

Powered by Community Server, by Telligent Systems