3
3
Back to the basics! You're in you comp sci class again, except wiser and golfier. You have the tools, you have the power… but do you have the skill? Probably.
Crash Course for the non-Computer Scientist (skip if you don't need it)
A string is symbolically represented by an arbitrary letter (usually, for our purposes, will be etc. Of course, we know a string as something like "Hello, World!"
or 'Hello, World!'
, or, if you're the snarky Python user, """Hello, World!"""
.
An alphabet can be thought of as a set (i.e. no repeating characters) of symbols, of which strings can be made. For example, ; this is the binary alphabet, of which contains strings like and . These strings can said to be strings over , or, alternatively, .
The length of any string is denoted . For example, .
There is the empty or null string , which is equivalent to ""
. It is a valid string in over any alphabet. In other words, is the unique string satisfying the property .
The set is the set of all strings over for which .
The set is called the Kleene closure of , and is the set of all strings over . This can be considered the language of .
The concatenation of two strings and is denoted , and is the string containing the characters of followed by the characters of .
is said to be a prefix of if there is some string that satisfies the equality . (If , then is said to be a proper prefix of .)
The alphabet of a string is denoted , and is the minimal alphabet so that is a string over
The projection of a string relative to an alphabet is defined as
and is essentially the removal of all characters in not in .
TL;DR
Objective Write a program, series of functions, series of programs etc. that can calculate as many of the following tasks as possible:
- (1) Calculate, given a string
s
, its length. - (2) Arrive at, given a string
s
and an alphabetΣ
, whether or not (output a truthy/falsy value) that string is over said alphabet. - (1) Given an alphabet, arrive at whether or not (output a truthy/falsy value) the alphabet is valid (a valid alphabet can have no repeating characters, but is otherwise valid).
- (4) Given an alphabet
Σ
and a positive integern
, display . - (6) Given an alphabet
Σ
and an integern
, display the firstn
entries in (Remember thatε ∈ Σ
!) - (1) Given a string
s
and a stringt
, outputst
. - (3) Given a string
s
, outputAl(s)
. - (5) Given a string
s
and an alphabetΣ
, outputπΣ(s)
.
Input is given by a string or your language's closest equivalent for a string input, an array, tuple, or n-ordinate of characters for an alphabet (your language's closest equivalent), and a number for a number (or your language's closest equivalent, heaven forbid your language does not support numbers!).
Each task has a score (the number in parenthesis). Your submission's score is calculated as follows:
sum points scored
score = —————————————————
length of bytes
Highest score wins.
Bonuses
- ×4 final score iff you output (with the correct symbols!) the input query. E.g., outputting
\pi_{\{0,1\}}(012345678910111213)=01101111
for an input ofΣ = [0,1]; s = 012345678910111213
. (You may choose to do this in either HTML or (La)TeX. Either counts.) - (I'm open to suggestions.)
Also, for the bonus, how would you notate the third or sixth challenges? – LegionMammal978 – 2015-10-25T19:11:51.270
10@CᴏɴᴏʀO'Bʀɪᴇɴ There is currently no incentive to solve more than 1 challenge, because any challenge with a worse ratio will give a lower score. The scoring system needs to be changed to make this challenge work. I would recommend making it
points/length
for each problem, and then sum the scores for each problem completed. Most points wins. – isaacg – 2015-10-25T19:17:12.5102@CᴏɴᴏʀO'Bʀɪᴇɴ That's almost there, but not quite. The point is that answering additional challenges should always improve your score. So you should sum the scores of each challenge, not compute an overall points number. – isaacg – 2015-10-25T20:17:31.893
4This is a situation in which the sandbox would have been handy to sort out issues prior to posting. – Alex A. – 2015-10-25T20:29:00.557
@isaacg actually, you can share code between the challenges. – Paŭlo Ebermann – 2015-10-25T20:41:01.867
For (6) is there a specific order required? I.e. what are the first elements of an infinite set? – Paŭlo Ebermann – 2015-10-25T20:42:44.030
For the bonus, is using unicode characters directly (and not HTML entities) also okay? – Paŭlo Ebermann – 2015-10-25T20:57:30.940
@PaŭloEbermann Yes. – Conor O'Brien – 2015-10-25T20:58:51.347
1The scoring has not really changed with the latest edits. It's now the inverse of what it was originally, and the highest wins. This changes the scores, but not the order of them. If somebody had score
s1
before, which was lower than scores2
, the new scores are now1 / s1
and1 / s2
, where the first score is higher. – Reto Koradi – 2015-10-25T21:14:26.030@RetoKoradi What do you suggest? – Conor O'Brien – 2015-10-25T21:21:44.993
1Task 6, the first
n
seems meaningless for aset
. Do you meanany n
? – edc65 – 2015-10-25T22:16:40.570I assume the order is meant to be lexicographical @edc65 – Lynn – 2015-10-25T22:26:57.893
@Mauris A lexicographical order requires an order on the alphabet. And we don’t know the alphabet. – Édouard – 2015-10-25T23:17:22.813
How do we parse "complete anything for the challenge?" Is JavaScript's built-in string type unsuitable for [1] because it has a
.length
property and therefore completes something for the challenge? Or is it merely forbidden to use that property? If our programming language contains lazy generators can we require that the $\Sigma$ "input" be the generator for $\Sigma^*$ ? – CR Drost – 2015-10-25T23:47:12.447@CRDrost For the former, it is acceptable. For the latter, I said that
Input is given by the most convenient method that does not complete anything for the challenge. E.g., you can accept a string for the first challenge, but not the length of the string.
Specifically, the use of an input that effectively solves the problem is forbidden. – Conor O'Brien – 2015-10-26T01:28:41.557@CᴏɴᴏʀO'Bʀɪᴇɴ I mean, I view "effectively solves the problem" as vague in these scenarios where interconversion is so trivial, which is why I'm asking you to clarify. – CR Drost – 2015-10-26T14:33:16.593
@CRDrost Thanks for clarifying your problem. It is a tad vague. I will disambiguate – Conor O'Brien – 2015-10-26T15:14:47.563
@CᴏɴᴏʀO'Bʀɪᴇɴ OK. I posted a new entry while you were revising that but it was invalidated by your rules change, so I have put its heading in strikethrough font; I think it might be worth keeping it for historical reasons. – CR Drost – 2015-10-26T15:28:07.107
0 counts as falsy in all languages, right? – user8397947 – 2016-06-07T01:41:25.417
@dorukayhan It depends on the language. Typically, if code inside an
if
statement runs with a value as a condition, the value is considered truthy – Conor O'Brien – 2016-06-07T02:03:48.9704
I'm voting to close this question as off-topic because it is a multi-part challenge with insufficient interaction between the parts
– pppery – 2019-10-19T18:57:24.540@pppery Thanks, but you’re retroactively applying a standard that wasn’t in place at the time the question was asked. Not really applicable – Conor O'Brien – 2019-10-19T19:21:29.517
Rules about question on-topicness apply to questions that predate them. Othertwise, First code golf decathlon would never have been closed and locked. All that has happened is that this clearly off-topic question has slipped through the cracks for three years -- well, the time has come for that to be remedied.
– pppery – 2019-10-19T19:24:36.343@pppery Alright. I don't really care, not terribly invested in this site. Seems stupid and pedantic, but do whatever. Good luck getting this closed. – Conor O'Brien – 2019-10-19T19:59:38.003