crypt :: String -> String -> String
crypt key salt =
taketail 10 $
unsafePerformIO $ peekCString $
unsafePerformIO $
withCString key $ \k ->
withCString salt $ \s ->
c_crypt k s
where
taketail :: Int -> [a] -> [a]
taketail i x = (reverse (take i (reverse x)))
makesalt :: String -> String
makesalt x =
map
fixsalt
(take 2
(if (length x) < 2 then ("H.") else (tail x)))
where
fixsalt :: Char -> Char
fixsalt c
| (inrange '0' '9' c) = c
| (inrange ':' '@' c) = (chr ((ord c) + 7))
| (inrange 'A' 'Z' c) = c
| (inrange '[' '`' c) = (chr ((ord c) + 6))
| (inrange 'a' 'z' c) = c
| c == '/' || c == '.' = c
| otherwise = '.'
where
inrange :: Ord a => a -> a -> a -> Bool
inrange low upp x = x >= low && x <= upp
tripcode :: String -> String
tripcode s = crypt s (makesalt s)
main :: IO ()
main = do
args <- getArgs
putStrLn (tripcode (head args))
>>40
also proof that the code tags don't work right on here. newlines right after [/code] get removed.
Name:
Anonymous2006-11-28 17:49
...NET?
Name:
Anonymous2006-12-09 14:14
Okay guys, I just learned list comprehension, and using that, I managed to turn my five line permutation function into a one-line golden masterpiece (I can't even understand the code anymore!). How's this for concise (LOL)!!
Any ideas on how I can remove the Eq dependency (/=) elegantly? I realize you usually want to be able to distinguish elements in a permutation, but it'd still be nice. Hmm... thinking about the code, I just figured it out! It does ys <- for every y <-. Nice, that explains why it works :)
Now, I want to see you C fanboys do this in 2000 lines of code!!
Name:
Anonymous2006-12-09 14:26
>>43
I just realized this doesn't work if two elements are the same... removing the Eq dependency would fix that, however.
Name:
Anonymous2006-12-09 14:54
>>43
how is this shit any better than obfuscated perl
it takes just as much effort to understand
Also, the Haskell solution is using simple language features, what's hard to understand about the solution is the actual algorithm used... I think, at least.
>>43
You could get rid of the Eq dependency by zipping the items on the input list with elements [1..], and then instead of having an Eq constraint on the 'a' type variable you could go with Int's Eq instance. If the caller needs the outputs to appear at most once in the output lists, s/he can just nub the input and be done with it.
Name:
Anonymous2006-12-15 20:30
Your code is incorrect. These will fail (compare to 2channel):
#><
#kami
Name:
sister preggo test in python2006-12-18 9:45
>>> def do_her():
... question = raw_input('do you really want to do her?')
... if question in ('y','yes','oh yes') : return True
... if question in ('n','no','im gay') : return False
... print 'is she pregnant?:'
... print do_her
Name:
Anonymous2006-12-18 10:11
>>51 >>8 it's a much simplified version of the tripcode algorithm,
anyway, this language is much better than all the other crap in this thread: function do_tripcode: dup. "2" "1" substr. "H." swap. concat. "A-Ga-f." ":-@[-` --{-" tr. crypt. "10" "3" substr.
function main: do_tripcode, print.
>>61
Incorrect, code written by novices is highly readable and thus easy to refactor into god-level unreadable Haskell.
Name:
Anonymous2007-01-03 10:26
>>61
It's not unreadable until you go entirely point-free and mix in some arrows for good measure.
Name:
Anonymous2007-01-03 10:34
Haskell is shit. I shouldn't have to achieve satori just to make a short program that takes 10 minutes in C.
Name:
Anonymous2007-01-03 11:03
>>53
If you can't tell me what language that is, maybe you can tell me how to google for "dup." instead of "dup".
Name:
Anonymous2007-01-03 12:15
>>65
I searched for "function dup substr concat swap crypt" in
msn.com and the first match was this thread.
Name:
Anonymous2007-01-03 12:19
dup. execute 'dup' (duplicates the value on top of the stack) instead of pushing it onto the stack" pop. "2" "1" substr. push '2' and then '1' onto the stack and then execute 'substr'" pop.
you should be able to figure out the rest...
as for what language it is, it doesn't have a name yet, but it does have a working compiler (currently unreleased) and about half of the standard library is written.
oops, just ignore the '" pop.' on the end of each of those lines...
thats how you do comments in this language, i replaced the " at the beginning with [/code] and forgot to take the stuff off the end of each comment.
Name:
Anonymous2007-01-03 12:24
>>67
Did you start from scratch, or adopt another compiler?
>>71
actually, no. i didn't even think of the similarities with forth, as i've never used forth... >>67
oops... the comma is a typo for a period.
the period means to pop the first value off the stack and execute it if it's a function or just discard it if it's not. so the function gets pushed onto the stack and then popped off and executed. except that the compiler doesn't actually do the push and pop.
and actually i guess you could use just a period instead of " pop." for comments...