I know there's a room for it so I won't bring it up much here, however I am excited at the possibility of a PPCG/CR contest (considering the change of plans to mix teams from both sites)
class TestTranscribeDnaToRna(unittest.TestCase):
"""
Test `transcribe_dna_to_rna`.
"""
def test_trivial_input(self) -> None:
"""Validate that `transcribe_dna_to_rna` with the trivial input provided by the challenge returns the correct result."""
input_dataset = "GATGGAACTTGACTACGTAAATT"
expected_ouput = "GAUGGAACUUGACUACGUAAAUU"
actual_output = transcribe_dna_to_rna(input_dataset)
self.assertEqual(expected_ouput, actual_output)
def test_null_input(self) -> None:
@HyperNeutrino After some more reading I realized I made a rather large error in my interpretation of the sequence. Its fixed now. Hopefully this should be the last error of this type.
test_int_input (__main__.TestTranscribeDnaToRna)
Validate that an int input raises an error. ... ok
test_nontrivial_input (__main__.TestTranscribeDnaToRna)
Validate that `transcribe_dna_to_rna` with a real input provided by the challenge returns the correct result. ... ok
test_null_input (__main__.TestTranscribeDnaToRna)
Validate that NULL input raises an error. ... ok
test_trivial_input (__main__.TestTranscribeDnaToRna)
Validate that `transcribe_dna_to_rna` with the trivial input provided by the challenge returns the correct result. ... ok
def transcribe_dna_to_rna(dna_str: str) -> str:
"""
Transcribe DNA string into RNA string.
tldr: replace `T` char with `U` char, disregarding case.
"""
if not isinstance(dna_str, str):
raise ValueError("Input is not a string.")
elif dna_str is None:
raise ValueError("`None` / `null` input is invalid.")
# TODO this check is broken:
elif not bool(re.match(r"[ACDGT]*", str(dna_str))):
raise ValueError()
return dna_str.replace("T", "U").strip()
I wanted to learn about pointers and someone suggested that I give C a try, so I went through Linked List Basics from Stanford CS library, implemented some of the code (and tried to improve the code a bit as I went), as well as wrote "unit tests" (to the extent you can call them such in C).
I'm ...
@ASCII-only At most universities data structures is an easy A, at my university they use it as a strainer course, so things get pretty hard. That being said It is one the best courses I have taken so far.
@Phrancis Linked lists are a tool that are meant for specific scenarios. They are slow if you use them incorrectly, but fast if you use them as you are intended.
The main advantage to Linked lists is that then are O(1) on insertion and deletion. They might not be better for tail end recursion, that remains to be seen.
Vim question: Is there a way to run dd without it writing to a register?
>_> I need to write up a brief guide on using git, and I'm using MS Word. The problem is that I need to have both code segments and plaintext segments, and I want grammar checking in the plaintext segments and have absolutely no correction in the code segments.
I think MS Word might not be the best tool, but I can't think of anything else.
Assembly language / machine code must take input and output as defined by an ABI for the platform that predates the challenge
For example, most commonly used ABIs for x86 state that 32-bit integer outputs are returned in the %eax register. As such, that's a valid way to output a 32-bit integer. ...
Assembly programs may take input from registers
If there are no I/O devices available, an answer might consist of a subroutine that reads its input values from the machine registers.
Create kek variants!
Challenge
Write a program or function that outputs every possible kek variant possible.
What's a kek variant, you ask? It is any three-letter string that follows the following syntax:
xyx
Where x is a consonant and y is a vowel (we will treat the letter Y as a vowel for...
It theoretically shouldn't cause any problems, because of how it's parsed, but it does...
Hmmm...
Oh, that's why. doing something like printvar = 3 works fine, but trying to access it anywhere will make it assume you want to print var, instead of access the variable printvar.
But at the very least print print print "Honk"; is valid syntax, so all is good in the world.
My first code golf post, apologies for any mistakes...
Context
In rock climbing (bouldering specifically), the V/Vermin (USA) climbing grades start at 'VB' (the easiest grade), and then go 'V0', 'V0+', 'V1', 'V2', 'V3', 'V4', 'V5' etc. up to 'V17' (the hardest grade).
Task
You will take as in...
The Double Slit Experiment
code-golf ascii-art physics random animation
A lazy physicist has the job to perform the double slit experiment. However, they are lazy and can't be bothered to set up all the equipment themselves and so are going to simulate the effects. They can't program though so ...
A lazy physicist has the job to perform the double slit experiment. However, they are lazy and can't be bothered to set up all the equipment themselves and so are going to simulate the effects. They can't program though so are going to need some help. As they are lazy your program should be as sh...
Hard-coding the output
Unless the question is an obvious exception (the primary exception being those tagged kolmogorov-complexity), your program is expected to do work, not just print a pre-calculated result. If the question doesn't require input and so a solution which just prints the answer w...
It compiles into the following method System.Environment.get_UserName()
The source too (to be complete :P) public static string UserName { [System.Security.SecuritySafeCritical] // auto-generated get { new EnvironmentPermission(EnvironmentPermissionAccess.Read,"UserName").Demand();
StringBuilder sb = new StringBuilder(256); int size = sb.Capacity; Win32Native.GetUserName(sb, ref size); return sb.ToString(); } }
@TheLethalCoder After you type in the multi-line message you want to code-format, there will appear a button fixed font next to send and upload. That will automatically format it as code, by adding 4 spaces in front of each line.
public static string UserName { [System.Security.SecuritySafeCritical] // auto-generated get { new EnvironmentPermission(EnvironmentPermissionAccess.Read,"UserName").Demand();
StringBuilder sb = new StringBuilder(256); int size = sb.Capacity; Win32Native.GetUserName(sb, ref size); return sb.ToString(); } }
Becomes
public static string UserName {
[System.Security.SecuritySafeCritical] // auto-generated
get {
new EnvironmentPermission(EnvironmentPermissionAccess.Read,"UserName").Demand();
StringBuilder sb = new StringBuilder(256);
int size = sb.Capacity;
Win32Native.GetUserName(sb, ref size);
return sb.ToString();
}
}
Anonymous
So in C#, properties are syntactic sugar for private variables with getters and (optionally) setters automatically or manually generated. Something like public string Foo { get { return this._foo; } set { this._foo = value; } } is roughly equivalent to public string getFoo() { return this->_foo; } public void setFoo(string value) { this->_foo = value; } in C++.
Anonymous
Properties are methods that have syntactic sugar. When they're used as rvalues, the get method is called. When they're used as lvalues in assignments, the set method is called (with an implicit argument value).
@feersum I'm not sure - I've never tried it. The syntactic sugar for the getter would probably get in the way of doing it directly, but I'm sure there's a workaround.
Anonymous
By meta consensus, a function-like thing is valid, even if it requires different syntax to call, so long as it meets the other requirements on functions.
Comparing Strings
code-golf string
You will be given two non-empty strings containing printable ASCII. If their contents are exactly the same, output their contents. If their contents are different, output a third string. This third string cannot be a substring of either string, and neither str...
when x is *{
when y is x{
print "y was just set to what x is fam (" + x + "), better put a stop to that.";
y = 0;
};
};
x = 1;
print y = 1;
>> y was just set to what x is fam (1), better put a stop to that.
>> 0
Backstory
The host government has promised that in addition to the security guards in each match, there will be a platoon of elite commandos that will be deployed for extra protection in each stadium for each match. In order to move quickly between cities and stadiums there will be a dedicated a...
Simple challenge: given a series of positive integer numbers, find the number that contains among its digits the longest run of consecutive digits. The trick? It's allowed for the digits to wrap around the possible values (0123456789) and to run backwards. So both 2345, 89012 and 5432109 are vali...
@ConorO'Brien Possibly. For starts, you'd want $matches[0] since PowerShell is zero-indexed everywhere. Depending upon how you have the workflow, you could pipe it to a where-clause with |?{$_-match'regex' and then encapsulate that in parens and pull out the 0th. Or, you could use Select-String but that tends to be longer.
code-golf string filesystem
tail: troll: file truncated
Background
When you run tail -f file in bash, the file is outputted and then any subsequent appends.
However, when you remove something that has already been displayed, tail outputs:
tail: nameoffile: file truncated
Your Challenge
Wh...
when fib is *{
if fib <= 1
fibout = 1
else if fib != 1{
local n = fib;
fib = n - 1;
local a = fibout;
fib = n - 2;
local b = fibout;
fibout = a + b;
}
};
fib = 5;
print fibout;
Horrifying Fibonacci implementaiton
I tried using fib as the output variable too, but I quickly realized that became an issue.
Would it be fine if I made a language with a wide variety of modes? like 20, e.g. 1 mode would just be for fibonacci challenges, would that mode switch be included in byte count?
Using MetaGolfScript
MetaGolfScript is a family of programming languages. For example, the empty program in MetaGolfScript-209180605381204854470575573749277224 prints "Hello, World!".
It is similar to using extra command line arguments, where they should also count as characters. And using the ...
when fib is 0 { done = 1; }
when done is 0 {
local sum = a + b;
a = b;
b = sum;
fib = fib - 1;
done = done;
}
a = 0;
b = 1;
fib = 5;
done = 0;
print a;
@TheLethalCoder I am planning to change the behaviour of ()s. Instead of them starting entirely new Carrot programs, they will start another Carrot program in the same sheet (the tape of tapes). This will allow the program to fetch values from other cells in the sheet.