Haskell, 16 111 + 57 = 168 bytes
import Data.String
instance IsString[Int]where fromString=map((-48+).fromEnum)
f::[Int]->Int
f=foldl1((+).(2*))
+57 bytes for the compile flags -XOverloadedStrings, -XOverlappingInstances and -XFlexibleInstances.
The challenge has some cumbersome IO format, be...
This answer originally tried to go with the idea that you could input a list of integers, and claims that not being able to do so was cumbersome IO
I'm conflicted on the idea that one should be able to take an array of characters as a reasonable substitution for a string.
@Geobits I think I used that in programming class to pass an int into a method, modify it inside of the method, and retain the value without returning it
@Lembik Because he just keeps getting smarter and smarter until (spoilers) he turns into pure energy inhabiting the world's computer and communications infrastructure.
Yes, but String is literally just a wrapper for a char[] with some useful methods (and made immutable). Saying we can use the wrapper for a thing but not the thing is just the same as saying we can't use int, but must use Integer instead.
What are we talking about? Seems like Xanderhall is trying hard to reinforce that char[] and String are not the exact same thing, but I have no idea why.
What general tips do you have for golfing in JavaScript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to JavaScript (e.g. "remove comments" is not an answer).
Note: Also see Tips for Golfing in ECMAScript 6
@Lembik Much much better than it used to be, but obviously is and will be slower than C. You can pretty often reach very reasonable performance however, so it's not really a problem for most things.
@seequ thanks but I want to see how much the performance of the JVM has improved relative to the performance of gcc, say . Looks like no one has done this
@Poke @Geobits On an unrelated note, don't suppose either of you has any links to a discussion on imports? I've been trying to hunt through, but it mostly seems like everyone just says "Yes, imports count towards your byte count" with no reference to any consensus.
The most commonly linked post regarding imports seems to be meta.codegolf.stackexchange.com/questions/8287/… , but even that one simply says "There are lots of questions about whether to count the bytes in an import statement"
@seequ Because they severely limit certain languages in terms of byte count. (Yes, I mostly write Java answers, but it's not the only language that needs imports)
@seequ I think this is the general consensus of similar metaposts. You sort of end up grouping languages. For example C# and Java can compete to some extent because they're similarly verbose
@Poke See, I don't agree with that. I'd like to actually be able to post a decently competitive answer without having to spend bytes doing import java.util.*.
The lack of a straightforward answer on meta is odd, but the lack of any answer (or even a comment really) saying they shouldn't be counted is at least some kind of consensus.
I'd be okay with stdlib imports not counting towards it (like java.util.*, or for C# System), but then there'd probably be arguments over what actually counts as core libraries in each language and it would be kinda complicated.
@Xanderhall When you pick a language, you fight within that language's limits. I don't think there's a reason to change the rules because you don't like those limits.
Although if you have to use System at some point, chances are having a single System.Console or using System; isn't going to be the main factor in your byte count anyway.
@Xanderhall Let's say you've imported java.util.* implicitly. Heck you can even have all the static imports you want. "a".substring(0,3) or (using a List) list.get(0) is still going to be longer than a golfing language's ability to perform those tasks
@Xanderhall Well technically, if we just start removing things we don't see fit, we could argue that types don't alter the outcome of a program either. Could just go get rid of all the variable definition types. Sure it won't compile as is, but you saved some bytes right?
@Xanderhall I think one good reason not to allow free imports is that we want to allow all languages to participate, and it would be a big hassle to determine which imports are free in every single one. It would also make scoring less obvious for newcomers.
And making all imports free would be overkill, since golfing would mostly be about finding a good library.
A Squirrel has to transport nuts from location A to location B. The distance between two
locations is “X” kms.
The Squirrel will consume one nut for every 1 km it travels. The Squirrel
can carry at max “Y” nuts at a given time.
If there are “Z” nuts at location A, what is the
maximum number of...
I just realized the problem with "if a tree falls in a forest and nobody is around to hear it, does it make a sound?". If nobody is around, then the sound is not the issue. The issue is whether it fell in the first place. For all we know, the forest simply randomly changes every time we visited it.
@Rainbolt I think one of the fundamental tenets of science is that the universe follows the same laws everywhere (this wasn't always the case). However, there's simply no way we know that that is true.
@mbomb007 Welp, guessed that, I just don't find it funny ^^ And religion on its own is pretty much the world's biggest joke, that's why I'm a proud pastafari :V
also, this is totally off-topic, but the fact that 90% of our challenges are code-golf has one large benefit: We are less useful for homework and off-site challenges
If you had even glanced at those results you would see that ironic does not apply to the hat but something else (like The ironic catholic) so this doesn't answer the question
@mbomb007 It is, it is, and I accept that. To many people, religion can be their salvation, and for that, it's good. I just can't find myself 'good' in it
@Xanderhall Yeah but I think the points in that post can be applied to other languages too. Python vs Java, for example, usually leans in Python's favor
In this meta post, it's decided that function literals are valid when a function is required.
What about lambda expressions in Java 8? These are similar to function literals in other languages, but aren't really the same thing. Actually, these can be used in place of an instance of a functional ...
> A simple take might be that with the full declaration, it could be pasted into any class and work as-is. Without it, you have to paste both the function and something else. I don't see it as any different than requiring import statements to be counted if needed. Yes, they're outside the function, but you need them for the function to work in any given class.
It turns out that the only difference between a bug and a user story is how I react when I discover that the work item is not covered by requirements. User Story: "Yea, that's a cool feature. I should implement this when I have some free time!" Bug: "Why would the user ever want to do this?!"
Ah, okay. Yeah, the way they actually solved it with dozens of interfaces that do the same thing instead of introducing either simple Function1, Function2... "classes" with an automatic-if-not-declared-otherwise Void return (which diverges a LOT from the language) or just (which never, ever happens in Java) introduce a Callable<Parameters, Return> with Tuple types (Ceylon got me hooked) and thus polymorphic generics...