Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

A Challenge For Prog

Name: Anonymous 2008-05-16 8:12

No, I'm not a student looking to get my program written for me.
I'm just trying to find the most optimized solution to a problem, and at the same time it makes a decent challenge for /prog/.

The problem :-

Name: Anonymous 2008-05-16 8:14

You have a set of doubly-linked classes. (Yes this is C++).
Each class contains an int of any value.

You must rearrange the links so that every possible combination of numbers is displayed to the console screen.

E.g
class 1 contains 1, 2 contains 2, 3 contains 3.
So it's 123.

Now the program needs to have this output:
123
132
213
231
321
312

DOES /PROG/ RISE TO THE CHALLENGE?

Name: Anonymous 2008-05-16 8:19

this is C++
now you have OVER 9000 problems

Name: Anonymous 2008-05-16 8:33

>>2
You have a set of doubly-linked classes.
Hint: they're called objects.

Name: Simon Peyote Joints 2008-05-16 9:04

{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses #-}

import Control.Monad.State
import Control.Monad.Reader

newtype Permu s a = Permu { unPermu :: StateT [s] [] a }
    deriving (Functor, Monad, MonadPlus)

runPermu :: Permu s a -> [s] -> [(a, [s])]
runPermu = runStateT . unPermu

evalPermu :: Permu s a -> [s] -> [a]
evalPermu p xs = map fst $ runPermu p xs

execPermu :: Permu s a -> [s] -> [[s]]
execPermu p xs = map snd $ runPermu p xs

draw :: Permu s s
draw = Permu $ do
    s <- get
    (x, xs) <- lift $ select' s
    put xs
    return x

select' :: [a] -> [(a, [a])]
select' [] = []
select' (x : xs) = (x, xs) : map (fmap (x :)) (select' xs)

pruneIf :: (s -> Bool) -> Permu s ()
pruneIf f = Permu $ do
    modify . filter $ not . f

prune :: (Eq s) => s -> Permu s ()
prune s = pruneIf (s ==)

select :: [a] -> Permu s a
select = Permu . lift

instance MonadReader [s] (Permu s) where
    ask = Permu get
    local f p = select . evalPermu p . f =<< ask

permute :: [a] -> [[a]]
permute = join . liftM evalPermu . mapM . return $ draw

main :: IO ()
main = putStr . unlines . map show . permute $ [1, 2, 3]

Name: Anonymous 2008-05-16 9:07

>>2
what

Name: Anonymous 2008-05-16 10:57

>>5
Excuse me, but OP said "doubly-linked classes [sic]". You, sir, have failed.

Name: Anonymous 2008-05-16 13:35

I'd give the OP advice if >>2 actually made ANY FUCKING SENSE.

Name: Anonymous 2008-05-18 1:29

>>8


I'd fuck your sense if OP had any advice.

Name: Anonymous 2008-05-18 1:40

Umm most efficient way

First the whole linked list bullshit is retarded  Basically a linked list optimized algorithm for this type of problem is retarded.  It's like saying hey here is a stack now use it to efficiently randomly access certain numbers, now make it optimized!!! OMG

The fastest implementation of this is basically moronic.  There is no "fastest implementation". 

The problem of arranging it in every combination is a factorial.

Factorial gets extremely slow the more numbers added.

There really is no optimized way to output them since you basically are forced to take a factorial time algorithm to do so.  It's worse then an NP complete problem.

so in ending fuck off.




Name: Anon 2008-05-18 8:13

I'd also love to give advice. Just need to solve the following problem:

1) rearrange classes
2) ?????
3) PROFIT!

WUT for?

Name: Anonymous 2008-05-18 10:33

I'd fuck OP in the sense of giving bad advice.

Name: Anonymous 2008-05-18 21:33

>>2
Work with plain old arrays and stop being a faggot. Shit, even more, if i had to solve this, i'd malloc() a fucking array of integers of the size of your linked list.

If you insist it must be OMG OPTIMIZED, then suggest how would some code that does this be useful in real life apps.

Name: Anonymous 2008-05-19 10:50

import List

permu l = map fst $ iterate (concatMap (\(f,s) -> fmap(\x -> (x:f, delete x s)) s)) [([], l)] !! length l


Name: Anonymous 2008-05-19 14:43

>>14
wow you can use libraries?

Name: Anonymous 2008-05-19 14:46

>>14

PermuteAndPrintList input

Name: Anonymous 2008-05-19 15:48

import Monad

permu [] = [[]]
permu (x:xs) = ap [(x:), (++[x])] $ permu xs

Name: >>17 2008-05-19 16:38

Last version was wrong. Sorry about that.

import Monad

permu [] = [[]]
permu l = do (a, x:b) <- map (flip splitAt l) [0..length l]
             map (x:) $ permu (a ++ b)

Name: Anonymous 2008-05-19 19:47

>>15

Data.List is one of the fundamental Haskell core libraries. As well disallow C++ solutions from using the STL. All he's using from List is 'delete', and that's a like one-line definition for this usage.

Name: Anonymous 2008-05-19 19:49

wtf is haskell? never heard of that language.

Name: Anonymous 2008-05-19 19:59

>>20
It's not a language. It's a dog.

Name: Anonymous 2008-05-19 20:07

>>20
>>21
Terrible!

Name: Anonymous 2008-05-19 20:09

>>22
Poor form. Wait for the setup!

Name: Anonymous 2008-05-19 20:48

>>19 <-- Did anyone understand what the fuck this guy is trying to say?

Name: Anonymous 2008-05-19 21:24

>>24
His dog died in 2007 because he lacked pancreas. How did he secrete digestive enzymes? Terrible!

Name: Anonymous 2008-05-19 21:30

>>25 <-- Did anyone understand what the fuck this guy is trying to say?

Name: Anonymous 2008-05-19 22:01

>>26
*grabs dog*

Name: Anonymous 2008-05-19 22:43

>>25
Should've gotten a new pancreas like in Neuromancer.

The sky was the color of television, tuna fish'd into a dead channel.

Name: Anonymous 2008-05-20 0:02

>>26
lurk moar

Name: Anonymous 2008-05-20 1:07

But who in their right mind would tuna fish with their butt?

Name: Anonymous 2008-05-20 3:09

Speaking of which, please take a look at this:

http://img262.imageshack.us/img262/6736/litsscreenct0.png 

Name: Anonymous 2008-05-20 8:20

well, haskell sucks ass and haxed my anus

Name: Anonymous 2008-05-21 12:34

>>30
Shut up, ddrddr.

Name: Anonymous 2008-05-21 13:23

ddrddrddrddrrddrrrr

Name: Anonymous 2008-05-21 17:03

>>32
how does it smell

Name: Anonymous 2008-05-21 20:08

Name: Anonymous 2008-05-21 20:21

>>36
Like a penis? Cool.

Name: Anonymous 2008-05-21 20:27

>>36
All I see is THE METAVERSE IS A DANGEROUS PLACE; HOW'S YOUR SECURITY? CALL HIRO PROTAGONIST SECURITY ASSOCIATES FOR A FREE INITIAL CONSULTATION.

Name: Anonymous 2008-05-21 20:36

>>36
Now we need to create an extensible smell description language.

Name: Anonymous 2008-05-22 7:49


Treat a subset of double-linked list as a ring.

   ***>

  /2-3-4\
1<       >5
  \8-7-6/

   <***

     ==>

    /3-4-5\
1-2<       |
    \8-7-6/

     <==

        ->

      /4-5\
1-2-3<     >6
      \8-7/

       <-

(Operation applies within every rotating ring after every turn using whatever order of existing links it has until the ring is back in its initial position. Then outer ring makes its step)

Name: Anonymous 2011-02-03 5:26

Name: Anonymous 2011-02-04 16:00

Name: Anonymous 2011-02-04 17:03

Name: Sgt.Kabukimanセ꜏ 2012-05-23 5:46

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List