mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Puzzles

Reply
 
Thread Tools
Old 2012-03-23, 19:04   #100
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
doh I seem to be working on a N sided die not a 6 sided one. just shows the importance or THOROUGHLY reading instructions:

Code:
(e)->j=0;k=1;a=vector(3,b,vecsort(vector(6,b,d=0;until(d>0,d=random(e+1));d),,4));for(f=1,3,for(g=if(f==1,2,if(f==2,3,if(f==3,1))),if(f==1,2,if(f==2,3,if(f==3,1))),if(a[f]==a[g],next(2));for(h=1,6,for(i=k,6,if(a[f][h]<a[g][i],k=k+1,j=j+k*(e-h)))));if((j/(e^2))>.5,,return(0));j=0;k=1);return(1)
a few changes and a few number changes changing to 6. I'm currently using a second code to check this a bit I just have to figure out how to figure out uniqueness or test an amount that will give the correct answers.
I was just going to eliminate a whole lot of possibilities other than a[f]==a[g], by changing it to vecsort(a[f],,4)==vecsort(a[g],,4) but at times I get a forbidden followed by a unknown type 48 warning. opened a new pari instead and it works fine so far.

Last fiddled with by science_man_88 on 2012-03-23 at 19:18
science_man_88 is offline   Reply With Quote
Old 2012-03-24, 18:45   #101
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I was just going to eliminate a whole lot of possibilities other than a[f]==a[g], by changing it to vecsort(a[f],,4)==vecsort(a[g],,4) but at times I get a forbidden followed by a unknown type 48 warning. opened a new pari instead and it works fine so far.
I'm guessing I'm the one holding this up now if only I could get my code to work as intended I am trying to use an if to eliminate a lot of of them from needing to check much else at all beforehand:


1)if sorted version of vectors are equal
2)if first sorted vector's first value is less than any value after second sorted vector's 3rd element

are the main things I was trying to implement:

Code:
(e)->j=0;
k=1;
a=vector(3,b,vecsort(vector(6,b,d=0;until(d>0,d=random(e+1));d),,4));
for(f=1,3,
    for(g=
        if(f==1,2,
           if(f==2,3,
              if(f==3,1
                )
             )
          ),
       if(f==1,2,
          if(f==2,3,
             if(f==3,1
               )
            )
         ),
       if(vecsort(a[f],,4)==vecsort(a[g],,4) 
       || vecsort(a[f],,4)[1]<vecsort(a[g],,4)[6]
       || vecsort(a[f],,4)[1]<vecsort(a[g],,4)[5]
       || vecsort(a[f],,4)[1]<vecsort(a[g],,4)[4]
       || vecsort(a[f],,4)[1]<vecsort(a[g],,4[3]
       ,next(2)
         )
       );
       for(h=1,6,
            for(i=k,6,
                 if(a[f][h]<a[g][i],
                   k=k+1,
                   j=j+k*(e-h)
                   )
                )
           );
           if((j/(e^2))>.5,
              ,
             return(0)
              );
              j=0;
              k=1
             );
            return(1)
I think I may have found the error(s) in the process of putting it like this I just find it hard to make it that way in PARI.

Last fiddled with by science_man_88 on 2012-03-24 at 18:45
science_man_88 is offline   Reply With Quote
Old 2012-03-24, 21:01   #102
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I'm guessing I'm the one holding this up now if only I could get my code to work as intended I am trying to use an if to eliminate a lot of of them from needing to check much else at all beforehand:


1)if sorted version of vectors are equal
2)if first sorted vector's first value is less than any value after second sorted vector's 3rd element

are the main things I was trying to implement:

Code:
(e)->j=0;
k=1;
a=vector(3,b,vecsort(vector(6,b,d=0;until(d>0,d=random(e+1));d),,4));
for(f=1,3,
    for(g=
        if(f==1,2,
           if(f==2,3,
              if(f==3,1
                )
             )
          ),
       if(f==1,2,
          if(f==2,3,
             if(f==3,1
               )
            )
         ),
       if(vecsort(a[f],,4)==vecsort(a[g],,4) 
       || vecsort(a[f],,4)[1]<vecsort(a[g],,4)[6]
       || vecsort(a[f],,4)[1]<vecsort(a[g],,4)[5]
       || vecsort(a[f],,4)[1]<vecsort(a[g],,4)[4]
       || vecsort(a[f],,4)[1]<vecsort(a[g],,4[3]
       ,next(2)
         )
       );
       for(h=1,6,
            for(i=k,6,
                 if(a[f][h]<a[g][i],
                   k=k+1,
                   j=j+k*(e-h)
                   )
                )
           );
           if((j/(e^2))>.5,
              ,
             return(0)
              );
              j=0;
              k=1
             );
            return(1)
I think I may have found the error(s) in the process of putting it like this I just find it hard to make it that way in PARI.
yet another simple thing only check for the third entry if the third isn't neither will the others.
science_man_88 is offline   Reply With Quote
Old 2012-03-24, 22:50   #103
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
yet another simple thing only check for the third entry if the third isn't neither will the others.
sorry worded wrong basically unless you prove the third element is greater you have no guarantee of half.
science_man_88 is offline   Reply With Quote
Old 2012-03-25, 01:48   #104
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by lavalamp View Post
Based on actual runtime, my code for N=30 would run in a comparatively brief tens of millions of years.
what are you down to now ? if I did everything properly ( addmitedly I haven't found a way to do: "The sets of dice {A,B,C}, {B,C,A} and {C,A,B} are the same set." or a way to make sure they are all unique but even testing what I believe could be N^18 possibilities ( admittedly likely a lot less) I think I'm down to just over 2300 years. oh never mind that was my N=7 result.

Last fiddled with by science_man_88 on 2012-03-25 at 01:57
science_man_88 is offline   Reply With Quote
Old 2012-03-25, 11:57   #105
lavalamp
 
lavalamp's Avatar
 
Oct 2007
Manchester, UK

23·59 Posts
Default

Here is a fairly ginormous hint:

Perhaps you should look at how you could generate all combinations of two digits, remember that for a combination, the order they are in doesn't matter. eg. 19 OR 91, but not both, they are counted as the same combination, "a 1 and a 9".

If you count all the valid combinations, how many are there? [url=http://en.wikipedia.org/wiki/Triangular_number]Hint[/url].

How about combinations of 3 digits, how many combinations are there now? [url=http://en.wikipedia.org/wiki/Tetrahedral_numbers]Hint[/url].

Try this with various ranges of numbers, 1 to 2, 1 to 3 etc.

Now generalise it to 6 "digits" (or "sides of a die" in our case), and use 1 to 30 as your single digit range (if you can allow yourself to think of 30 as a single digit, just pretend you're working in base 31 or higher). Now you can generate all combinations of a die without repeats and in numerical order.


If you don't get the trick right away, that's fine, but think about it for a couple of days. If you can't initially write down code to generate 2 or 3 digit combos, just work them out on pen and paper until you see a pattern, if you restrict yourself to a digit range of 1 to 4 or similar, there aren't that many.

If you get stuck at some point and have questions, then as a general rule don't immediately post them. Wait a while and you might discover the answers yourself. Similarly if you work something out, don't post it immediately, work out as much as you can then post everything together at the end, it's much easier to read that way.
lavalamp is offline   Reply With Quote
Old 2012-03-25, 12:24   #106
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by lavalamp View Post
Here is a fairly ginormous hint:

Perhaps you should look at how you could generate all combinations of two digits, remember that for a combination, the order they are in doesn't matter. eg. 19 OR 91, but not both, they are counted as the same combination, "a 1 and a 9".

If you count all the valid combinations, how many are there? [url=http://en.wikipedia.org/wiki/Triangular_number]Hint[/url].

How about combinations of 3 digits, how many combinations are there now? [url=http://en.wikipedia.org/wiki/Tetrahedral_numbers]Hint[/url].

Try this with various ranges of numbers, 1 to 2, 1 to 3 etc.

Now generalise it to 6 "digits" (or "sides of a die" in our case), and use 1 to 30 as your single digit range (if you can allow yourself to think of 30 as a single digit, just pretend you're working in base 31 or higher). Now you can generate all combinations of a die without repeats and in numerical order.


If you don't get the trick right away, that's fine, but think about it for a couple of days. If you can't initially write down code to generate 2 or 3 digit combos, just work them out on pen and paper until you see a pattern, if you restrict yourself to a digit range of 1 to 4 or similar, there aren't that many.

If you get stuck at some point and have questions, then as a general rule don't immediately post them. Wait a while and you might discover the answers yourself. Similarly if you work something out, don't post it immediately, work out as much as you can then post everything together at the end, it's much easier to read that way.
if you're working with n single digit possibilities it's n^ length for possible combinations , I already implemented vecsort (vector,,4) which sorts them if they have the same amount of things but in a different order I've already put it to return 0 now. so that destroys that in fact I was able to do a single N=9999^9999 last night in about 16 ms . 7^3 in less than 2 seconds as my timing was almost linear going for 7^4 took a little over 7 times the time but 7^18 = 7^18-3 times as many so it will take 7^15 times as long. maybe I should stop 377 is up I believe.
Code:
Euler376(e)=j=0;k=0;a=vector(3,b,vecsort(vector(6,b,d=0;until(d>0,d=random(e+1));d),,4));for(f=1,3,for(g=if(f==1,2,if(f==2,3,if(f==3,1))),if(f==1,2,if(f==2,3,if(f==3,1))),if(vecsort(a[f],,4)==vecsort(a[g],,4),return(0),if(vecsort(a[f],,4)[1]<vecsort(a[g],,4)[3],j=18));for(h=1,6,for(i=if(j==18,4,1),6,if(a[f][h]<a[g][i],k=k+1;if((k+j)>18,return(1)),j=j+k*(e-h))));if(j<=18,,return(0)));j=0;k=0);return(1)

Last fiddled with by science_man_88 on 2012-03-25 at 12:26
science_man_88 is offline   Reply With Quote
Old 2012-03-25, 14:51   #107
lavalamp
 
lavalamp's Avatar
 
Oct 2007
Manchester, UK

25158 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
if you're working with n single digit possibilities it's n^ length for possible combinations
No, it is not. There are n^length PERMUTATIONS, which is not what is required here.
lavalamp is offline   Reply With Quote
Old 2012-03-25, 14:57   #108
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by lavalamp View Post
No, it is not. There are n^length PERMUTATIONS, which is not what is required here.
yeah I'm looking at 377 for now I'll get back 376 some time. I've already got a script for what they seem to mean already except I've never heard digital sum used that way ( or at least not for just those types of numbers).
science_man_88 is offline   Reply With Quote
Old 2012-03-25, 18:48   #109
voidme
 
Feb 2012

67 Posts
Default

377 is hilarious

there is an OEIS sequence but it's incorrect
voidme is offline   Reply With Quote
Old 2012-03-25, 20:59   #110
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
yeah I'm looking at 377 for now I'll get back 376 some time. I've already got a script for what they seem to mean already except I've never heard digital sum used that way ( or at least not for just those types of numbers).
well because I have 2 versions of PARI I have 2 different things ( though the second is in partial due to CRG, because it's an alteration of a code he gave to me for a different purpose) first one:

Code:
(n)->d=0;forstep(x=n,(10^n-1)/9,9,if(vecsort(eval(Vec(Str(x))),,8)[1]==0,next(1),if(sum(X=1,#vecsort(eval(Vec(Str(x))),,4),vecsort(eval(Vec(Str(x))),,4)[X])==n,d=d+x)));d
the second one:

Code:
(n)->b=0;a=Vec(select(v->vecmin(v)>0,partitions(n)));for(x=1,#a-1,b=b+((10^#a[x]-1)/9)*n);for(v=1,#a[#a],b=b+a[#a][v]*10^(#a[#a]-v));b
neither is completely work for the problem as they run out of memory.
science_man_88 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Project Euler jhs Puzzles 32 2021-01-19 04:05
Project Euler 486 lavalamp Puzzles 8 2015-02-04 14:28
Euler (6,2,5) details. Death Math 10 2011-08-03 13:49
Project Euler Mini-Geek Lounge 2 2009-10-23 17:19
Bernoulli and Euler numbers (Sam Wagstaff project) fivemack Factoring 4 2008-02-24 00:39

All times are UTC. The time now is 05:21.


Fri Aug 6 05:21:05 UTC 2021 up 13 days, 23:50, 1 user, load averages: 2.61, 2.37, 2.37

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.