The Project Euler thread

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • axith
    FFR Veteran
    FFR Simfile Author
    • Dec 2007
    • 1251

    #226
    Re: The Project Euler thread

    for all it's worth, here's my friend key: 83532459359302_e704d4c6b1d37a7739410f38da156b2a

    Comment

    • axith
      FFR Veteran
      FFR Simfile Author
      • Dec 2007
      • 1251

      #227
      Re: The Project Euler thread

      So which keywords make python read from a text file? My eyes are buggy from looking though online reference stuff and there's several problems that require it..

      Comment

      • emerald000
        the Mathemagician~
        • Nov 2005
        • 1320

        #228
        Re: The Project Euler thread

        You will want to use:

        Code:
        file = open('/path/to/file')
        
        file.read()       # Returns whole file.
        file.readline()   # Will return line by line.
        file.readlines()  # Returns a list of every line.
        
        file.close()      # Close the file after you have read everything you need.

        Comment

        • kaiten123
          FFR Player
          • May 2008
          • 1117

          #229
          Re: The Project Euler thread

          just did 96 which was cool since i never really used recursion in a way that was non-trivial before
          no idea how you guys do some of the higher numbered ones, highest one i did was 243, which for some reason is many times easier than everything around it, didnt even write any code.

          edit: got to lvl 3 :)
          Last edited by kaiten123; 12-23-2012, 12:49 AM. Reason: lvl up

          Comment

          • kaiten123
            FFR Player
            • May 2008
            • 1117

            #230
            Re: The Project Euler thread

            brute forced 407 lol
            never saw that box at the bottom right before, is that new? or does it pop up when you solve something recent?

            Comment

            • leonid
              I am leonid
              FFR Simfile Author
              FFR Music Producer
              • Oct 2008
              • 8080

              #231
              Re: The Project Euler thread

              i should get back to solve rest of the problems



              Proud member of Team No

              Comment

              • Arkuski
                FFR Veteran
                • Jul 2006
                • 1118

                #232
                Re: The Project Euler thread

                This is pretty awesome I'm giving some of these a go

                Originally posted by Wayward Vagabond
                i can appreciate a good looking woman when i see one and this one just happened to be my mom

                Comment

                • Reincarnate
                  x'); DROP TABLE FFR;--
                  • Nov 2010
                  • 6332

                  #233
                  Re: The Project Euler thread

                  411 wasn't too bad -- pretty much an exercise in programming

                  Comment

                  • Reincarnate
                    x'); DROP TABLE FFR;--
                    • Nov 2010
                    • 6332

                    #234
                    Re: The Project Euler thread

                    415... only 3 solvers after 7 and a half hours.

                    Yeah I can pretty much kiss my 100% goodbye

                    It's been fun, PE :(

                    Comment

                    • MracY
                      FFR Veteran
                      • Oct 2007
                      • 284

                      #235
                      Re: The Project Euler thread

                      Originally posted by Reincarnate
                      2 mod 3 is 2

                      (x mod y is the remainder of x / y)

                      PS use Python instead, it's cooler



                      sumTotal = 0
                      num = 1
                      while num < 1000:
                      if (num % 3 == 0) or (num % 5 == 0):
                      sumTotal = sumTotal + num
                      num = num + 1
                      print sumTotal


                      Damn thing doesn't save formatting but w/e
                      Just as a note to people who want to join Project Euler: this solution is not necessarily representative of what you will be doing.

                      Here are some of my crude notes for problem 1, that used logic in stead of programming:





                      vertical axis is m
                      horizontal axis is n


                      Sum of the series of 5 is 0.5nm+0.5m
                      Sum of the series of 3 is 0.5pq+0.5q

                      1000/5 = 200.
                      The last value here is 1000, so n = 199
                      m = 1000-5 = 995

                      1000/3 = 333 with 1 remainder, so p = 333
                      q = 1000-1 = 999

                      Sum5 = 0.5*199*995+0.5*995
                      = 99500

                      Sum3 = 0.5*333*999+0.5*999
                      = 167166

                      99500+166833=266333



                      There is overlap between the sums of multiples of 15.
                      1000/15 is 66 with 10 remainder, so x = 66
                      y = 1000-10 = 990

                      Sum of this series is 0.5xy+0.5y
                      = 0.5*66*990+0.5*990 = 33165

                      So the answer is: 99500+166833-33165 = 233168

                      Comment

                      • leonid
                        I am leonid
                        FFR Simfile Author
                        FFR Music Producer
                        • Oct 2008
                        • 8080

                        #236
                        Re: The Project Euler thread

                        @Reincarnate use code tag

                        Code:
                        while 1:
                          print "INDENT"
                          if "INDENT":
                            print "MORE INDENT"
                        print "NEVER REACHES HERE"



                        Proud member of Team No

                        Comment

                        • benguino
                          Kawaii Desu Ne?
                          • Dec 2007
                          • 4185

                          #237
                          Re: The Project Euler thread

                          Maybe ill try to play around and do some more problems this weekend :) (I haven't touched PE in awhile) . gotta start on my take-home test and other school stuff first though xP
                          AMA: http://ask.fm/benguino

                          Not happening now! Don't click to join!



                          Originally posted by Spenner
                          (^)> peck peck says the heels
                          Originally posted by Xx{Midnight}xX
                          And god made ben, and realized he was doomed to miss. And said it was good.
                          Originally posted by Zakvvv666
                          awww :< crushing my dreams; was looking foward to you attempting to shoot yourself point blank and missing

                          Comment

                          • benguino
                            Kawaii Desu Ne?
                            • Dec 2007
                            • 4185

                            #238
                            Re: The Project Euler thread

                            Started doing this in my free time again :3 Just got problem 34 this morning. Problem and code below; any tips that can make me a better programmer or mathematician is greatly appreciated :P

                            problem:

                            145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

                            Find the sum of all numbers which are equal to the sum of the factorial of their digits.

                            Note: as 1! = 1 and 2! = 2 are not sums they are not included.


                            solution: (in Java)

                            Code:
                            //this will be our final answer
                            		int probSum = 0;
                            		
                            		//at some point, the sum of the factorials of the digits won't be large enough to add up to the number
                            		//so choose our digits to be 9 and find when we have too many digits
                            		//our upper bound for curious numbers becomes k
                            		int i = 1;
                            		int nFact = factorial(9);
                            		int k = 9;
                            		while(i*nFact > k)
                            		{
                            				k += 9*Math.pow(10, i);
                            				i++;
                            		}
                            		
                            		for(int j=10; j <=k ; j++)
                            		{
                            			String[] digits = (j+"").split("");
                            			
                            			int sum = 0;
                            			for(int l = 1; l < digits.length; l++)
                            			{
                            				sum += factorial(Integer.parseInt(digits[l]));
                            			}
                            			
                            			if(j==sum)
                            			{
                            				probSum += j;
                            			}
                            		}
                            		
                            		System.out.println(probSum);



                            EDIT: cool, got another :3


                            Problem:

                            Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

                            For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 53 = 49714.

                            What is the total of all the name scores in the file?


                            Solution:

                            Code:
                            int totalScore = 0;
                            		
                            		File file = new File("names.txt");
                            		Scanner scan = null;
                            		try 
                            		{
                            			scan = new Scanner(file);
                            		} 
                            		catch (FileNotFoundException e) {}
                            		String nameString = scan.next();
                            		String[] names = nameString.split("\",\"");
                            		ArrayList<String> names2 = new ArrayList<String>();
                            		for(int i = 0; i < names.length; i++)
                            		{
                            			names2.add(names[i]);
                            		}
                            		
                            		Collections.sort(names2);
                            		for(int i = 0; i < names2.size(); i++)
                            		{
                            			char[] chars = names2.get(i).toCharArray();
                            			int charSum = 0;
                            			for(int j = 0; j < chars.length; j++)
                            			{
                            				charSum += chars[j] - 'A' + 1;
                            			}
                            			totalScore += charSum*(i+1);
                            		}
                            		System.out.println(totalScore);
                            Last edited by benguino; 02-26-2013, 11:36 AM.
                            AMA: http://ask.fm/benguino

                            Not happening now! Don't click to join!



                            Originally posted by Spenner
                            (^)> peck peck says the heels
                            Originally posted by Xx{Midnight}xX
                            And god made ben, and realized he was doomed to miss. And said it was good.
                            Originally posted by Zakvvv666
                            awww :< crushing my dreams; was looking foward to you attempting to shoot yourself point blank and missing

                            Comment

                            • Arkuski
                              FFR Veteran
                              • Jul 2006
                              • 1118

                              #239
                              Re: The Project Euler thread

                              Learned some jython, and these are all much easier

                              Originally posted by Wayward Vagabond
                              i can appreciate a good looking woman when i see one and this one just happened to be my mom

                              Comment

                              • Choofers
                                FFR Player
                                FFR Music Producer
                                • Dec 2008
                                • 6205

                                #240
                                Re: The Project Euler thread

                                I'm currently on my lunch break, so I decided that instead of studying for my ethernet and osi model exam tomorrow, I'd delve into powershell.

                                Had a bit of an issue getting custom scripts to work without having digital signatures, but oh well.


                                Code:
                                $count = 0
                                $total = 0
                                do{if (($count % 3 -eq 0) -or ($count % 5 -eq 0))
                                  {
                                  $total = $total + $count
                                  }
                                  else
                                  {
                                  $total = $total
                                  }
                                $count++
                                }
                                while ($count -lt 1000)
                                echo $total


                                this feels very reminiscent of java and maybe you DuDeZ will stop hating me because I'm not using BASIC

                                maybe ???


                                edit: problem two solved, I was originally incrementing my variables one number at a time but I quickly realized that this would need a variable for every number in the sequence lol


                                Code:
                                $f0 = 0
                                $f1 = 1
                                $fsum = 0
                                do{
                                  if ($f1 % 2 -eq 0)
                                  {
                                    $fsum = $fsum + $f1
                                  }
                                  if ($f0 % 2 -eq 0)
                                  {
                                    $fsum = $fsum + $f0
                                  }
                                  $f0 = $f0 + $f1
                                  $f1 = $f1 + $f0
                                  }
                                while ($f0 -lt 4000000)
                                echo $fsum
                                Last edited by Choofers; 07-15-2013, 02:19 PM.

                                Comment

                                Working...