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

Pages: 1-

The greatest and worst method evARR!!!

Name: Anonymous 2007-08-13 3:20 ID:ZlKPicRr

class String
    def random_caps
        letters = self.split("")
        letters.length.times do |n|
            letters[n] = letters[n].upcase if rand(4) == 0
        end
        letters.join("")
    end
end

created after total boredom.

discuss uses, etc.

Name: Anonymous 2007-08-13 3:31 ID:y0hQ6b0E

from random import*;random_caps=lambda s:''.join(chr(ord(c)^((random()>0.75)*32))for c in s)

Name: Anonymous 2007-08-13 3:44 ID:HTcG9yxK


;RANDOM_CAPS
;THIS ROUTINE REQUIRES 2 2-BYTE POINTERS IN ZERO PAGE
; IDENTIFYING WHERE THE INPUT AND OUTPUT STRINGS ARE
;SELECT APPROPRIATE LOCATIONS FOR YOUR SYSTEM
;THE FOLLOWING WORKS ON COMMODORE 64 ARCHITECTURE
INPUT  EQU 251
OUTPUT EQU 253
;STRINGS MUST BE TERMINATED WITH A ZERO BYTE AND BE LESS
; THAN 255 CHARACTERS IN LENGTH
;THIS ROUTINE ALSO REQUIRES ANOTHER ROUTINE NAMED 'RANDOM'
; THAT PRODUCES A RANDOM OR PSEUDORANDOM NUMBER IN .A
; YOU HAVE TO WRITE THAT ONE YOUR DAMN SELF
RNDCAP LDY #0 ;START AT 0
LOOP   LDA (INPUT),Y ;GET A CHAR
       BEQ DONE ;IF ZERO, STOP
       TAX ;SAVE IN X
       JSR RANDOM ;GET RANDOM
       CMP 64 ;64 FOR 1 IN 4 CHANCE
       BCS SKIP ;IF MORE THAN 64 SKIP IT
       TXA ;GET BACK A
       AND #%11011111 ;TURN OFF BIT 6, MAEK IT CAPITAL
       JMP CONT ;NXT PLZ
SKIP   TXA
       STA (OUTPUT),Y ;STORE THE SHIT
CONT   INY ;SO, NXT PLZ
       BEQ DONE; BUT IF .Y = 0 IT FLIPPED OVER, QUIT
       JMP LOOP; LOOP
DONE   RTS
;STUB ROUTINE, MAKE YOUR OWN
RANDOM LDA #255
       RTS

Name: Anonymous 2007-08-13 3:46 ID:Heaven

>>1
Crappy coding style considered harmful.

class String
    def random_caps
        self.split('').collect do |c|
            rand(4) == 0 ? c.upcase : c
        end.join
    end
end

Name: I LIKE PARENS 2007-08-13 5:56 ID:Heaven

OKAY FAGGOTS I DON'T KNOW SHIT ABOUT C OR WHATEVER THAT IS BUT THIS IS NOT FUNNY HERE'S A SCHEME CODE FOR MAKING A TEXT ALL CAPS.

(define (up a)
  (let ((a-list a) (b-list a))
    (set! a-list (string->list a))
    (set! b-list (map char-upcase a-list))
    (set! a-list (list->string b-list))
    a-list))

Name: Anonymous 2007-08-13 8:12 ID:fXNuDll6

randomCaps = mapM $ \ ch -> Random.randomRIO (0 :: Int, 1) >>= \ n -> return $ [Char.toUpper, Char.toLower] !! n $ ch

Name: Anonymous 2007-08-13 8:58 ID:MBD/348l

private static final Random rand = new Random();
public static String randomCaps(String s) {
  StringBuilder b = new StringBuilder(s);
  for(int i=0; i<b.length(); i++)
    b.setCharAt(i, rand.nextBoolean()
      ? Character.toUpperCase(b.getCharAt(i))
      : Character.toLowerCase(b.getCharAt(i)));
  return b.toString();
}

Name: Anonymous 2007-08-13 9:15 ID:RApp4OTu

>>3 is an EXPERT 6502 PROGRAMMER

Name: Anonymous 2007-08-13 11:13 ID:Heaven

>>7
ONE WORD, ENTERPRISE, THREAD OVER.

Name: Anonymous 2007-08-13 21:24 ID:+lrec7hz

destructive:
(defun randomcaps (s)
   (map-into s
       (lambda (c)
            (if0 (random 4)
                 (char-upcase c)
                 c))
        s))

example:

[18]> (let ((x "yeah yeah yeah dude")) (randomcaps x) x)
"yeaH yeAh yeah DuDe"

if you want a functional version switch "map-into s" for "map 'string"

Name: Anonymous 2007-08-13 22:08 ID:hJIpXFbV

>>6
Chaining lambda expressions with >> and >>= doesn't count for purposes of haskell golf.

Name: Anonymous 2007-08-13 22:44 ID:+lrec7hz


randomCaps = mapM $ \ ch -> Random.randomRIO (0 :: Int, 1) >>= \ n -> return $ [Char.toUpper, Char.toLower] !! n $ ch
(defun randomcaps (s) (map-into s (lambda (c) (if0 (random 4) (char-upcase c) c)) s))

lisp is clearer, yet shorter.

Name: Anonymous 2007-08-13 23:33 ID:CXcA5c6Q

randomCaps s = do
   g <- Random.newStdGen
   putStr $ zipWith ($) (map ([id, Char.toUpper]!!) $ Random.randomRs (0,1) g) s

cycle "FAP"

Name: Anonymous 2007-08-14 12:36 ID:vEkh3DN2

This is how you do it in a language that didn't have string functions sloppily tacked on as an afterthought:

s|.|int-rand-4?$&:uc$&|eg

Name: Anonymous 2007-08-14 12:45 ID:Heaven


for(; *s = rand()%2toupper(*s):tolower(*s); s++);

C > you

(now some C weenie will mention the (unsigned char) casts that i /forgot/ to put when i called toupper/tolower. fukin weenies.)

Name: Anonymous 2007-08-14 12:55 ID:WE2irXYb

>>15
Ugly.  Also you forgot Questiond.

Name: Anonymous 2007-08-14 13:31 ID:kcXs1HzP

>>1
Pass all your email through it. Other useful filters, implementation not shown:

>>>print leetify("I want that report done by friday! No more slacking off. -- Boss.")
Omglol! i want t4at report done by fridaY!!!!11 no more slackiNg off. -- bsz

>>>print smurfify("Why do you never answer my email? If this continues I will have to fire you!")
Why do smurf never smurf my smurf? Smurf this continues I smurf have to smurf smurf!

Name: Anonymous 2007-08-14 15:58 ID:9eMrMHd1

int(*f[2])(int)={&toupper,&tolower};
for(;*s=(f[random()%2])(*s);s++);

Name: Anonymous 2007-08-14 20:37 ID:9eMrMHd1

: random_caps ( str -- str ) [ (random) even? [ ch>upper ] [ ch>lower ] if ] map ;

Name: Anonymous 2007-08-14 20:43 ID:Heaven

>>19
: random_caps ( str -- str ) [ { ch>upper ch>lower } random execute ] map ;

Name: Anonymous 2007-08-14 21:17 ID:Heaven

random_caps ($@ . !! ? (\@ ^ > | ^ <) . &)

Name: Anonymous 2007-08-14 21:19 ID:Heaven

for(;*s=(random()%2?toupper:tolower)(*s);s++);

Name: Anonymous 2007-08-14 22:51 ID:7G7hd/vk

>>22
for a fair comparison, it should look something like this (and the function is called rand()):

void random_caps(char* s)
{
for(;*s=(rand()%2?toupper:tolower)(*s);s++);
}

or if you want to compete with the one liners:

void random_caps(char* s){for(;*s=(rand()%2?toupper:tolower)(*s);s++);}



Name: Anonymous 2007-08-14 22:59 ID:Heaven

while(*s = (rand()&1:?toupper:tolower)(*s++));

Name: Anonymous 2007-08-15 2:05 ID:buK/UCAs

randomCase = mapM (if unsafePerformIO (randomR (0,4)) == 0 then toUpper else id)

Name: Anonymous 2007-08-15 3:51 ID:Heaven

LOL, you sure do enjoy writing trivial code.. noobs.

Name: Anonymous 2007-08-15 6:59 ID:GRimqj0v

>>26
you wish you could write code this GREAT

Name: Anonymous 2007-08-15 18:52 ID:QfjBAsiB

>>25
unsafePerformIO considered harmful

Name: Anonymous 2007-08-15 19:33 ID:5fUHgnsG

>>28
>>unsafePerformIO considered unsafe

Name: Anonymous 2007-08-15 20:17 ID:CzFgLH+j

>>28
unsafePerformIO is the only way to get anything done in Haskell.

Name: Anonymous 2011-02-03 7:59

Name: Anonymous 2011-02-17 19:53

that's cool and all, but check 'em
Don't change these.
Name: Email:
Entire Thread Thread List