How to golf string output in Chef

13

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).

Jason Thompson

Posted 2014-10-13T17:40:29.397

Reputation: 239

1Outside 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... – Geobits – 2014-10-13T18:00:33.233

1I'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. – Jason Thompson – 2014-10-13T18:16:12.567

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. – Optimizer – 2014-10-13T18:21:33.210

3@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. – Geobits – 2014-10-13T18:27:42.797

Ah... Okay, @Optimizer. I guess I misinterpreted the part of the help area that said, "Non-challenge questions that are are related to solving programming puzzles or a particular type of challenge are also on topic." Perhaps that's another challenge for me to figure out. ;) I'll reword it. – Jason Thompson – 2014-10-13T18:28:18.617

Right now it seems there's a fine line between "non-challenge" and "general programming" questions that is hard to navigate. Hopefully we'll have clearer rules in the future. – Geobits – 2014-10-13T18:29:41.517

I'll take @Geobits advice and post some code examples. If you guys wouldn't mind, please don't outright delete this question until I get a chance to go home and link to some of my attempts. – Jason Thompson – 2014-10-13T18:30:27.743

1There 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. – COTO – 2014-10-15T08:24:45.587

If Chef had a way of extracting a byte from a multibyte num then one could encode an arbitrary string easily. One could use a loop to extract each byte. Unfortunately, there is no AND operator and the numbers (at least in the Perl interpreter) are floats.

One other thing that may have worked, but didn't is that it looks like arithmetic operations in Chef cause the answer to be pushed on top of the operand already in the stack. (that is peek, add, push), but the Perl interpreter does pop, add, push. – Jason Thompson – 2014-10-15T21:08:05.450

Can you post the 18 character that you want to write? Or do you want a method that will work for any 18 character string? – justhalf – 2014-10-16T08:37:33.347

The competition is over, but it would still be interesting to learn what the solution could have been. Ultimately, I wanted to print "Engineering Health" on the screen. Here's a link to the gist that has my submission to the competition. https://gist.github.com/CernerJT/80198257abc36cc4c3b3

What I did to solve it was to not care about capitalization and to remove the space. I thought it would be much more amazing to have been able to write a program that could take any arbitrary string and print it out.

– Jason Thompson – 2014-10-16T13:23:03.837

No answers