?

Log in

No account? Create an account
So, off and on this last week, I was corresponding with a fellow with… - CERisE's Testing for L

> Recent Entries
> Archive
> Friends
> Profile

December 22nd, 2004


Previous Entry Share Next Entry
06:44 am
So, off and on this last week, I was corresponding with a fellow with a British accent. I had a somewhat lengthy phone interview with him and on Friday, he asked me to come in.

As circumstances would have it, that Friday was two days after relsqui, philled2thebrim, talnkyo, and I spent until 6am talking about Kitii (a conlang for game night).

So, on no sleep, I went to the interview. I felt alright about it. I succeeded in making the three people I spoke to that day laugh at least once (which is always important to me in these situations). When prompted, I wrote an extremely pleasing bit of C. I was asked to write a function that would reverse a string in place.
int reverse(char* reverseme){
   int retval=-1;
   if(retval!=NULL){
      int len=strlen(retval){
      if(len>0){
         int half=len>>1;
         for(;retval<half;retval++){
            reverseme[retval]^=reverseme[len-(retval+1)];
            reverseme[len-(retval+1)]=reverseme[retval];
            reverseme[retval]^=reverseme[len-(retval+1)];
         }
      }
   }
   return retval;
}
<
Well, almost like that. I admit, I forgot the if(returnme!=NULL) line on the paper I wrote it. However, about 3 seconds after handing it to him, I mentioned that if(returnme!=NULL) should _really_ be there. He asked me about my logic (he couldn't quite parse the len-(returnval+1) bit and we had a short discussion about the state of compiler optimizations with the len>>1 bit.

So, anyway. I left there feeling that I did about as well as anyone could expect, but it wasn't a spectacular interview in my mind.

On Sunday, I got an email. It went like this (my thoughts in italics):
Thanks so much for coming in on Friday. Oh hell, not ANOTHER rejection
You impressed everyone and I think you'll thrive in our busy environment. ...but...
Your ability to solve problems and your sys admin skills are exactly what's needed to help our customers. Wait. What does he mean "exactly what's needed?" Hey, he doesn't mean...Wait, does he?
I'll write a formal offer letter on Monday for you TOUCHDOWN! Extra point good! The fans go wild and the cheerleaders come out for celebratory smooches!

So, yeah 8) I have a job! It's a short enough distance that I'm considering walking to work every day. I hate to speak in riddles, but level_head will understand when I say that my pay surpassed my initial listing of desired salary. Oh, and I get paid on the 15th and the end of the month which sure beats my previous company's policy of paying on the last day of the month.

Everyone at the office is really uber friendly. relsqui and I had planned on going to Jack's, but at around 11:30a, I found out that there was a planned company Christmas/welcoming-the-three-new-hires lunch. Since she was walking, I couldn't very well tell her about it. No one complained that she came along and she agrees with me that at the least, they've all got wonderful senses of humor.

Oh yeah! And I have a key to the office! And a really large cubicle that I'm going to personalize with my poster of the dependencies in the 2.6 linux kernel and probably a few other things.

On a sad note, the SIMM on my keychain broke off last night. The key ring fit through one of the holes on the side where the plastic pegs on the mother board fit in. The hole that it was through had been slowly getting larger and larger until last night on the way out to the car, I pulled my keys out and watched it fall. =/

So, until then, I have a keychainless keychain. With like 4 looped keyrings. relsqui is theorizing that the limit of keyrings on my keychain will go slowly to infinity.

I'm tempted to put the keychain through the other side of the SIMM, but it'd be merely delaying an inevitable repeat and I might not be so lucky about knowing where it ended up. =/

For now, it'll simply be unadorned.

And, by the way, woohoo! I have a job! 8)

EDIT: This is what happens when you're on 4 hours of sleep. *shrugs* returnme is a lot like returnval. It's all retval now. As it should be.

(20 comments | Leave a comment)

Comments:


[User Picture]
From:bloodlossgirl
Date:December 22nd, 2004 03:18 pm (UTC)
(Link)
congratulations, Phil!
[User Picture]
From:testing4l
Date:December 22nd, 2004 03:58 pm (UTC)
(Link)
Muchos arigato schoen, BLG 8)

With any luck, you'll get some level of amusement out of the certainly soon-to-come tech support calls 8)
[User Picture]
From:creativecstasy
Date:December 22nd, 2004 04:10 pm (UTC)
(Link)
congrats!!
[User Picture]
From:testing4l
Date:December 22nd, 2004 06:48 pm (UTC)
(Link)
Thanks 8)

Say, weren't you not coming to game night because of the time? We're thinking of rescheduling it.
[User Picture]
From:creativecstasy
Date:December 22nd, 2004 07:42 pm (UTC)
(Link)
well i have conflicts literally every night. rehearsals don't stop for anything.
[User Picture]
From:testing4l
Date:December 23rd, 2004 04:11 am (UTC)
(Link)
Too bad. =/

Clearly, we'll just have to kidnap you some morning.
[User Picture]
From:testing4l
Date:December 23rd, 2004 04:13 am (UTC)
(Link)
And might I add that among the many things I missed in posting via lynx (text-based web browser) was your neato new icon.
[User Picture]
From:relsqui
Date:December 22nd, 2004 07:26 pm (UTC)
(Link)
Dude. You don't initialize returnme. :P
Also you could have called me 'cause I had my phone, and made a point of mentioning that, but whatever. ;)
I will just have to get you another keychain. *g* The keyring was your theory initially because of the Burning Man thing which led to this one, but I approve of testing it out. (Failing that, want a padlock? I have some extras. Or I could put the padlock on mine and you could have the key. ;))
[User Picture]
From:relsqui
Date:December 22nd, 2004 07:27 pm (UTC)
(Link)
Where by initialize, I mean declare.
[User Picture]
From:testing4l
Date:December 23rd, 2004 04:13 am (UTC)
(Link)
And by declare, you mean properly type the same variable name.
[User Picture]
From:boymaenad
Date:December 23rd, 2004 12:28 am (UTC)
(Link)
I don't know if you speak VB, but would the equivalent of this have been sufficient, or is there something more nifty I'm missing?

Sub Reverse(MyChars as Variant)
 If Not IsNull(MyChars) Then
  Dim L as Long
 
  For L=Len(MyChars) to 1 Step -1
   MyChars=MyChars & Mid(MyChars, L, 1)
  Next L

  MyChars=Mid(MyChars,(Len(MyChars)/2)+1)

 End If

End Sub


Time: 10 mins

just wondering how employable I am :)
[User Picture]
From:boymaenad
Date:December 23rd, 2004 12:30 am (UTC)
(Link)
oh and CONGRATS :)
[User Picture]
From:testing4l
Date:December 23rd, 2004 05:55 am (UTC)
(Link)
*nods* tanks tanks. Like that one that guy stole from Camp Pendleton and got stuck on one of your brethren. 8)

[User Picture]
From:testing4l
Date:December 23rd, 2004 05:51 am (UTC)
(Link)
I speak VB. Sad though it is.

Yours has the same result in that it takes characters from the end of the array towards the beginning of the array and concatenates them.

It is, however, much much much slower. Yours will require memory allocation and double the size of the array before the end of the program whereas mine does not.

A somewhat better version of VB (and equivalent to what I did) is:

Sub Reverse (ByRef MyChars as Variant)
   If Not IsNull(MyChars) Then
      Dim n as Long
      n = Len(MyChars)
      If n > 0 Then
         Dim half as Long
         Dim i as Long
         Dim pStr as Long
         Dim s as Char   
         half = n / 2
         pStr=StrPtr(MyChars)
         For i = 0 to half
            s = pStr(i)
            pStr(i) = pStr(n-i)
            pStr(n-i) = s
         Next i
      End If
   End If
End Sub


But then again, I'm not sure that StrPtr is a valid call or that MS still does the stupid idiotic bit with strings being pointers to pointers to strings.

I also couldn't test this even if I really wanted to since my only copy of VB is in LA.

Your code is essentially what most VBers would probably do.
[User Picture]
From:boymaenad
Date:December 23rd, 2004 06:38 am (UTC)
(Link)
wow, I hadn't heard of StrPtr, nor does VB (behind Access) have help on it. the function still exists, but considering the lack of help, I think it's for backward-compatibility. or they don't want to talk about it. :)

I tried compiling the code - "Char" isn't a valid type, you probably mean String. also, the references to pStr(i) fail because pStr is a Long, not an array.

if I dim pStr as an array, then this line:

pStr = StrPtr(MyChars)


fails because StrPtr returns a Long. I see how the routine would work if StrPtr returned an array representing the string, but apparently it doesn't.

what would you do now? :)

here's what I did, and it works:

Sub Reverse(ByRef MyChars As Variant)
   If Not IsNull(MyChars) Then
      Dim n As Long
      n = Len(MyChars)
      If n > 0 Then
         Dim half As Long
         Dim i As Long
         Dim s As String
         half = n / 2
         
         For i = 0 To half - 1
            s = Mid(MyChars, i + 1, 1)
            Mid(MyChars, i + 1, 1) = Mid(MyChars, n - i, 1)
            Mid(MyChars, n - i, 1) = s
         Next i
      End If
   End If
End Sub


as to my code, I originally thought of dimming a second variable, but thought it was more fun to use the single variable. (plus I have a strange neat-freak motivation to use as few variables as possible.) then after posting, realized that if the string were more than half a string's maxlen, it would overflow.

I compared my original to this one by running ten thousand transformations with each and timing them (I have a routine that does that sort of thing :) ). yours, once corrected, was indeed about 30% faster than mine on average.

p.s. I hesitate to believe that most VBers would write code that actually worked perfectly off the tops of their heads, but I know what you mean :)
[User Picture]
From:boymaenad
Date:December 23rd, 2004 06:40 am (UTC)
(Link)
actually, the isnull test and the len > 0 test are redundant; here's cleaner:

Sub Reverse(ByRef MyChars As Variant)
    If Not IsNull(MyChars) Then
        Dim n As Long
        n = Len(MyChars)
        Dim half As Long
        Dim i As Long
        Dim s As String
        half = n / 2
        
        For i = 0 To half - 1
           s = Mid(MyChars, i + 1, 1)
           Mid(MyChars, i + 1, 1) = Mid(MyChars, n - i, 1)
           Mid(MyChars, n - i, 1) = s
        Next i
    End If
End Sub
[User Picture]
From:boymaenad
Date:December 23rd, 2004 06:53 am (UTC)
(Link)
...which leads me to wonder - does len in C return the number of characters minus one? if not, then I think your C code wouldn't work. not that it isn't brilliant :)
[User Picture]
From:testing4l
Date:December 24th, 2004 10:04 pm (UTC)
(Link)
strlen returns the number of characters before a \0 (null) character. So, strlen("abc") returns 3, even though that array is actually at least 4 chars in length (or, if it isn't, then we'll never know until the debugging phase because the program will die).

It will work. I tested it afterwards. I think I could actually write it faster using char*s, but that's probably only faster on an x86.
[User Picture]
From:testing4l
Date:December 24th, 2004 10:15 pm (UTC)
(Link)
Yeah, that's about right. Most of the savings in this case is that s probably never resizes. This is what I would've done if I didn't know about StrPtr. BTW, there's also VarPtr() and ObjPtr() IIRC.

In truth the difference is perhaps 5%. Mid() is a fairly well optimized function in VB.
[User Picture]
From:testing4l
Date:December 24th, 2004 10:12 pm (UTC)
(Link)
MS doesn't want to talk about it because that means you could do things the Right Way in VB and the whole point is to have structured, crippled code. If you google for it, you'll still find references.

It's amusing to me because real basic had peek and poke written into the language to make it useful. MS is trying to keep out the rough equivalents to make VB "useful".

I seemed to recall that there was a type in VB that would hold a single Char. It's possible I'm misremembering. My brain was telling me specifically not to use a String though for the aforementioned memory management reasons.

I don't fear using too many variables. Usually, the variables save you space that the code to eliminate those variables would normally take. relsqui had a great example with her most recent project where a lookup table saved her at least 15 lines of code.

Anyway, VB is totally the wrong language for this sort of fun ; )

> Go to Top
LiveJournal.com