15
\$\begingroup\$

I'm attempting to solve a programming golf style programming puzzle. I need to write an 18 character phrase in Chef in less than 32 "lines" of code. In this case, a line counts as an ingredient or an instruction.

The most straightforward way of doing this is to declare an ingredient for each character and put each ingredient into a baking dish. Unfortunately for what I'm trying to do, that takes too many "lines" of code. (I'm limited to 32 and I want to print a 18 character phrase. 18*2 + title + serves command + headers = 40).

Here are things I tried:

So I had the idea of just using large numbers that would span multiple unicode chars. But when I print it out, I get garbage. So then I had the idea to just stream my characters by reading off each byte of a large number at a time and popping them into a baking dish in a loop. Unfortunately, there doesn't seem to be a way to do with the operators I have (the basic four arithmetic operators). I tried taking a number, dividing by 256, multiplying by 256, and subtracting that from my original number to get the least significant byte, but then discovered that Chef uses floating point (that is the number doesn't change).

There are no logical operators. There's no comparison operators. Any idea on what I can try next to print out an 18 character phrase in less than 32 "lines" of code? (Putting commands on the same line doesn't help. It still counts the same).

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Outside the box: What interpreter are you using? I don't see anything in the spec that requires Chef to use floating point. If you write your own interpreter using integers... \$\endgroup\$
    – Geobits
    Oct 13 '14 at 18:00
  • 2
    \$\begingroup\$ I'm unsure why help solving a programming golf problem is considered off topic here. I would consider it off topic on StackOverflow. I'll edit it to make it clear I'm solving a programming puzzle. \$\endgroup\$ Oct 13 '14 at 18:16
  • \$\begingroup\$ The questions seems little legit. If you can modify it and turn it into a programming challenge with shortest code as scoring criteria and other rules, then it can be reopened. As of right now, it simply looks like you need help in doing some stuff, even though the question is nice. \$\endgroup\$
    – Optimizer
    Oct 13 '14 at 18:21
  • 5
    \$\begingroup\$ @Optimizer Not all questions need to be challenges. @ Jason It might help if you post the code you're currently trying to golf. What works for one string may not work for another (due to patterns or whatever). It also changes it from general advice to "I have this code that works correctly and I'm trying to golf it to X lines/characters", which may be received better. \$\endgroup\$
    – Geobits
    Oct 13 '14 at 18:27
  • 1
    \$\begingroup\$ There would have to be some kind of exploitable sequence in the characters. Within the "Chef" rules, I don't see it's feasible to encode an arbitrary string with more than one character per ingredient. \$\endgroup\$
    – COTO
    Oct 15 '14 at 8:24
1
\$\begingroup\$
Chef has no string types, so the ingredients are positive integers. 0 is used to separate the starting list from used ingredients and to end the used ingredients list.

A, B: stack
    T, J, IN: int
    T = 1
    A.push(0) // used as the marker for the bottom of the stack
    IN = input() // input the first list
    while(IN):
        A.push(IN)
        IN = input()
    IN = input() // for each used ingredient
    while(IN):
        B.push(0)
        while(T): // move all ingredients up to and including the one we are moving right now to the second stack
            T = A.peek() - IN
            B.push(A.pop())
        A.push(B.pop())
        if(A.peekUnderTop() != 0):
            A.swapTopTwoItems()
        T = B.pop() // move the ingredients from the second stack back to the first
        while(T):
            A.push(T)
            T = B.pop()
        T = IN // to make it non-zero for next iteration
        IN = input(0
    print(A.inverted())
\$\endgroup\$
1
  • \$\begingroup\$ I don't understand how this answer helps golf string output in Chef (and I also don't understand what does the code do) \$\endgroup\$ Jan 16 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.