Results 1 to 5 of 5

Thread: Technical puzzle

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Thumbs up Technical puzzle

    Your application has a object named Company, which has properties as Name, Address & Code. Also, you have an object named Companies containing list (array) of Company. Can you write a code to print out all the properties of all the Company object in the Companies object, separated by *#* string as shown below.

    Company1Name*#*Company1Address*#*Company1Code*#* Company2Name*#*Company2Address*#*Company2Code….. *#* Company100Name*#*Company100Address*#*Company100Code

    Think of a solution without any loop (for or while) and leverage your language’s feature.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Technical puzzle

    Without a for or while does that mean I should use a GoTo

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Technical puzzle

    which language is this in?

    That said, it's a jacked exercise, contrived with no real-world application what so ever (especially if the answer is using a goto, which I don't think it is)...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Technical puzzle

    I was joking about the Goto but it would work.

  5. #5
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: Technical puzzle

    using F# I would use List.Iter and a simple lambda.
    Code:
    type company = {name : string; adress : string; code : int}
    let companies = [{name = "abc";adress = "123";code = 1};{name = "dfg";adress = "456";code = 2}]
    companies |> List.iter (fun x -> printfn "%s*#*%s*#*%d" x.name x.adress x.code )

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width