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

Pages: 1-

rotate my anus

Name: Anonymous 2010-11-29 14:45

sup /prog/, I wrote this in c#, and it seems that I'm too stupid to reverse this to write a rotate right algorithm. can you halp?


    /// <summary>
    /// rotates the chars in a string to the left p times
    /// </summary>
    /// <param name="v">value to rotate</param>
    /// <param name="len">value length</param>
    /// <param name="p">places to rotate</param>
    /// <returns></returns>
    static string rotl(string v, int len, int p)
    {
        char[] o = new char[len];

        for (int i = 0; i < len; i++)
        {
            o[i] = v[(i + p) % len];
        }

        return new string(o);
    }

Name: Anonymous 2010-11-29 14:48

I wrote this in c#
Now you have two problems

Name: Elly_Tran_Ha !HfYItjXlBs 2010-11-29 14:49

//assuming you're not using negative numbers

int i = len; i>0; i--

//using negative numbers
int i=0; i>i-len; i--

Name: Anonymous 2010-11-29 14:51

static string rotr(string v, int len, int p){
        char[] o = new char[len];
        p = len - p;

        for (int i = 0; i < len; i++)
        {
            o[i] = v[(i + p) % len];
        }

        return new string(o);
    }

well that was hard.

Name: Anonymous 2010-11-29 14:52

>>3

for (int i = len; i > 0; i--)
{
     o[i] = v[(i + p) % len];
}


index was outside the bounds of the array o-o

Name: Anonymous 2010-11-29 14:53

>>4
thanks

Name: Anonymous 2010-11-29 14:55

>>5

Oh yeah... int = len-1

but yeah 5 has it as well.

Name: Anonymous 2010-11-29 15:06

>>3,5,7
hey fill me in, what does the order you traverse the array have to do with the direction the characters have shifted?

Name: Anonymous 2010-11-29 15:16

>>8
Uh... everything?

Name: Anonymous 2010-11-29 16:04

>>9
everything eh?
are you sure it's not NOTHING?
because I think it might be NOTHING.

Name: Anonymous 2010-11-29 17:00

>>10
No, no, I'm pretty sure it's everything.

Name: Anonymous 2010-11-29 17:01

anus@anustop:~$ gcc -o test test.c
anus@anustop:~$ ./test faggot 6 2
faggot
ggotfa
otfagg
anus@anustop:~$ gcc -D FAIL -o test test.c
anus@anustop:~$ ./test faggot 6 2
faggot
ggotfa
ggotfa

#include<stdio.h>
#include<stdlib.h>

char* rotl(char v[], int len, int p){
    char *o;
    int i;

    o = malloc(sizeof(char) * len);

    for (i = 0; i < len; ++i)
      o[i] = v[(i + p) % len];

    return o;
}

#ifdef FAIL
char* rotr(char v[], int len, int p){
    char *o;
    int i;

    o = malloc(sizeof(char) * len);

    for (i = len-1; i >= 0; --i)
      o[i] = v[(i + p) % len];

    return o;
}
#else
char* rotr(char v[], int len, int p){
    return rotl(v,len,len-p);
}
#endif

int main(int argc, char *argv[]){
    char *o, *p;
    if(argc != 4)
      return 1;

    printf("%s\n%s\n%s\n",
           argv[1],
           o = rotl(argv[1],atoi(argv[2]),atoi(argv[3])),
           p = rotr(argv[1],atoi(argv[2]),atoi(argv[3])));
    free(o);
    free(p);
    return 0;
}

I'm starting to suspect the order you traverse the array has nothing to do with the shift in characters. Can you give me your satori-level analysis >>9 ? Because I'm still not sure.

Name: Anonymous 2010-11-29 17:41

Dear Lord, OP, what the fuck. At least try and use your fucking brain every once in a while, please.

Name: Anonymous 2011-02-03 1:40

Name: Anonymous 2011-02-04 15:49

Name: Anonymous 2013-09-01 14:14



               ,.-'"二フ
   ______         / //´
 く__ヽ、__`ヽ.      | | /
   `\ ヽ、!    ____,/ / !_
     `ヽ ヽ、'' ´   i。i./ `ヽ. ○
       ,`>!。/   `´      ヽ.
  O   /     i  、_ヽ. 、    ', ゜  
     ,'   /__,! ハ ハ,.ニ!、 iヽ!   ! 
     i  .i. ,!-!、. V ´ト ! }ハ !、  !
     イ i ハi ト_!.   'ー'゙。OVi  ',  o 
     レヘ 7,, _,,... -─ 、 ""i | i  ', 
   O 。 !人 |´     | 人/ ハ  ',
       / .ヘ`ヽ、_____,,..ノ//トー-'、!  ', 。
       レ´ i ヽ、 /i///_」::::::/:::ヽ. ! 
         ! .!/ヘ,.-'─、、;;;;____:::::::ヽ. |
        ./ /7:Y/ ,   l |:oo::::::`ヽ::i |
       //::::i:〈iゝi、_!__r//:::::::::::::::::ン ノ
      /::::::::/:::::Y:::::::::ゝ'─r--‐-i´イ

Name: Anonymous 2013-09-01 15:45



                     r、
.              ┌r────┴' ────┐
          ト 、   .| | ‐|ァ   _|_  ー┐ l   |
        ノ '"´ ̄| | /|⌒ヽ.  ! -‐ァ /| ̄|ヽ. |
     ,. ' /     | | ´| (_メ、 / 、_ し' .ノ   |
      / /   /|  .|_|__________|
     .!  | / _/__!  /  /__./  ,.ゝ| |
    | ∠ _/___L/|/_」_ハ   ノ .| |
    |  レ/('弋_ノ:::::::::::ヒノ ソイ   | |
   .ノ <r、`゙         ´゙|.フ  | |
   '( ノ  /_ノト,、._  ´__,,. イ ヽ   | |
   ´ レ'⌒ソヽ.r<\「ヽ!ノ⌒ソ  | |
        /\__/ムソl,ト、_     | |
  人     くX\|X|::ハ::||// 、__({⌒ヽ   人
(__)_ /\ソ,[>ムく]\// !ヽ、__ノ_.(__)
 」__[___/ヽ/イ´:::::ノ人:::ヽ._`''ー‐_'.| |___」__[
(__) |-'J7、イ/:::::::ヽ.,ハ.    | |   (__)
 |_|.  `ーへ二二ニ二_ン     | |    |_|
[__]二二  r|、_|_r|、_|、..二二 | | 二[__]
 |  |       }  _{. }__ {.     | |    |  |
 |_|       「 '⌒Y⌒`'|.     | |    |_|
    ̄ ̄ ̄ ̄`ー‐'`ー '  ̄ ̄ ̄ └' ̄ ̄ ̄ ̄

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