also, 56 for english to alien translator: r"%v"_d"a_oauieu_o"pu)+Zv d'i"ni"'o"pi"'u"ki"'a"bo"'e"nu
no idea how to make it shorter. other golflangs appear to be using titlecase, which Japt lacks :(
@DJMcMayhem re: that score system post, there is a way that works almost all the time, since we have (mostly) consistent post formatting... it's called SEDE querying
@Shaggy any clue why "factorial\nsquare\ncube\nprime\ncomposite\ntriangular\npositive\nnegative" makes shoco error when running it through your permutation string array thing?
Goal
Write a program or function that takes a positive integer n and randomly generate a legal series of pitches (a Pitch string) of length n.
Input
A non-zero, positive integer n <= 100
Output
Return a random string, or list of characters, that represent a possible, valid pitch string of le...
kolmogorov-complexity
Kolmogorov Complexity Machine
Given a string, return a golfed program (in any language, not necessarily the language of the answer) that outputs that string.
Just an idea fragment currently, I see many issues
Scoring? I thought of (average ratio of (output / length of in...
For a while now, I've been running into a problem when counting on my fingers, specifically, that I can only count to ten. My solution to that problem has been to count in binary on my fingers, putting up my thumb for one, my forefinger for two, both thumb and forefinger for three, etc. However...
Unique Skittle Pairs
code-golf
This is my first question, so hopefully it's OK.
I like to eat Skittles. However, I only like to eat them in pairs, and and those pairs must not have two Skittles of the same color. Your task is to find the most pairs that you can that match these requirements.
C...
Hold up..... this isn't trolling.
Background
These days on YouTube, comment sections are littered with such patterns:
S
St
Str
Stri
Strin
String
Strin
Stri
Str
St
S
where String is a mere placeholder and refers to any combination of characters. These patterns are usually accompanied by a I...
Random C++ question: Is there a way that I could force this program to give a single error on line 16 rather than the gross long errors that boost gives?
Suppose you have a string \$s_0\$ and someone else has a hidden string \$s_1\$. You don't know what \$s_1\$ is but they tell you that they can get from your string, \$s_0\$, to their string by making a certain number of moves \$d\$. Each move can be one of the following:
Insertion : Add a ch...
Reducing switches in a binary array
Write a function to reduce an n-dimensional array's toggle/switch count for each row to be less than or equal to a desired toggle count. However, simply sorting the array isn't an option, because:
The Hamming distance between the original and modified array ...
Ideas for empty set symbol? There's about a gazillion in the unicode space - there's one listed as an APL symbol so that's probably well supported by fonts, but it isn't called an empty set there. Alternative would be the one in the math space, or maybe others?
@Οurous The APL symbol ⍬ is the empty simple numeric list (APL differentiates between the types of empty arrays), which is why it is a digit zero with the APL symbol for "without" ~.
APL symbols might be appropriate for programming languages, but likely aren't for mathematical discussion, the same way you wouldn't use === for equality in a maths paper
fwiw, I think the optimum for a golfing language, except possibly one where the operators do things that vary wildly based on context, is for the only data types to be "number" (probably bignum-rational), and "array"
I think it's probably best to allow arrays to be untyped in the sense that they don't care what type their elements are, because some problems require heterogenous arrays to work
Huh. Somehow I think I'm in the wrong. For the YouTube comments challenge, the two PowerShell answers print "O\nO\nO" for input "O" while every other answer just prints "O"...
well, if "number" is your only base type, there's no character/codepoint distinction
in every golfing language I've seen which makes the distinction, it causes problems
also, forcing your arrays to have fixed numbers of dimensions is a problem in programs that want output like [[],[[]],[[[]]],[[[[]]]]]
those maybe aren't that common, but they come up often enough to want languages to be able to deal with them
I guess there's a big difference in philosophy between languages that want the data types to reflect the data directly, and languages which just want to provide a set of data types that can be used to encode any data you care about
CMC: Given an array of positive integers, output an array where each element corresponds to an empty array at depth n. For example, 1, 2, 3, 4 -> [[], [[]], [[[]]], [[[[]]]]]
@ais523 Wouldn't you want more types? That way you could infer from the problem what is more likely wanted? For example if the problem is on a graph your array manips would probably mostly do nonsensical operations on it while you could have a bunch operators specifically for graphs.
addition is a meaningful operation on codepoints, often; I guess multiplication and division are less often meaningful
although if you have a problem like "decode UTF-8 without the use of encoding-related builtins", being able to mix strings and integers and arrays is pretty useful, as it doesn't naturally fall into any of those categories
@ais523 One thing I've contemplated for arithmetic on characters is for the system to "remember" that this number "wants" to be a character and change it back to a character asap. E.g. ⌈'y'÷2⌉ should give '='
like, there's some useful mathematical operation on numbers, and if you perform that operation on the codepoints, it does case-folding (or some similar string operation)
lower(upper(x)) is actually useful for "normalising" Turkish. I've mapped that to abs(). So |'İiIı' is the same as ⌊⌈'İiIı' which gives 'iiii' whereas ⌊'İiIı' gives 'iiiı' and ⌈'İiIı' gives 'İIII'
@ais523 What's wrong some arguments causing the function to have different properties? The floor of a real non-integer is always to the left of that number, but the floor of a complex non-integer may be to the right (but below). E.g. ⌊0.9+0.1i⌋=1 if ⌊z⌋ is the complex integer y such that |z-y| is minimised.
@ais523 I realise that, but that's the only sensible locale agnostic normalisation since Unicode refused to encode lowercase i with dot and uppercase i without dot.
@ais523 Wolfram Language instead floors each dimension separately. APL does as I described. It is of course easy to do the parts separately, but the closest integer isn't so easy.
http://mathworld.wolfram.com/FloorFunction.html > The floor function |_x_|, also called the greatest integer function or integer value (Spanier and Oldham 1987), gives the largest integer less than or equal to x.
@ais523 Comparing magnitudes is obviously easy, but then you end up with things like neither a<b nor a>b being true while a≠b. In the Total Array Ordering we recently added to Dyalog APL, we compare the real parts first, and tie-break by the imaginary part.
@ais523 well... it would be meaningful if there were separate types for different representations of a complex number/representation matters, and then you floor each component and return a vector :P
@Poke It started with the question of desirable number of types in a golfing language, inspired by a request for a good symbol for the empty set, with the suggestion of APL's ⍬ which is a type-specific empty list.
IMO, if you have a program that solves your problem and you can't run it in a reasonable length off time, what you need is a better compiler rather than a faster program
@Rick the way to think about it is that we're trying to communicate the idea behind the task we've been set as tersely as possible; so code golfing is about discovering new forms of communication
what's the shortest way we can express the concept of "print all odd integers from 100 to 1 in reverse order", for example?
@Rick FWIW, some people also golf in Machine code, or turing tarpits which is like the opposite of using libraries or long methods. Even expressing simple concepts can be really challenging
if you want to know which of two (real-life) objects is heavier, you don't make a set of digital scales and a comparator, you use a pair of analog scales (which is just a stick and a pivot)
@Adám not entirely; if you don't count the RAM, though, they're about 99% made of PMOS and NMOS transistors, which are typically combined into NAND, NOR, NOT, or a variant/mix of those
PMOS and NMOS give you "true if 0" and "false if 1" conditions which can be combined with and/or; so a "NAND gate" is an arrangement of PMOS and NMOS transistors that form the expression "the output is true if input A is false or input B is false, and the output is false if input A is true and input B is true"
I believe NAND gates are more common than NOR gates, although they're both used, as are NOT and various complex hybrids
RAM is an exception because it contains a large number of capacitors, which have time-dependent behaviour
(this is because the purpose of RAM is to persist values over time, and it's much cheaper to use a time-dependent component and refresh it now and again than it would be to use a bistable circuit)
incidentally, the reason to use NAND gates isn't just because they're universal, but because the definition of CMOS (i.e. a PMOS/NMOS combination) requires you to invert the inputs every time, so a NAND gate is easier to build in hardware than an AND or OR gate
and the reason NAND gates are more common than NOR gates is that the 0 and 1 logic levels aren't symmetrical in practice, normally your ground has more capacity than your power supply does, so a 0 pulls "stronger" than a 1, and that affects things like how many devices you can connect without an amplifier in between
but CMOS allows you to create any Boolean expression as long as the output is (non-strictly) decreasing in every input
so NAND, NOR, NOT, and various combinations are all used as single gates
@Rick I wouldn't say that. Rather there exists a set of essential operations (like subtraction and multiplication) that are very versatile for both domains.
not quite; the more builtins you have, the longer their names will have to be
a golfing language I've been working on uses a six-bit character set (so 64 characters); that means the builtins have shorter names than in almost any other language, but means you can't have nearly as many single-char builtins
@ais523 Sure, but again, this is just a matter of spelling. Ultimately, an infinite collection of languages, each with a single (the empty program) built-in for a particular problem ensures "winning" every challenge.
but it isn't interesting, because no single language in the collection is a good one for general-purpose communication
a special-purpose language will always be capable of beating a general-purpose language if both are written well, but it's general-purpose communication that we care about
@Adám I would like to see that too, but you'd need to golf a lot of programs to gather information to determine suitable weights
not only that, but some builtins would likely become unnecessary if you Huffman-coded the language, due to duplicating something that would have a comparable length if written using different builtins
@ais523 Hm, wouldn't it be wonderful if there was a publicly accessible website with a large collection of code golf problems solved in a couple of strong golfing languages…
@ais523 Good point. One would need to define each not-obviously-needed built-ins each in a variety of ways using obviously-needed built-ins, and iterate encodings to gradually optimise.
as a concrete example, "multiply by 1" is X1 (which IIRC is a primality test), and all integer constants must be immediately preceded by a capital letter, thus it's impossible for the 1 to merge with anything else
@Adám I considered that, and did in fact give shortcut encodings to a few commonly used high numbers; the issue is that low numbers tend to be used more frequently than high ones as-is
@Rick no, bijective means that two things have a 1-to-1 correspondence with each other, you can convert one to the other and back again and always end up where you started
fwiw, I find the "list of numbers by how often they're used" really interesting to look at
the original source is the entire text of English-language books in Google Books (I obviously don't have access to the original raw source for copyright reasons, but I do have access to the frequencies of every word that appears ≥30 times in it, and numbers are treated as though they were words)
so English, I guess
fwiw, I've long had a project to use this data to create a string compressor for a golfing language
@Adám maybe not radically; the powers of two are the main exception that comes to mind, but both programming and English are meant to describe real-world problems
fwiw, 4294967296 is the 36481th most common number in this list, so pretty common compared to how large it is
but 256 doesn't appear until position #376
65536 is in position #4734
(even then, 256 in golfing challenges seems to appear almost exclusively in the concept of "number of possibilities for a byte")
actually, the list goes down to numbers that were used 40 times, not 30 times
as well as the numbers that come to mind when people happen to need an arbitrarily large number
now I'm reminded of Perl modules; they're supposed to return a value saying whether they loaded correctly, but because Perl has exceptions nowadays, they basically always end with an arbitrary truthy constant; most people just use 1 but some people are more creative, and there are people who gather lists of all the truthy constants found at the end of Perl modules
:49239591, if it's just 1 to 1, would that just mean they are injective. Wouldn't they have to be both injective and surjective for it to be considered a bijection?
hmm, I like the use of !(); () (an empty list) is the consensus false value, so negating that should produce a consensus true value by definition
(it became the consensus false value because it's not only falsey, it also has a length of 0 in all contexts, whereas 0 has length 1 when viewed as a string. and "" has length 1 when viewed as a list, because it listifies to (""))
hmm, would be interesting to do something like this across the whole of Github
numbers tend to be fairly comparable in usage across languages (apart from languages which use line numbers, which will disproportionately be attracted to 10, 20, 30, 40, etc., but those are rarely used nowadays)