Someone give me a problem to script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrGiggles
    Senior Member
    • Aug 2005
    • 2846

    #16
    Re: Someone give me a problem to script

    How about wordcounters, I had fun with those because of all the little extra things you can work towards (ignoring numbers, acronyms, common words, etc) and it's not mathy at all

    bonus points if you use a sorting algorithm of your choice to sort in descending order of occurrence

    triple bonus points if it outputs a wordcloud rather than a list

    Comment

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

      #17
      Re: Someone give me a problem to script

      okay yeah, that prime number one looks a LOT easier now, gonna have to write some pseudo-code tonight and then I'll script it tomorrow at lunch

      for the DDReam one, that'll take a bit, I think. I don't know much about .ds files too, are they relatively the same as .sm files?

      the word counter would be trivial but I don't think powershell has the power (HEH) to generate wordclouds. maybe if I stopped being lazy and picked up javascript or java again.
      Last edited by Choofers; 08-12-2013, 04:13 PM.

      Comment

      • PaperclipGames
        Mrow~
        • May 2008
        • 648

        #18
        Re: Someone give me a problem to script

        On prime testing: create a list with primes, and for any next number you only need to test if it is divisable by any element in that list that is smaller than or equal to the square root of the number you're testing. If not, add it to the list of primes. Continue until you feel satisfied.

        For the number 100, you'd only have to check if it is divisible by any element in {2,3,5,7} since only those primes are leq 10. Of course you can immediately stop after checking 2, but the point is clear.

        (The reason that going through the square root is enough is because if your number n equals p*k for a p>sqrt(n) then k<sqrt(n) and you'd have found k already.)

        Edit: Using this method also makes it really easy to make another list that calculates the prime gaps.
        Last edited by PaperclipGames; 08-12-2013, 04:14 PM.
        948 AAAs | 1461 FCs | 549 TPs | 7 FMO AAAs
        Best AAAs: Exciting Hyper Highspeed Star (69), Nous (69), Pure Ruby (68), Heavenly Spores (68), Ambient Angels (66), Within Life (66), Defection (66) Southern Cross (65)

        Comment

        • shenjoku
          Wubalubadubdub
          • May 2005
          • 1697

          #19
          Re: Someone give me a problem to script

          I don't know anything about powershell or how hard you want this to be so here's a fairly common (I think) somewhat easy interview question:

          Write a program that takes in a string, reverses it, and prints the result. Try to do this as efficiently as possible, that's the hard part
          boop

          Comment

          • igotrhythm
            Fractals!
            • Sep 2004
            • 6535

            #20
            Re: Someone give me a problem to script

            Originally posted by Choofers
            if by valid anagrams you mean anagrams that make at least some sense, then that might be tough because I'd need a dictionary... unless I'm missing something

            arkuski you're gay and I'm dumb as shit



            Code:
            cls
            $strInput = read-host "insert string"
            $strNoCom = $strInput.Split(',')
            $strNoSpace = $strNoCom.Split(' ')
            $arrOutput = @()
            $intCount = 0
            $intCount2 = 0
            
            do{
                $strTemp = $strNoSpace[$intCount]
            
                if ($strTemp.Length -gt 1){
                    $arrOutPut += $strTemp
                    $intCount2++
                    }
                $intCount++
            }
            until($intCount -eq $strNoSpace.length)
            
            $arrOutput


            that prime one sounds super interesting, but I am seriously shit at math so I would have no idea how to efficiently test a number to see if it's prime
            If m % n != 0 for all prime integers n < sqrt(m), then m is prime. Probably how you'd write what Paperclip and Axith said. So for 11, it would test for 2 and 3, then stop and conclude that 11 is prime since 5 > sqrt(11), but the problem there would be the fact that you'd have to populate the list of test numbers from scratch every time. You'd also have to define 2 and 3 as prime to give you a leg up on populating the list of test divisors.

            As you can see, the runtime would go up quite quickly even to 100 because then you're running stuff for 49 that's like "2, yes. 3, yes. 5, yes. 7, no. 49 is not prime, do not add it to the list of test divisors, on to 50." As you can see, the sieve of Erastothenes is probably better for numbers in a range 1 to n inclusive. Remove 1, spare 2, remove all multiples of 2. Spare 3, remove all multiples of 3. Next number is 5, so remove all multiples of 5, and so on.
            Last edited by igotrhythm; 08-12-2013, 05:58 PM.
            Originally posted by thesunfan
            I literally spent 10 minutes in the library looking for the TWG forum on Smogon and couldn't find it what the fuck is this witchcraft IGR

            Comment

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

              #21
              Re: Someone give me a problem to script

              Originally posted by shenjoku

              Write a program that takes in a string, reverses it, and prints the result. Try to do this as efficiently as possible, that's the hard part
              $a = "string"
              [array]::Reverse($a)
              write-host $a

              that's the nice thing about powershell, working with anything other than numbers is generally very very easy

              Comment

              • shenjoku
                Wubalubadubdub
                • May 2005
                • 1697

                #22
                Re: Someone give me a problem to script

                lmao never mind then XD Shoulda figured as much since it's a scripting language.
                boop

                Comment

                • Fission
                  no
                  FFR Simfile Author
                  • Jan 2004
                  • 1850

                  #23
                  Re: Someone give me a problem to script

                  string reversal is much more relevant in a language like c/c++ that uses character arrays to store strings since most of what the string reversal problem is is linked list manipulation

                  EDIT: it depends on how the strings are stored internally too. this is based on the assumption that they are stored as a linked list (no implementation does this, afaik). string reversal is trivial with a dynamic array.
                  Last edited by Fission; 08-12-2013, 08:21 PM.

                  Comment

                  • Wayward Vagabond
                    Confirmed Heartbreaker
                    FFR Simfile Author
                    • Jul 2012
                    • 5866

                    #24
                    Re: Someone give me a problem to script

                    Originally posted by Choofers
                    okay yeah, that prime number one looks a LOT easier now, gonna have to write some pseudo-code tonight and then I'll script it tomorrow at lunch

                    for the DDReam one, that'll take a bit, I think. I don't know much about .ds files too, are they relatively the same as .sm files?

                    the word counter would be trivial but I don't think powershell has the power (HEH) to generate wordclouds. maybe if I stopped being lazy and picked up javascript or java again.
                    I think trumaestro means a sm file made with ddream

                    Comment

                    • trumaestro
                      I don't get no respect
                      FFR Simfile Author
                      • Jun 2006
                      • 1332

                      #25
                      Re: Someone give me a problem to script

                      Originally posted by Wayward Vagabond
                      I think trumaestro means a sm file made with ddream
                      Essentially. You can treat either as a text file though.

                      Comment

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

                        #26
                        Re: Someone give me a problem to script

                        oh cool

                        Comment

                        • Zephei
                          The Supreme Bean
                          • Nov 2011
                          • 297

                          #27
                          Re: Someone give me a problem to script

                          Originally posted by Arkuski
                          Write a script that finds a combination of positive integers (x,y,z) that satisfies the formula:

                          (x^3)+(y^3)=(z^3)
                          Damn, someone else already said that joke.

                          The prime number problem is a good one. Try using the sieve of eratosthenes.
                          Expert AAAs: 22
                          Master AAAs: 11
                          Guru AAAs: 9

                          Comment

                          • beary605
                            FFR Veteran
                            • Oct 2008
                            • 448

                            #28
                            Re: Someone give me a problem to script

                            The Four Fours?

                            Comment

                            • benguino
                              Kawaii Desu Ne?
                              • Dec 2007
                              • 4185

                              #29
                              Re: Someone give me a problem to script

                              Here's another one if you finish the rest are looking for more. I'll put it in spoilers so you can open it when you are ready instead of seeing the problem and being pressured to solve it (if you already have a good queue of problems to solve).


                              Tic Tac Toe AI

                              You're goal will be to make an AI smart enough to make not-dumb moves in Tic Tac Toe.

                              Input: a 3x3 matrix of strings. This is the current tic tac toe grid before the AI's turn. This matrix is filled with "X"s, "O"s, and empty strings to denote open spots. The AI is playing as X's.
                              Output: the 3x3 matrix that results after the AI you programmed has made it's move.

                              Requirements:
                              -If it is possible for the AI to win on that turn, you must make the move that allows the AI to win on that turn.
                              -If it is not possible for the AI to win this turn and it is possible for your opponent to win on his next turn, you must block him to prevent him from winning. If it is guarenteed your opponent will win next turn however, print "FUUUUUU..." and make whatever move you please.
                              -If none of the other cases hold above, make the move either via RNG or a method of your choosing.
                              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

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

                                #30
                                Re: Someone give me a problem to script

                                Got sieve implemented, that was fun to write. :P Script is super messy but I'll comment everything and make it look pretty once I get the full thing up and running.

                                Code:
                                $n = read-host "input integer"
                                $A = $False,$False
                                $x = 2
                                $B = @()
                                
                                do{
                                    $A += $True
                                    $x++
                                    }
                                until($x -eq [int]$n+1)
                                
                                $i = 2
                                
                                do{
                                write-host "Current value of i is $i."
                                    if($A[$i] -eq $True){
                                    $x = 0
                                    do{
                                           
                                            $j = ($i*$i)+($i*$x)
                                            write-host "Current value of j is $j."
                                            if($j -gt $n){                
                                            }
                                            else{
                                            $A[$j] = $False
                                            }
                                            $x++
                                            write-host "Current value of x is $x."
                                            }
                                        while($j -lt $n)
                                        }
                                        $i++
                                    }
                                while($i -lt [system.math]::Sqrt($n))
                                
                                $x = 0
                                
                                do{
                                    if($a[$x] -eq $true){
                                        [array]$B += $x
                                        }
                                        $x++
                                        }
                                        until($x -eq $n)
                                    
                                    $B

                                Comment

                                Working...