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

Banana programming challenge: Utilitarianism

Name: Adam 2013-01-19 23:31

Hello everyone. My name is Adam. For as long as I can remember, my sister and I have loved eating bananas. We do not share the same banana eating habbits however. I typically like eating the bananas earlier, when they are more green. My sister likes to eat the bananas later. You might think to yourself that we have ourselves a nice setup. I can buy a bunch of bananas and we can share, me eating the bananas earlier ones and her eating the later ones. But it turns out to be not so simple.

Suppose that the value I get from eating a banana can be given by ceil(.22*d^3-2.7*d^2+7.7*d+3.8) for integer values of d between 0 and 6 inclusive and d represents the number of days passed since purchasing the bananas. Also suppose that the value my sister gets from eating a banana is given by a graph that is symmetrical to mine about 3. As far as the cost of the bananas, the value of a dollar is worth 5 units of value to us.

On days that a banana is not eaten either of us, our little brother takes one for himself. This is to be avoided as he does not contribute money towards the bananas.

Maximize the combined value my sister and I can get from a bunch of bananas using the number of bananas bought and when they are eaten as variables. Bananas can only be bought at most one bunch per week and at most each person can eat one banana in a given day. The number of bananas consumed by my sister and I cannot differ by more than 1 for a given week. Bananas are sold in bunches of between 6-8 inclusive. Assume each banana weighs the same (.48 lb) and cost $1.42/lb.

Name: Anonymous 2013-01-21 0:48

>>38
You're indexing from 0, so on day 0 no one eats a banana meaning that the brother steals one.

This problem can't be done in LISP.

Name: Anonymous 2013-01-21 0:49

>>41
Intended for >>39

Name: Anonymous 2013-01-21 0:54

>>41 lol just start from 1?

[three days] should have been  (5*4/2 * 3^2) + (4 * 3) + 1

Name: Anonymous 2013-01-21 0:58

>>43
What do you mean just start indexing from 1?

Then you're not taking the maximum values from the graph. How are you sure that your is the optimal solution anymore?

Name: Anonymous 2013-01-21 1:10

>>44
That is not me.

Value of a banana: (* 5 (* 1.42 .48)) -> 3.408
Value of you eating a banana on the first day: 4.0
If you don't eat a banana on the first day your brother eats one, so effectively the value of eating a banana on the first day is 7.408, which is larger than six.

This idea became a bit convoluted because I completely forgot about the brother, but it seems I got lucky and it still works.
{0 1 2 3} and {2 3 4 5} or {0 1 2 3 4} and {3 4 5}

Name: Anonymous 2013-01-21 1:37

>>45
, so effectively the value of eating a banana on the first day is 7.40
This logic is flawed. The value of eating a banana on day one is still 4.

The idea behind the problem is to actually program a solution. Not look at the graph and guess what seems right.

Name: Anonymous 2013-01-21 2:01

>>46
I'm not guessing, and the logic isn't flawed. Quick bruteforcer agrees with me:


(define (c d) (ceiling (+ (* .22 (* d d d)) (* -2.7 (* d d)) (* 7.7 d) 3.8)))
(define me-values (map c (range 7)))
(define sister-values (reverse me-values))
(define banana-value (* 5 1.42 .48))

(define (max b . bs)
  (define (maxh b bs)
    (if (null? bs) b (maxh (if (< (cdr b) (cdar bs)) (car bs) b) (cdr bs))))
  (maxh b bs))

(define (eat who trace day)
  (cond ((eq? who 'M) (cons (cons 'M (car trace)) (+ (list-ref me-values day) (cdr trace))))
        ((eq? who 'S) (cons (cons 'S (car trace)) (+ (list-ref sister-values day) (cdr trace))))
        ((eq? who 'MS) (cons (cons 'MS (car trace)) (+ (list-ref me-values day) (list-ref sister-values day) (cdr trace))))
        ((eq? who 'B) (cons (cons 'B (car trace)) (cdr trace)))))

(define (recban trace day bananas)
  (if (= day 7) trace
      (cond ((= bananas 0) trace)
            ((= bananas 1) (max (eat 'M trace day)
                                (eat 'S trace day)
                                (eat 'B trace day)))
            (else (max (recban (eat 'M trace day) (+ day 1) (- bananas 1))
                       (recban (eat 'S trace day) (+ day 1) (- bananas 1))
                       (recban (eat 'B trace day) (+ day 1) (- bananas 1))
                       (recban (eat 'MS trace day) (+ day 1) (- bananas 2)))))))

(define (bananas banana-count)
  (let ((ans (recban '(null . 0) 0 banana-count)))
    (cons (car ans) (- (cdr ans) (* banana-count banana-value)))))


> (list bananas (range 6 9))
'(((S S M M M M . null) . 34.552)
 ((S S MS M M M . null) . 40.144000000000005)
 ((S MS MS M M M . null) . 42.736000000000004))

Name: Anonymous 2013-01-21 2:05

>>47
Cleaner:

[code]
(define (bananas banana-count)
  (let ((ans (recban (cons '() 0) 0 banana-count)))
    (cons (reverse (car ans)) (- (cdr ans) (* banana-count banana-value)))))

(map bananas (range 6 9))
'(((M M M M S S) . 34.552)
  ((M M M MS S S) . 40.144000000000005)
  ((M M M MS MS S) . 42.736000000000004))

Name: Over Bananas Thread 2013-01-21 2:55

This thread has too many instances of the word banana.
You can't reply anymore.

Name: Anonymous 2013-01-21 2:59

unless you use the word banana? ^^

Name: Anonymous 2013-01-21 4:13

And after all that, i looked back at the problem and saw that last line
>The number of bananas consumed by my sister and I cannot differ by more than 1 for a given week.
ugh, i bet that would make the math ugly (program not so much)
banana

Name: Anonymous 2013-01-21 7:17

>>51
No, that shrinks the problem domain dramatically. Now you only have to check a linear number of bananas, rather than every partition of size 2 of the number of bananas.

Name: Anonymous 2013-01-21 22:09

>>52
Doesn't mean it won't make the code looks worse.

Name: Anonymous 2013-01-22 4:06

>>53
that would make the math ugly (program not so much)
Take less drugs, kids

Name: Anonymous 2013-01-22 6:22

>>54 no u, see >>32,33,35,43
but really, trimming a few combinations off doesn't really seem too bad, just need to check -1<=x-y<=1 on each possible combo for validation...

Name: Anonymous 2013-01-22 6:30

actually, as a program, i would probably just go base 4, then trim everything....

Name: Anonymous 2013-01-22 8:03

/ branches get pruned // leaves get trimmed /? ^^ running over 65536 leaf nodes In Parallel !

http://soundcloud.com/hugoletras/roots-manuva_witness-the-fitness xD

Name: Anonymous 2013-01-22 8:15

Name: Anonymous 2013-01-22 10:13

>>57
"I summon up the power of banana clan!" xD

Name: Anonymous 2013-01-22 20:40

bump

Name: Anonymous 2013-01-22 20:48

Swiggin that hebrew juice
Now we deh 'pon it boost
Set dem spirit dem loose ^^

Name: Anonymous 2013-01-22 22:00

>>57-61
What the fuck is the point of this, fagshit?

Name: Anonymous 2013-01-22 22:10

Well well well [x3], Taskmaster burst, The bionic zit splitter, Breakneck speed, we drown ten pints of bitter, we lean all day, and some say that ain't productive, but that depends upon the demon that you're stuck with, 'cos right now
I see clearer than most, I sit here contented with this cheese on toast, I feel the pain of a third world famine, Segue, we count them blessings and keep jamming, 'tis him, scumbag, scum of the earth, his worth was nil, until he gained the skill of tongues, from 15 years young straight to my grey back self, I stay top shelf material, Jerk chicken, jerk fish, Break away slave bliss, Generate G's and then we stash them in the Swiss, Fools can't see this, Audio pistols, a fistful of hip hop donzai
Progressin' in the flesh, Esoteric quotes most frightening, Duppy took hold of my hand while I was writing, Let go me ting Duppy, Let go me hand, I summon up the power of banana clan...

Name: Anonymous 2013-01-22 22:42

>>63
What the fuck is the point of this, fagshit?

Name: Anonymous 2013-01-22 23:42

>>64
The point is to have you get laid, so we don't have to deal with your anger issues here.

Name: Anonymous 2013-01-23 0:20

part #1 ( -the generator- ^^ )

b_base = 4;

b_power = [1:7];

for (iter = b_power)

  b_long(iter) = b_base .^ b_power(iter);

  endfor;

b_mat(1:b_long(7),1:b_power(7)) = 0;

i_vec = [1:b_base];

j_vec = i_vec( ones(1,b_long(6)),: );

b_mat(:,1) = j_vec(:);

for(iter = b_power(1:6))

  s_mat = [];

  s_mat(1:b_long(iter), 1:b_long(7 - iter)) = 0;

  s_mat(:) = j_vec(:);

  s_mat2 = s_mat';

  b_mat(:,iter+1) = s_mat2(:);

  size(s_mat)

  endfor;

b_mat

Name: Anonymous 2013-01-23 3:50

...kind of lazy today, so just the first condition for the banana's thread...
selector = sum((b_mat > 1) .+ (b_mat == 4), 2) < 9;
Not bad, eh? eh? =D /reposted here for anti-thread-spaghettitation purposes.. ^^

Name: Anonymous 2013-01-27 1:54

Who is this faggot that keeps using this "^^" emoticon or whatever the fuck it is?

Name: Anonymous 2013-01-27 2:21

>>68
Dunno. I personally use only =) and ^_^

Name: Anonymous 2013-01-27 22:00

>>69
Go back to gaia.

Name: Anonymous 2013-01-27 22:03

>>66
What in the buttfucking Jesus am I reading?
for(iter = b_power)?

>>68
That ``hehe =)'' guy. I think he's actually retarded, in a very literal sense.

Name: Anonymous 2013-01-27 22:27

it's an octave/matlab thing.. ^^ loops are based on vectors..

Name: Anonymous 2013-01-27 22:30

>>68
See how >>72 doesn't even seem to care? Maybe his mom dropped him when he was little.

Name: Anonymous 2013-01-27 22:49

>>73 what are you yapping about?

Name: Anonymous 2013-01-28 0:26

>>66
You wrote this code like shit. Get better

>>71
That ``hehe =)'' guy
I think that's the same dude that wrote the Lisp code above.

Name: Anonymous 2013-01-28 0:38

it's a draft version ^^ the power is not in the tidiness of the code.. it's in the flexibility xD it can handle whatever new rules are thrown at it, just by adding a few more 'conditions', rather than rewriting the generator each time..

Name: Anonymous 2013-01-28 4:18

>>76
Fuck off with your emoticons you insufferable little twat.

Name: Anonymous 2013-01-28 5:36

it can handle whatever new rules are thrown at it, just by adding a few more 'conditions'
it's flexible in that you have to change the code when you want it to do something else
my FUCKING FACE

Name: Anonymous 2013-01-28 6:00

ah you made me laugh ^^
what kind of magical codes do you use then?

Name: Anonymous 2013-01-28 9:50

>>75
the same dude that wrote the Lisp code above.
He's way too fucking dumb for that.

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