• firu (unregistered)

    I'm sorry, i forgot that Gray code may be better for the state encoding, please accept my corrected version and consider changing the original also to use gray code. This will reduce some of the power consumed by switching less bits.

    module wtf(clk, rst, c); output [7:0] c; reg [7:0] c; input clk; input rst; reg [1:0] s;

    always @ (posedge clk or posedge rst) begin if (rst) c[7:0] <= 8'b0; else case (s[1:0]) 2'b00 : c[7:0] <= 8'd87; // 'W' 2'b01 : c[7:0] <= 8'd84; // 'T'; 2'b11 : c[7:0] <= 8'd70; // 'F'; 2'b10 : c[7:0] <= 8'd33; // '!'; endcase end

    always @ (posedge clk or posedge rst) begin if (rst) s[1:0] <= 2'b0; else s[1:0] <= {s[0], ~s[1]}; end

    endmodule

  • a right tool (unregistered) in reply to Right tool for the right job
    Right tool for the right job:
    I use for loops for everything! I use for loops for everything! I use for loops for everything! I use for loops for everything!
    Even when wan is enough?
  • a right tool (unregistered) in reply to m0ffx
    m0ffx:
    Yeah, the verb 'can' is a bit weird. And English spelling is very oddball.

    But there's an awful lot that's SIMPLE about English.

    • Few tenses (compared to some languages).
    • Only one (modern) form of 'you'.
    • The only noun-verb agreement is singular vs plural. There's no need for noun-adjective agreement.
    • No 'gender' for inanimate objects.
    • Monosyllabic words are enough for normal, everyday life
    • No one can write it correctly
  • Maj najm (unregistered) in reply to campkev
    campkev:
    pscs:
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.

    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).

    While I agree with you that the rule is almost useless, some of your examples are kind of WTF themselves. The rule is only meant for situations where the i and the e make a single sound. In science, society, deity and seeing, the i and the e are part of different syllables. Also, eider is Swedish, so you can hardly expect an English grammar rule to apply.

    eider is swedish? Sure dont look like it and I cant remember seeing it. Ejder otoh is a swedish word. ;)

  • Azd (unregistered)

    My first code review comment for this would be:

    Case 4 is inconsistant, all the other cases append only one character, where as this appends 2. Please seperate into 2 cases.

    Andy

  • Trainee Programmer (unregistered) in reply to Smash King
    Smash King:
    And if anyone suppose that the right way to handle a phone validation is a state machine, go back to Programming Logic 101 right away.
    What's wrong with using a state machine to validate a phone number?
  • needless complexity (unregistered) in reply to pscs

    [quote user="pscs"][quote user="ContraCorners"] No, someone came up with "I could have gone", it just isn't right.[/quote] I have gone.[/quote]

    That's not right either.

    I could have gone might be past tense or might be conditional. So it might have been right. I might have gone is also possibly conditional.

    "I was able to go" is right, also "I had been able to go". You have to convert the modal verb 'can' to the 'to be able to' form. You have difficulty converting modal verbs (verbs which change the 'mode' of another verb) to past tense.

    [/quote]

    "I could go" is a perfectly valid past tense of "I can go".

    Today, I can go to the store. Three years ago, I could go to the store.

    Or to do it your way:

    Today, I am able to go to the store. Three years ago, I was able to go to the store.

    They both mean the same thing, and they are both perfectly correct.

  • (cs) in reply to needless complexity

    [quote user="needless complexity"][quote user="pscs"][quote user="ContraCorners"] No, someone came up with "I could have gone", it just isn't right.[/quote] I have gone.[/quote]

    That's not right either.

    I could have gone might be past tense or might be conditional. So it might have been right. I might have gone is also possibly conditional.

    "I was able to go" is right, also "I had been able to go". You have to convert the modal verb 'can' to the 'to be able to' form. You have difficulty converting modal verbs (verbs which change the 'mode' of another verb) to past tense.

    [/quote]

    "I could go" is a perfectly valid past tense of "I can go".

    Today, I can go to the store. Three years ago, I could go to the store.

    Or to do it your way:

    Today, I am able to go to the store. Three years ago, I was able to go to the store.

    They both mean the same thing, and they are both perfectly correct.[/quote]

    It looks like I was wrong and that "I could go" is correct, but I've almost always heard it used in a way that implies that you are no longer able to.

    Which just adds more support to my supposition on the difficulty of English.

  • (cs) in reply to campkev
    campkev:

    It looks like I was wrong and that "I could go" is correct, but I've almost always heard it used in a way that implies that you are no longer able to.

    Which just adds more support to my supposition on the difficulty of English.

    At some point last night I realized I had forgotten how the hell this "I could go"/"I could have gone" debate started, and at that point I realized I needed to stop thinking about it and go kill some zombies. Left 4 Dead FTW!

  • icywindow (unregistered)

    Well, since everyone else is doing it, Ruby!

    cleanNumber.each do { |n| formattedNumber.push(n) } formattedNumber.insert(0,"(").insert(-5,"-").insert(4,")").join

  • arkal (unregistered) in reply to SenTree

    You're my friend!

  • BBT (unregistered) in reply to campkev
    campkev:
    A Nonny Mouse:
    "i could have gone" and "i was able to go" mean exactly the same thing

    Really? Would you ever say "I could have gone" about something you actually went to?

    No. But i wouldn't say 'i was able to go' either. I'd say I WENT, for fuck's sake. Either way of phrasing it implies that you'll follow with 'but I didn't', and sounds dumb if you don't.

  • (cs) in reply to David
    David:
    the main work to consult in this matter is Dr. Dan Streetmentioner's Time Traveler's Handbook of 1001 Tense Formations. It will tell you, for instance, how to describe something that was about to happen to you in the past before you avoided it by time-jumping forward two days in order to avoid it.
    John Stein:
    A niche in time saves Stein.
    (With apologies to Isaac Asimov)
  • Botia (unregistered)

    LOL, that's what it's all about! It truly makes you say WTF.

  • (cs) in reply to BBT
    BBT:
    campkev:
    A Nonny Mouse:
    "i could have gone" and "i was able to go" mean exactly the same thing

    Really? Would you ever say "I could have gone" about something you actually went to?

    No. But i wouldn't say 'i was able to go' either. I'd say I WENT, for fuck's sake. Either way of phrasing it implies that you'll follow with 'but I didn't', and sounds dumb if you don't.

    ??? "Hey, did you make it to the concert Friday?" "Yeah, my boss let me off early, so I was able to go."

  • (Visitor) (unregistered)

    phone "" 0 = "" phone s n = case n of { 12 -> "(" ++ phone s 11; 11 -> head s : phone (tail s) 10; 10 -> head s : phone (tail s) 9; 9 -> head s : phone (tail s) 8; 8 -> ") " ++ phone s 7; 7 -> head s : phone (tail s) 6; 6 -> head s : phone (tail s) 5; 5 -> head s : phone (tail s) 4; 4 -> "-" ++ phone s 3; 3 -> head s : phone (tail s) 2; 2 -> head s : phone (tail s) 1; 1 -> head s : phone (tail s) 0; _ -> ""}

  • BeSchT (unregistered) in reply to Maj najm
    Maj najm:
    eider is swedish? Sure dont look like it and I cant remember seeing it. Ejder otoh is a swedish word. ;)
    Is it? "Ejder zi lesn dem daily WTF solstu beser szrajbn programe!" Doesn't look swedish to me...
  • Lazy (unregistered) in reply to ContraCorners
    ContraCorners:
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!
    My guess would be something like this...

    Public Function StripNonNumericCharacters(ByVal sOrginalPhoneNumber as String) as String

    DIM sCleanPhoneNumber
    
    sCleanPhoneNumber = Replace(sOrginalPhoneNumber,"A","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"B","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"C","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"D","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"E","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"F","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"G","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"H","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"I","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"J","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"K","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"L","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"M","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"N","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"O","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"P","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Q","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"R","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"S","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"T","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"U","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"V","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"W","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"X","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Y","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Z","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"a","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"b","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"c","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"d","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"e","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"f","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"g","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"h","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"i","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"j","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"k","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"l","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"m","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"n","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"o","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"p","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"q","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"r","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"s","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"t","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"u","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"v","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"w","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"x","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"y","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"z","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"`","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"~","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"!","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"@","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"#","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"$","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"%","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"^","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"&","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"*","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"(","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,")","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"_","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"-","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"+","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"=[","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"]","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"\","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"{","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"}","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"|","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,";","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,";","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"""","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"'","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,",.","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"/","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"<","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,">","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"?","")
    
    return sCleanPhoneNumber
    

    End Function

    I find this type of code in our legacy system on a daily basis :-(

  • Lazy (unregistered)

    Oh, and...

    The past simple tense of "I can go" is "I could go." "I could have gone" is past perfect.

    Don't confuse syntax with semantics here. "I could go" can be interpreted as past indicative (I was able to do it yesterday, but now I can't) or second conditional (I could do it now, if i wanted to.) In both cases, the tense of the modal verb is the same.

  • Keybounce (unregistered) in reply to Tempura
    Tempura:
    Bah, ugly!

    print ''.join(['W', 'T', 'F', '!'][i] for i in xrange(4))

    Might be a little out of practice (15 years), but I think this works:

    out(['W' | [ 'T' | [ 'F' | [ '?' | [] ] ] ] ] );

    P.s. Did I really read all of those comments and language discussions?

  • (cs)
    Public Shared Function BuildComment() As String
            Dim oldComment As String
            Dim builtComment As New System.Text.StringBuilder
            oldComment = "me and this"
    
                For i = 0 To 14
    
                    Select Case i
                        Case 0
                            builtComment.Append(oldComment.Chars(7))
                        Case 1
                            builtComment.Append(oldComment.Chars(8))
                        Case 2
                            builtComment.Append(oldComment.Chars(9))
                        Case 3
                            builtComment.Append(oldComment.Chars(10))
                        Case 4
                            builtComment.Append(oldComment.Chars(6))
                        Case 5
                            builtComment.Append(oldComment.Chars(9))
                        Case 6
                            builtComment.Append(oldComment.Chars(10))
                        Case 7
                            builtComment.Append(oldComment.Chars(2))
                        Case 8
                            builtComment.Append(oldComment.Chars(0))
                        Case 9
                            builtComment.Append(oldComment.Chars(3))
                        Case 10
                            builtComment.Append(oldComment.Chars(5))
                        Case 11
                            builtComment.Append(oldComment.Chars(4)) 
                        Case 12
                            builtComment.Append(oldComment.Chars(1))
                        Case 13
                            builtComment.Append(oldComment.Chars(10))
                        Case 14
                            builtComment.Append(oldComment.Chars(10))
    
                    End Select
    
                Next
    
                Return builtComment.ToString
    
            End If
    
        End Function
    
  • oheso (unregistered) in reply to Kermos
    Kermos:
    I swear, the next person that looks at me all wide eyed when they find out I study Japanese and asks me, in English nonetheless, "Isn't that too difficult?" is gonna be beaten senseless with a rubber chicken.

    muzukashii sugiru ja nai no?

  • oheso (unregistered) in reply to oheso

    8-'

  • oheso (unregistered) in reply to Code Dependent
    Code Dependent:
    ... until he finally had his fill of it, and rose up to his full height of about 6'5" and said, "Why, you young punk, I used to put away three like you before breakfast."

    Clearly meaning, "...and I still can."

    Au contraire. It makes no representation whether he is currently able to or not. (I'm speaking only of the language now, and not of whatever facial expressions or mannerisms the actor was employing as I only vaguely remember that episode.)

    Furthermore, it is different from the example, which would be "I used to be able to put away three like you before breakfast." Clearly meaning that he no longer can.

  • VB 101 (unregistered) in reply to dpm
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    Either that's sarcasm or I'm reading something different to you because only the length = 0 is checked.
  • Teh name!! (unregistered) in reply to BeSchT
    BeSchT:
    Maj najm:
    eider is swedish? Sure dont look like it and I cant remember seeing it. Ejder otoh is a swedish word. ;)
    Is it? "Ejder zi lesn dem daily WTF solstu beser szrajbn programe!" Doesn't look swedish to me...

    Well, if its a bird, then Im pretty sure its a swedish word. Otherwise, you've got another word that is spelled the exact same way. ;) And the fact that you also have a word spelled the exact same way doesnt really prevent the existance of a word with a completely different meaning being spelled the same way in a completely different language.

    And I just pointed out that eider is not a swedish word. The only correct use I can find of that spelling in swedish is the name of a german river. And I bet that its spelled the same way in german, so thus, its not swedish at all. ;)

  • drobnox (unregistered)

    Common Lisp

    (loop for i from 0 to 2
            do (cond
                ((eq i 0)
                 (format t "W"))
                ((eq i 1)
                 (format t "T"))
                ((eq i 2)
                 (format t "F"))))
  • Aaron (unregistered)

    I'm not a computer programmer. I'm a controls engineer and I program in ladder logic. Sometimes I write crummy VB macros to do simple tasks for me.

    I don't usually get much out of the code snippets posted here because they tend to go over my head. This one made me chuckle!

  • J (unregistered)

    I'd hate to see what this does with an international phone number.

  • (cs) in reply to Trainee Programmer
    Smash King:
    And if anyone suppose that the right way to handle a phone validation is a state machine, go back to Programming Logic 101 right away.

    Right! The real way to validate a string is of course a Regex.

    Wait a minute...

  • Wyrd (unregistered) in reply to firu

    Ok, this is really horrible code, but at least you can read it and figure out what it's supposed to do.

    Also, it looks to me like it will actually achieve the correct result. If so, then it's on par with bubble sort--except that bubble sort is obvious and wtf is only obvious if you're in the middle of stroke.

    -- Furry cows moo and decompress.

  • Offf (unregistered) in reply to Wyrd

    I read the code. I burst in tears. Literally.

  • (cs)

    I want to see a haskell implementation

  • Iago (unregistered) in reply to Kermos
    Kermos:
    Easy in Japanese though. :)

    行く - iku- go 行った - itta - went

    The amusing thing is that this is an irregular verb in Japanese. If it had been a regular verb, the past tense would have been 行いた *iita.

    oheso:
    muzukashii sugiru ja nai no?
    「難しいすぎる」って日本語になるか。「難しすぎる」だろ、普通。
  • Obsidian (unregistered)

    It's probably the work of an average programmer that was not used with Visual Basic. Guessing functions like MID$ and such from the first time is not obvious. However, "for" and "case" are written this way in many different languages. With the help of the auto-completion, this could explain a weird choice.

  • derp (unregistered)

    Someone indulge a newbie and explain exactly what's wrong and what the better alternative is.

    Please?

    As far as I see, it loops through each position and assigns appends the character relating to that position. What's wrong with a for case loop?

  • you're missing the point (unregistered) in reply to JimmyVile

    if its a fixed length state machine, why even run it in a loop at all? he could just code all 12 statements sequentially with no for and no select case.

  • derp (unregistered) in reply to you're missing the point

    I think I misunderstood it.

    The case statement and for loop could just be removed and it would execute just the same, yes?

    I was thinking of where the condition for the case was dynamic, rather than just going 1, 2, 3

  • TadGhostal (unregistered) in reply to Vollhorst

    Except there's no fall-thru in vb

    Vollhorst:
                For i = 0 To 12
    
                Select Case i
                    Case 0
                    Case 1
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(1))
                    Case 2
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(2))
                    Case 3
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(3))
                    Case 4
                    Case 5
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(5))
                    Case 6
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(6))
                    Case 7
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(7))
                    Case 8
                    Case 9
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(9))
                    Case 10
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(10))
                    Case 11
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(11))
                    Case 12
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(12))
    
                End Select
    
            Next
    
    Obvious, isn't it?
  • C (unregistered)

    I think this is simply supposed to be the "set next statement" in a crude IDE that offers only variable value watching and changing...

  • MF (unregistered) in reply to pscs
    pscs:
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.

    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).

    i get your point. but i don't think i would ever spell 'seeing' as 'seieing' or would that be 'sieeing'. no wait 'siieeng'...

Leave a comment on “Formatting a Phone Number - The Long Version”

Log In or post as a guest

Replying to comment #:

« Return to Article