Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Balanced quinary quasiquine

Post

Balanced quinary quasiquine

+1
−0

Given an integer $N$ in balanced quinary, output the first $N$ characters of your source code if $N$ is positive, or the last $-N$ characters of your source code if $N$ is negative.

Terminology

Quinary Standard quinary (base $5$) has digits $0, 1, 2, 3, 4$. In a quinary number a digit $n$ places from the right is worth $5^n$ times that digit's individual value.

For example, the quinary number $1234$ converts to decimal like this: $$(1\times5^3)+(2\times5^2)+(3\times5^1)+(4\times5^0)$$ $$(1\times125)+(2\times25)+(3\times5)+(4\times1)$$ $$125+50+15+4$$ $$194$$

Balanced quinary Balanced quinary works exactly the same as standard quinary, except it uses digits worth $-2,-1,0,1,2$. In a balanced quinary number a digit $n$ places from the right is worth $5^n$ times that digit's individual value, just like in standard quinary. This allows balanced quinary to express all positive and negative integers without the need for a leading minus sign / negation symbol.

For the following example we will use $Y$ to represent $-2$ and $Z$ to represent $-1$, so our digits are $Y,Z,0,1,2$.

For example, the balanced quinary number $YZ12$ converts to decimal like this: $$(Y\times5^3)+(Z\times5^2)+(1\times5^1)+(2\times5^0)$$ $$(-2\times125)+(-1\times25)+(1\times5)+(2\times1)$$ $$-250-25+5+2$$ $$-268$$

Input

  • The input will be an integer in balanced quinary
  • You may choose any $5$ characters to represent the $5$ digits of balanced quinary
  • As these digits do not necessarily have to be numeric characters, you are free to choose between taking input as a numeric type, or as a string, including any ordered data structure of characters
  • The input will never have leading zeroes
  • The input may correspond to a value larger in magnitude (absolute value) than the number of characters in your source code
  • The input will never be empty (zero is represented in balanced quinary as the digit $0$)

Output

For input that evaluates to $N$:

  • If $N$ is positive, the output is the first $N$ characters of your source code
  • If $N$ is negative, the output is the last $-N$ characters of your source code
  • If the magnitude (absolute value) of $N$ is greater than the number of characters in your source code, the output consists of your entire source code
  • The required characters of your source code must be output in order
    • Specifically, if $N$ is negative, the last $-N$ characters must not be in reversed order.
      If your source code is QUINTESSENTIAL the last $9$ characters are ESSENTIAL, not LAITNESSE
  • The output may include an optional trailing newline
  • If $N=0$ the output must be empty (apart from the optional trailing newline)

Excluded trivial cases

Using source code of length $3$ or fewer characters is defined to be a challenge-specific loophole, and is not a valid answer.

Detailed justification Source code with length $3$ characters or fewer meets the requirements trivially, without requiring an implementation of balanced quinary.

In order to demonstrate that it is correctly interpreting the balanced quinary base system (not just the individual digits), your code must have at least $2$ different outputs for inputs with $2$ digits.

The smallest magnitude of a $2$ digit balanced quinary number is $3$. This means that source code of $3$ or fewer characters would lead to the full source code being output for all $2$ digit inputs, regardless of value. The shortest source code length that can lead to different outputs for different $2$ digit inputs is therefore length $4$ ($4$ characters - even in cases where that means more than $4$ bytes).

Test cases

These test cases use $Y,Z,0,1,2$ as digits of value $-2,-1,0,1,2$ respectively. In your own code you are free to use whichever character you wish to represent each of these 5 values.

The test cases are in the format
quinary input : decimal equivalent : "output characters"
The output characters are based on your source code being the string QUINTESSENTIAL and the double quotes do not form part of the output (they just make empty output easier to read for these test cases).

0 : 0 : ""
Z : -1 : "L"
1 : 1 : "Q"
Y : -2 : "AL"
2 : 2 : "QU"
Z2 : -3 : "IAL"
1Y : 3 : "QUI"
Z1 : -4 : "TIAL"
1Z : 4 : "QUIN"
Z0 : -5 : "NTIAL"
10 : 5 : "QUINT"
1000 : 125 : "QUINTESSENTIAL"
Z000 : -125 : "QUINTESSENTIAL"

Scoring

This is a code golf challenge. Your score is the length of your source code in bytes. Lower is better.

Note that your score is in bytes, but the required length of output is measured in characters, in case the two are not equivalent for your chosen language.

Explanations are optional, but I'm more likely to upvote answers that have one.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

May we take input as an array of balanced quinary digits? (2 comments)
typo. missing 0. (2 comments)
typo. missing 0.
torres‭ wrote about 2 years ago

I get Z00= -25, not -125, and 100= 25, not 125. (Z5^2)+ (05^1)+ (0*5^0) = _25 . 'Z000' would be -125. Similarly for 100/1000.

trichoplax‭ wrote about 2 years ago

Thanks for catching this. Now edited to fix.