@justkelly_ok Woof, yeah. I agree that's entirely inappropriate for SO. I just pushed a change to remove questions from that site from the Hot Network sidebar. I'll ping folks internally to review the site's content more closely as well.
JavaScript inline code that prompts the user to enter a number, pass the number to an external JavaScript function and let the function calculate and display the factorial of the number entered by the user.
You have to make something that takes in one input from a default I/O method (as an integer), and prints out the sum of all the permutations of that number (not necessarily unique)
For example:
10 would return 11 because 10 can have 2 permutations (10 and 01), and the sum of those two numbers w...
In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.
In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.
Some tests:
'A' returns 1 (me...
We define the most basic form of the UNIX cat program: Copy data from stdin to stdout verbatim. Data means arbitrary 8-bit binary data.
The challenge: Implement cat using only bash built-in commands. The program may fork, but may not cause any program to exec, other than bash.
I've been writing...
Generate an RSA key pair
Given a positive integer \$N >= 3\$, output an RSA key pair (both the private and the public key) whose key length is \$N\$ bits.
The RSA key generation algorithm is as follows:
Choose an \$N\$-bit semiprime \$n\$. Let the prime factors of \$n\$ be \$p\$ and \$q\$.
Co...
Yeah. Not sure exactly how I'm going to proceed because I want to be able to do Frac(1, 0) and get 1/0 (or maybe inf) as the result. I think I may have to write a __new__ method for my subclass, because otherwise fractions.Fraction.__new__ is going to raise a ZeroDivisionError and give me no opportunity to catch it.
That's what I was originally going to do... then I thought I could piggyback off of a lot of Fraction's functionality by inheriting from it. On the other hand, now that I think of it, pretty much every function and operator is going to have to handle the 0-denominator case separately, so you're probably right.
(Shameless plug: this is for a new language I'm working on called Spearmint. It's functional, concatenative, and is eventually going to be compilable into a [hopefully] competitive golfing language. And it will have rational numbers, as soon as I figure out the best way to program that.)
How it is annoying in Python, how often do I override built-in names by accident. I did this today: async for type, id, object in h.reply(msg) - every var is a built-in...
I can't understand how could someone seriously name a global built-in id, that's one of most common var names I would use.
Minimum 1's to get 1-expression for n
code-golf number
Background
Challenge is inspired by this question.
The 1-expression is a formula that in which you add and multiply the number 1 any number of times. Parenthesis is allowed, but concatenating 1's (e.g. 11) is not allowed.
Here is an exam...
@Adám If I can take the array as its string representation, here's a regex-based answer in 38 bytes of Pip: aRx:`(\d+,)*\d+`_.",0"XMX(aMRxY',N_)-y. I'm not sure, but I think this may be shorter than any actual array-based solution. :P
Ooh, actually, I have a function submission (takes an array, returns an array) that's also 38 bytes and is quite elegant: {Y{a>0?#gMX:fMUg}Va{a>0?g+^0XyfMUg}Va}. It uses language features, like recursion and the binary version of eval, that I rarely get to use in golf. Fun!
Wait, no, I misread the spec. Shoot. The actual CMC is harder than what I solved. :(
import numpy as np
x = np.random.randint(0,7,(3,3))
#while any(element >= 4 for element in np.nditer(x)):
while ([[x[i,j]>=4 for i in range(x.shape[0])] for j in range(x.shape[1])]):
#if x[i,j] >= 4:
if i > 0: x[i - 1, j] += 1
if j > 0: x[i, j - 1] += 1
if i < 2: x[i + 1, j] += 1
...
Not All Sums Are Equal
code-golfmathnumerical-analysissum
Introduction
When computing the sum of a list of floating pont values, the order in which we add up the summands matters. A good way to reduce errors, is beginning with the summand with the least modulus and working your way up to the n...