Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Pizza Cost Optimization Dark Pattern Programming Example:

Here is the pizza cost optimizer from Pizzatool, written in object oriented NeWS PostScript, which checks all of the pre-defined base pizza styles and selects the "best" combination of style + extra toppings, ostensibly to save the user some money.

It's actually a dark pattern, because it's biased towards selecting higher level pizzas instead of the least expensive pizza. But at least the dark pattern is documented:

"Figure out the cost of the pizza, were we to order it as this style, and remember the style as the best match if it pleases us. The definition of pleasing us is biased towards matching higher level complex pizza styles, rather than economical lower level pizzas with extra toppings. This is the kick-back to Tony&Alba's for all that free beer."

The Story of Sun Microsystems PizzaTool How I accidentally ordered my first pizza over the internet:

https://medium.com/@donhopkins/the-story-of-sun-microsystems...

Tony and Alba's Pizza and Pasta, Mountain View:

https://www.yelp.com/biz/tony-and-albas-pizza-and-pasta-moun...

PizzaTool Source Code:

https://www.donhopkins.com/home/archive/NeWS/pizzatool.txt

    % Calculate the cost of this pizza.
    %
    /updatecost { % - => -
      10 dict begin % localdict
        /TheBest /defaultstyle ClassStyle send def
        /TheStyle null def
        /TheTopping null def
        /TheBestCost 99 def
        /TheBestExtras 0 def

        % For each and every pizza style in the universe:
        /styles ClassStyle send { % forall:               % style
          /TheStyle exch def                              %

          % Ask this style for its list of standard toppings.
          /TheToppings /toppings TheStyle send def

          % Is every topping from this style on our pizza?
          true                                            % true
          TheToppings { % forall:                         % true topping
            Toppings exch arraycontains? not { % if:      % true
              % Oops, this topping's not on the pizza. No dice.
              pop false exit                              % false
            } if                                          % true
          } forall                                        % true|false

          { % if: all the toppings of the style were on our pizza:
                                                          %
            % Make an array of our pizza toppings that aren't in the style.
            /ExtraToppings [
              Toppings {                                  % ... topping
                % Is this topping included in the style? Then toss it.
                TheToppings 1 index arraycontains? {      % ... topping
                  pop                                     % ...
                } if
              } forall
            ] store                                       %

            % Figure out the cost of the pizza,
            % were we to order it as this style,
            % and remember the style as the best match if it pleases us.
            % The definition of pleasing us is biased towards matching
            % higher level complex pizza styles, rather than economical
            % lower level pizzas with extra toppings.
            % This is the kick-back to Tony&Alba's for all that free beer. 
            PizzaSize /pizzasizeindex self send           % sizeindex
            ExtraToppings length                          % sizeindex extras
            /extraprice TheStyle send                     % $
            dup                                           % $ $
            ExtraToppings length                          % $ extras
            /extras TheStyle send sub                     % $ $ extras'
            1 le { .9 mul } if                            % $ biased$
            TheBestCost le { % ifelse:                    % $
              % Hey this is the best match so far, let's not forget it!
              /TheBestCost exch store                     %
              /TheBest TheStyle store
              /TheBestExtras
                ExtraToppings length /extras TheBest send sub
              store
            } { pop } ifelse                              %
          } if                                            %
        } forall                                          %

        % Set the window footers of the pizza topping panel.
        % The left footer displays the name of the pizza style,
        % and the right footer displays a message
        % telling the user to choose more toppings,
        % or the number of extra toppings,
        % or nothing at all.
        TheBestExtras dup 0 lt { % ifelse:                % extras
          neg dup 1 eq { () } { (s) } ifelse              % extras (plural?)
          exch (Choose % more topping%!) sprintf          % (message)
        } { % else:                                       % extras
          dup 0 ne { % ifelse:
            dup 1 eq { () } { (s) } ifelse                % extras (plural?)
            exch (With % extra topping%.) sprintf         % (message)
          } { % else:                                     % extras
            pop nullstring                                % ()
          } ifelse
        } ifelse                                          % (left footer)
        /name TheBest send exch                           % (left) (right)
        /setfooter ToppingWindow send                     %

        % Remember the price of this pizza in dollars rounded to cents,
        % and calculate its string value. 
        TheBestCost                                       % $
        Fraction mul
        100 mul round 100 div
        /Price 1 index store
        dup 100 mul round cvi 100 mod                     % $ cents
        exch floor cvi                                    % cents dollars
        1 index 10 lt { (%.0%) } { (%.%) } ifelse         % cents dollars fmt
        sprintf                                           % (price)

        % Set the value of the costfield and totalfield labels to
        % the price string.
        dup /setvalue costfield send
        /setvalue totalfield send                         %

        % Set the value of the stylevalue label to the name of the best style,
        % and set the stylemenu value to the index of that name in the list of
        % pizza styles. (The stylemenu is an exclusive settings menu.)
        /name TheBest send                                % name
        dup /setvalue stylevalue send
        PizzaStyleNames exch arrayindex {                 % index
            [exch] /setvalue stylemenu send               %
        } if                                              %

        % Remember the best match pizza style.
        /Style TheBest store

      end % localdict
    } def


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: