Solutions to the 2nd gambling puzzle

destraynor


Trackbacks

Steve the Gambler - Caught by the IRS
Time for another programming puzzle, this was given to a friend in an interview for a mobile phone operator. Apparently it maps neatly on to some problem that must regularly be solved in mobile phone networks, but seeing as said friend didn't get the job,
Weblog: destraynor
Tracked: Dec 05, 20:52

Comments
Display comments as (Linear | Threaded)

Can I/we see Jeremy Weissmann's elegant solution he mentioned? Pleeeeease? :-)
#1 elfz on 2006-11-13 04:08 (Reply)
The solution by Andrew is not haskell but Erlang. Additionally, the version by Cale will not work as it is put on your page. I am certain he did not intend to have it appear this way, but leading whitespace is important for Haskell.
#2 vincenz (Homepage) on 2006-11-13 07:58 (Reply)
The ruby solution is incorrect. I would guess that an editor tried to 'clean it up' and broke the code.
#3 Rick on 2006-11-13 10:22 (Reply)
I was going by what was entered in the comment box. If anyone wants to mail me a corrected version I'll post it here.
#4 Des Traynor (Homepage) on 2006-11-13 10:28 (Reply)
Here is a Lisp solution using tail recursion:

(defun maximize (future &optional (sum 0))
(cond ((null future) sum)
((null (cdr future))
(if (< (car future) 0) sum (+ sum (car future))))
((let ((v (if (< (car future) 0) 0 (car future))))
(if (> (maximize (cdr future) sum) (+ v (maximize (cddr future) sum)))
(+ sum (maximize (cdr future) sum))
(+ sum v (maximize (cddr future) sum)))))))
(print (maximize '(158 44 196 399 47 2 -158 -197 375 121 806 44 953 7 20 1 7 88 191 33 654 156 321 784 -111 159 88 49 25 366 861 869 380.)))
#5 Jeff Cunningham on 2006-11-13 15:48 (Reply)

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications
You can use [geshi lang=LANG][/lang] tags to embed source code snippets
 
 

About:

Switch to Dark on Light!
Pic of Me.

This website is the online diary of me, Des Traynor, a User Experience Researcher in Dublin, Ireland. I work with Contrast.

I usually write on 5 topics:

I update about 3-4 times per month. Be sure to subscribe so you don't miss this good stuff. If this is your first time here, check out the archives.


My official homepage provides more information about who I am, and what I research. You can contact me at destraynor [at] gmail [dot] com

Shower doors Ireland, Bathrooms, Shower Enclosures, Bathroom Suites, showers, beds, mattresses, online bed store, king size, queen, duvet, bedroom furniture bathroom furniture, sinks, suites, toilets, taps, and basins online

RSS Feed

Quicksearch