text
stringlengths 180
608k
|
---|
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win.
Closed 8 years ago.
[Improve this question](/posts/53086/edit)
It can be in any language, plus the map must be in the output only **not in the source code**.
This is my first question here, so please feel free to edit it. Also, there might be some rules about scoreboard which I'm not familiar how to put it here.
Cheers!
[Answer]
## Vatican
In CJAM:
```
46c
```
You can test it [here](http://cjam.aditsu.net/#code=46c)
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/12222/edit).
Closed 3 years ago.
[Improve this question](/posts/12222/edit)
Find the highest common factor of two(positive integer) input numbers (not greater than 5000) in the minimum number of iterations.
If you use a loop, it should increment a counter, starting at 0 for the first run. The counter should be the first statement in the loop. If you use more than one loop, they too should have a similar counter.
So
```
counter_1=0;
counter_2=0;
...
loop{
counter_1=counter_1 + 1;
...
code
...
loop_nested{
counter_2=counter_2 + 1;
...
code
...
}
}
total_count=counter_1 + counter_2 + ...
```
Test cases
first-number second-number-->expected-output
450 425-->25
27 23-->1
1000 1001-->1
36 54-->18
2 4000-->2
4000 2500-->500
2000 4000-->2000
99 75-->3
584 978-->2
3726 4380-->6
The code with the lowest sum of all counters for all test cases wins.
There is no restriction on program length. Of course, you can't use any standard functions. There is no restriction on the language that you use.
Also, please write the sum of counters that your code produces.
[Answer]
Along similar lines to Ilmari's solution, but slightly shorter (comparing expanded versions):
```
#include <stdlib.h>
#include <stdio.h>
#define D(pn, p) (a%(pn) + b%(pn) ? 1 : (p))
#define P(p) D(p, p)
#define P2(p) D(p, p) * D(p*p, p)
int main (int argc, char *argv[]) {
int a, b, t, gcd;
if (argc != 3) return 1;
a = atoi(argv[1]);
b = atoi(argv[2]);
if (a < 1 || a > 5000 || b < 1 || b > 5000) return 1;
// Force an order: a <= b
if (a > b) {
t = a; a = b; b = t;
}
gcd = (a == b || a*2 == b || a*3 == b || a*4 == b || a*5 == b ||
a*3 == b*2 || a*5 == b*2 || a*4 == b*3 || a*5 == b*3 ||
a*6 == b*5) ? a :
((a|b) & -(a|b)) *
P(3) * D(9, 3) * D(27, 3) * D(81, 3) * D(243, 3) * D(729, 3) *
P(5) * D(25, 5) * D(125, 5) * D(625, 5) *
P(7) * D(49, 79) * D(343, 7) *
P2(11) * P2(13) * P2(17) * P2(19) * P2(23) *
P(29) * P(31) * P(37) * P(41) * P(43) * P(47) * P(53) * P(59) *
P(61) * P(67) * P(71) * P(73) * P(79) * P(83) * P(89) * P(97) *
P(101) * P(103) * P(107) * P(109) * P(113) * P(127) * P(131) *
P(137) * P(139) * P(149) * P(151) * P(157) * P(163) * P(167) *
P(173) * P(179) * P(181) * P(191) * P(193) * P(197) * P(199) *
P(211) * P(223) * P(227) * P(229) * P(233) * P(239) * P(241) *
P(251) * P(257) * P(263) * P(269) * P(271) * P(277) * P(281) *
P(283) * P(293) * P(307) * P(311) * P(313) * P(317) * P(331) *
P(337) * P(347) * P(349) * P(353) * P(359) * P(367) * P(373) *
P(379) * P(383) * P(389) * P(397) * P(401) * P(409) * P(419) *
P(421) * P(431) * P(433) * P(439) * P(443) * P(449) * P(457) *
P(461) * P(463) * P(467) * P(479) * P(487) * P(491) * P(499) *
P(503) * P(509) * P(521) * P(523) * P(541) * P(547) * P(557) *
P(563) * P(569) * P(571) * P(577) * P(587) * P(593) * P(599) *
P(601) * P(607) * P(613) * P(617) * P(619) * P(631) * P(641) *
P(643) * P(647) * P(653) * P(659) * P(661) * P(673) * P(677) *
P(683) * P(691) * P(701) * P(709) * P(719) * P(727) * P(733) *
P(739) * P(743) * P(751) * P(757) * P(761) * P(769) * P(773) *
P(787) * P(797) * P(809) * P(811) * P(821) * P(823) * P(827) *
P(829);
printf("The greatest common divisor of %d and %d is %d.\n", a, b, gcd);
return 0;
}
```
[Answer]
## C, no loops -> 0 iterations
```
#include <stdlib.h>
#include <stdio.h>
#define Q(n) (a % (n) == 0 && b % (n) == 0) ? (n) :
#define R(n) Q((n)+9) Q((n)+8) Q((n)+7) Q((n)+6) Q((n)+5) Q((n)+4) Q((n)+3) Q((n)+2) Q((n)+1) Q(n)
#define S(n) R((n)+90) R((n)+80) R((n)+70) R((n)+60) R((n)+50) R((n)+40) R((n)+30) R((n)+20) R((n)+10) R(n)
#define T(n) S((n)+900) S((n)+800) S((n)+700) S((n)+600) S((n)+500) S((n)+400) S((n)+300) S((n)+200) S((n)+100) S(n)
#define U(n) T((n)+4000) T((n)+3000) T((n)+2000) T((n)+1000) T(n)
int main (int argc, char *argv[]) {
int a, b, gcd;
if (argc <= 2) {
fprintf(stderr, "Usage: %s <num1> <num2>\n", argv[0]);
return 1;
}
a = atoi(argv[1]);
if (a < 1 || a > 5000) {
fprintf(stderr, "Input %d out of range!\n", a);
return 1;
}
b = atoi(argv[2]);
if (b < 1 || b > 5000) {
fprintf(stderr, "Input %d out of range!\n", b);
return 1;
}
gcd = U(1) 0;
if (gcd) {
printf("The greatest common divisor of %d and %d is %d.\n", a, b, gcd);
} else {
fprintf(stderr, "Unable to find gcd of %d and %d! Inputs out of range?\n", a, b);
}
return 0;
}
```
Given that you've specified an upper limit of 5000 on the input values, this challenge can be solved in *any* language without *any* (runtime) loops just by taking a trivial solution using a single trial-division loop and unrolling it 5000 times.
I've chosen to use C, since the C macro preprocessor allows the solution to be written in a compact manner. The macros will be expanded at compile time into a single *huge* nested ternary `?:` expression.
(If you consider the compile time macro expansion to be a loop in disguise, feel free to run the code above through the C preprocessor and consider the expanded *output* — which is also a valid C program — to be my solution. I won't include the expanded version in this post, though, since it's huge.)
[Answer]
### Ruby
```
def gcd(a,b)
('x'*a+' '+'x'*b).gsub(/^(.*)\1* \1+$/,'\1').length
end
```
A completely different solution - no explicit loops either.
[Answer]
# Tcl, 0 loops.
Some languages don't even have loops, they use recursion.
Note: if you don't use Tcl 8.6, replace `tailcall` with `return [...]`
```
proc gcd {a b} {
if {$b > $a} {tailcall gcd $b $a}
if {$b == 0} {return $a}
tailcall gcd $b [expr {$a % $b}]
}
```
Well, and here for the people that said recursion is a loop:
```
proc gcd2 {a b {i 0}} {
if {$b > $a} {lassign [list $a $b] b a}
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
set a [expr {$a % $b}]
if {$a == 0} {return $b}
set b [expr {$b % $a}]
if {$b == 0} {return $a}
}
```
[Answer]
## APL (0 loops)
All right, after some people have posted even smarter ideas I might as well post this one, which I wrote to support my comment. It has no loops or recursion expressed in it.
```
∇GCD;divs;gcd
divs ← {A/⍨A=⌈A←⍵÷⍳⍵}
gcd ← {⊃A/⍨(A←divs⍺)∊divs⍵}
⎕ ← ⎕ gcd ⎕
∇
```
For people who are not familiar with reading APL, I'll give all explict looping constructs that I know of below:
* `:For` ... `:EndFor` (for loop)
* `:While` ... `:EndWhile` (while loop)
* fn`¨`list (apply *fn* to each element in *list*)
* fn`⍣`*N* (apply *fn* *N* times)
* fn`⍣`condfn (apply *fn*, until (*condfn*( *x*, *fn*( *x* ) ) is true)
* `{`...`∇`...`}`: recursion (`{`...`}` is a function, `∇` refers to the function it is used in)
Explanation of the program:
* `divs`: (get divisors of a number, in descending order)
+ `A/⍨A=⌈A`: select from `A` those elements where `A` is equal to `ceil(A)`
+ `A←⍵÷⍳⍵`: ...where `A` is the right argument (`⍵`) divided (`÷`) by the numbers from 1 to `⍵` (`⍳⍵`)
* `gcd`: (get the greatest common denominator of two numbers)
+ `⊃`: get the first (thus, biggest, see above) element of:
+ `A/⍨`: the elements selected from `A`, where...
+ `(A←divs⍺)`: `A`, which is the divisors of the left argument,
+ ...`∊divs⍵`: ...is a member of the divisors of the right argument.
* `⎕ ← ⎕ gcd ⎕`: output (`⎕ ←`) the GCD of input (`⎕`) and input (`⎕`).
] |
[Question]
[
User inputs an integer. Print out proper fractions using all positive integers up to the user's input, in ascending order.
Rule 1: Eliminate equal fractions.
Rule 2: Fractions should be in their simplest form.
Rule 3: Use "/" as a fraction symbol and next line (\n or \r as convenient) as a separator between fractions.
Winning Criteria: The shortest code wins.
For example:
4:
```
1/4
1/3
1/2
2/3
3/4
1
```
6:
```
1/6
1/5
1/4
1/3
2/5
1/2
3/5
2/3
3/4
4/5
5/6
1
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 10 bytes
```
¶OfεuΣ´Ṫ/ḣ
```
[Try it online!](https://tio.run/##ARwA4/9odXNr///Ctk9mzrV1zqPCtOG5qi/huKP///82 "Husk – Try It Online")
```
ḣ # 1..input
´ # argdup: use this range twice
Ṫ # to construct a table
/ # of one element divided by the other
# (Husk will automatically simplify the fractions);
Σ # now flatten the table to a list
u # and keep only the unique elements,
f # filter to keep only those
ε # with value at most 1,
O # sort in ascending order,
¶ # and split by newlines
```
(or, also 10 bytes: `¶uOṁṠM`/ḣḣ` [try it](https://tio.run/##yygtzv7//9C2Uv@HOxsf7lzgm6D/cMdiIPr//78ZAA))
[Answer]
# JavaScript (ES6), 77 bytes
Based on [the algorithm given in Wikipedia](https://en.wikipedia.org/wiki/Farey_sequence#Next_term).
```
f=(d,a,b=(n=d,1),c=1)=>a^b?[a&&a+`/${b}
`]+f((k=(n+b)/d|0)*d-b,c,d,k*c-~~a):1
```
[Try it online!](https://tio.run/##VcpLDoIwEADQPadgYWCGTsUmxoVJ9SB@wrQDRCGtEeNG5erVrev3rvzkyd8vt4cOUdqUOgtCTM5CsEIGyVuDdsdntz9wUbBq6sXLfbLmpDqA4deUw1reK6xEO/IkNFRezzPj1iQfwxTHdjnGHjpYY67y8hhKzP5hg5i@ "JavaScript (Node.js) – Try It Online")
### Commented
```
f = ( // f is a recursive function taking:
d, // the input n and the parameters (a, b, c, d)
a, // which are initially set to:
b = (n = d, 1), // (undefined, 1, 1, n)
c = 1 //
) => //
a ^ b ? // if a is not equal to b:
[ a && // append either a + '/' + b + '\n' if a is defined
a + `/${b}\n` // or just an empty string if a is undefined (which
] + // happens only for the first iteration)
f( // append the result of a recursive call:
(k = (n + b) // set k = floor((n + b) / d)
/ d | 0) //
* d - b, // update d to k * d - b
c, // update a to c
d, // update b to d
k * c - ~~a // update c to k * c - a
// (with a coerced to 0 if undefined)
) // end of recursive call
: // else:
1 // stop the recursion and append the final '1'
```
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 56 bytes [SBCS](https://github.com/abrudz/SBCS)
```
{↑↑'1',⍨(⊣,'/',⊢)⍥⍕/¨m[⍋÷/¨m←w/⍨≠÷/¨w←⊃⍵,.(¯1↓,¨)⍨,\⍵]}⍳
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=q37UNhGI1A3VdR71rtB41LVYR10fyO5apPmod@mj3qn6h1bkRj/q7T68HcR61DahXB@o8FHnArBAOVDgUVfzo96tOnoah9YbPmqbrHNoBVDrCp0YoGBs7aPezQA&f=S1Mw4UpTMAMA&i=AwA&r=tryapl&l=apl-dyalog&m=train&n=f)
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 28 bytes
```
j{mj\//Ri.*dd<oc.*N^SQ2sUQ)1
```
[Try it online!](https://tio.run/##K6gsyfj/P6s6NytGXz8oU08rJcUmP1lPyy8uONCoODRQ0/D/fzMA "Pyth – Try It Online")
##### Explanation
```
j{mj\//Ri.*dd<oc.*N^SQ2sUQ)1 | Full code
-----------------------------+------------------------------------------------------------------------------------------
^SQ2 | Generate all pairs of integers [1..input]
oc.*N | Sort by division
< sUQ | Keep only the first <input>th triangular number of pairs (the next pair is always [1, 1])
m /Ri.*dd | Divide each pair by its GCD
mj\/ | Join each pair by '/'
{ | Remove duplicates
j ) | Join all by '\n'
| Print (implicit)
1 | Print 1
```
[Answer]
# [Factor](https://factorcode.org) + `math.matrices`, ~~83 76~~ 71 bytes
```
[ [1,b] 1 over n/v outer [ [ 1 min ] map ] gather natural-sort stack. ]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=LU0xDsIwDNz7Cj-AFnVBCB5QsbAgpqpDCGmImibFcSrxFpYOwJ_6G1zCYt-d787PTyskeZxmfT4djtUOekG3AoXTKkCn0CmbJB5oJIs_Nqol9ScerwohqHtUbnEEj2ScZoUCDKiIHgMaR7DPss07Uptv56qGulxdGijBj5x26xF8JEZ8YLE3DhquH3hqfrJYBEUUNl_qIZCQXQFNqntJYW2C05T2Fw)
#### How?
In Factor, division produces ratios that automatically reduce to simplified form, so that helps a lot.
* `[1,b] 1 over n/v outer` If \$x\$ is the input, \$\Bigl[1\ldots x\Bigr]\otimes\Bigl[\frac{1}{1}\ldots\frac{1}{x}\Bigr]\$ (where \$\otimes\$ is the tensor/outer product).
* `[ [ 1 min ] map ] gather` Get a list of the unique elements of the above matrix whose values are clamped to a maximum of 1.
* `natural-sort` Sort into ascending order.
* `stack.` Print each ratio to stdout with a newline.
[Answer]
# [Goruby](https://codegolf.stackexchange.com/questions/363/tips-for-golfing-in-ruby/9289#9289), 77 bytes
Very direct port of the [code from Wikipedia](https://en.wikipedia.org/wiki/Farey_sequence#Next_term)
-4 bytes thanks to [Raztime](https://codegolf.stackexchange.com/users/80214/razetime)
```
->n{a,b,d=0,c=1,n
dw{k=(n+b)/d
a,b,c,d=c,d,k*c-a,k*d-b
sa b<2?a:a*1r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JLgl18Ya6f1Tax9DMwHH7q_GehcUPJ3gAjdA2aZ8yocEHTMmFwLcqMSYOFfdU3CDSx6jUnoIqU68HOK3GIMVRvNNqba8-mjNNmFgDdYeUc7iE95HNjS24Q8kSoAlc2LFOiNRPd-QCXSVYQRGJ7PgAMMKe4g8yx8EOTVlUbo24ozWMKhvZqgj2pDKtxzxrzAElzetONv0Fnn42ZP1WmZo2S8ItquN1TQplHQtO3jooD6wzshqjrv_u0DbHLwUniGOOEtVqY3Y03ouORecS1NIsLp41zfY-Htn86l3tbxIq4p4kN0KwKhoI7S-xIuuPYRWFPU8FmHxMHnu6H5H9q_vyyLeMCV8v80pj4n900nfxS4_qs9uPHyAqz6Nqz53X0LseD8dhkcd69sO3eZA69mRcl--CXjN7WPXLobdi_1JiNa95r7ot0f56Xs79KvTz_8e9fzp-IigRxkMwuAjqbBmKQ3FU3M088iv1JMjAsikz8Bjdjek7wNzmPB4pA_PibK3JJxlM5iQfiyYw2jTP6cTn_YeGuHz64818)
# [Ruby](https://www.ruby-lang.org/), 85 bytes
```
->n{a,b,d=0,c=1,n
while n>=c
k=(n+b)/d
a,b,c,d=c,d,k*c-a,k*d-b
puts b<2?a:a*1r/b
end}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGiNNulpSVpuhY3Q3Xt8qoTdZJ0UmwNdJJtDXXyuMozMnNSFfLsbJO5sm018rSTNPVTuEBKkoGKgFgnWytZNxFIpugmcRWUlhQrJNkY2SdaJWoZFukncaXmpdRCDF-SFm0WC2EuWAChAQ)
[Answer]
# [Python](https://www.python.org), 99 bytes
```
def f(n):
a,b,c,d=0,1,1,n
while~n+c:k=(n+b)//d;a,b,c,d=c,d,k*c-a,k*d-b;print([1,f"{a}/{b}"][b>1])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3k1NS0xTSNPI0rbgUEnWSdJJ1UmwNdAyBMI9LoTwjMye1Lk872SrbViNPO0lTXz_FGqYKiHWytZJ1E4Fkim6SdUFRZl6JRrShTppSdWKtfnVSrVJsdJKdYawmxKqlaRqGBlA2zHoA)
Another port of the [Farey sequence generation algorithm](https://en.wikipedia.org/wiki/Farey_sequence#Next_term), though this one's a bit cheaty since the code on the Wikipedia article is given in Python.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 10 bytes
```
¨Vv/fU~ṅs⁋
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCqFZ2L2ZVfuG5hXPigYsiLCIiLCI2Il0=)
```
¨Vv/fU~ṅs⁋
¨Vv/ # Create a division table from [1, input]
fU # Flatten and uniquify
~ṅ # Keep only elements <= 1
s # Sort
⁋ # Join on newlines
```
] |
[Question]
[
**This question already has answers here**:
[Largest Number Printable](/questions/18028/largest-number-printable)
(93 answers)
Closed 4 years ago.
I'm surprised this hasn't been done yet, but here we go.
Create a program which prints some number of 1s (ideally as large as possible) before halting.
The rules are simple:
Your program is bounded to 50 bytes in size.
Your output must only be a continuous row of 1s (plus trailing newline if it has to be added), without any breaks in the middle.
Your program must halt. No infinite loops.
Your program must not use STDIN or output to STDERR.
Your program must use STDOUT or closest equivalent.
Your score is the amount of 1s your program prints before halting.
Have fun.
[Answer]
# [Runic Enchantments](https://github.com/Draco18s/RunicEnchantments/tree/Console), Score: Aproximately ~~(10↑↑200)~~ (10↑↑303)18.877
```
>>>yybbqf:p'!A'!A'!A'!A'!A'!A'!A'!A'!A'!AFm1)b*?*@
```
[Try it online!](https://tio.run/##KyrNy0z@/9/Ozq6yMimpMM2qQF3REQ9yyzXUTNKy13L4/x8A "Runic Enchantments – Try It Online")
Utilizes Stephen's idea of factorials (they're kind of expensive in Runic, so I hadn't considered them originally) and managed to squeeze out ~~two~~ *three hundred* of them via implicit edge looping. Value-in is `15^15` (`437,893,890,380,859,375`) and the resulting value is then multiplied against the *string* `1111` (`bbq` is just as long as `"1"` and produces more 1s).
`200->300` accomplished by removing flow control logic and simply raising the "skip when true" to jump over the start of the program (executes the `:p` for bonus length, but is dwarfed by the factorials, but is responsible for the extra 3 powers of 10 in the tower).
["Wolfram|Alpha doesn't understand your query"](https://www.wolframalpha.com/input/?i=%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%28%283%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29%21%29)
[Answer]
# Python, 9^9^9^9^9^9^9^9^9^9^9^9^9 (or 9↑↑13)
```
print("1"*(9**9**9**9**9**9**9**9**9**9**9**9**9))
```
I hope this is right
[Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EQ8lQSUvDUkuLMLLU/P8fAA "Python 3 – Try It Online")
[Answer]
# [cQuents](https://github.com/stestoltz/cQuents), Aproximately (10↑↑45)7.347
```
"#t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&1
```
[Try it online!](https://tio.run/##Sy4sTc0rKf7/X0m5RJEUoGb4/z8A "cQuents – Try It Online")
Note that it does not start printing the 1s until it calculates the result of the factorial, so this probably will not run on any real system.
According to Wolfram Alpha, this value equals
[](https://i.stack.imgur.com/AK224.png)
or in plaintext
```
10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^(10^7.346902562777663))))))))))))))))))))))))))))))))))))))))))))
```
[Answer]
## Python 3 approx 9↑↑(36^8) 9↑↑(36↑(9↑↑3))
```
print("1"*eval("**".join("9"*int('z'*9**9**9,36)))
```
Must calculate first.
(Edited because I'm bad at math notation, and to include an improvement from randomdude999)
[Answer]
# MATLAB, Score: 9↑↑(2↑(10↑313))
```
x=9;
while(cputime<realmax/2)
x=x^x;
end
ones(1,x)
```
[Try it online!](https://tio.run/##y08uSSxL/f@/wtbSmqs8IzMnVSO5oLQkMzfVpig1MSc3sULXUJOrwrYirsKaKzUvhSs/L7VYw1CnQvP/fwA "Octave – Try It Online")
`cputime` counts the number of seconds that the MATLAB thread actually runs on the CPU as a double. `realmax` is the maximum double, `~10^308`; I divide by 2 because cputime will rollover back to zero and we actually need the loop to stop. According to the profiler, on my computer MATLAB can run the loop `1e6` times in about `3.7 seconds`. That means we'll perform `x=x^x` about `10^313` times! That isn't just 9↑↑(10↑313), because it compounds on every loop. It's 9↑↑(2↑(10↑313)) I think. I could cheat and make the condition `cputime==realmax/2`, and then it would be up to random chance when the program finally ends, making an absolutely insane number, but one that can't be calculated.
---
# MATLAB, Score: 9↑↑79 (or about (10↑↑78)8.568)
```
f=@(x) factorial(x)^x;
ones(1,f(f(f(f(9^9^9^9)))))
```
[Try it online!](https://tio.run/##y08uSSxL/f8/Py@1WMNQJy0xuSS/KDMxR8NUU/P/fwA "Octave – Try It Online")
Probly not as big as the power tower answers though. I need to figure out a short way to do that here.
[Answer]
# [PHP](https://php.net/), 43 bytes, Score: ~1e17 (based on my PC performance)
```
set_time_limit(-1);while(time()<4e9)echo 1;
```
[Try it online!](https://tio.run/##K8go@G9jXwAki1NL4ksyc1PjczJzM0s0dA01rcszMnNSNUCCGpo2JqmWmqnJGfkKhtb//wMA "PHP – Try It Online")
This will run until `2096-10-02` and then stop. This isn't an infinite loop as it will finally halt. I can set it to longer dates, but I think `4e9` or `2096-10-02` is good enough for me, it is about the idea 😊
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), approx. (10↑↑46)10.994 amount of `1`s (50 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage))
```
žm!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1×
```
**Explanation:**
```
žm # Push the builtin 9876543210
!!!...!!! # Take the factorial 46 times
1× # Push that many 1s as string
# (after which it's output implicitly as result)
```
This will print exactly \$9876543210↑↑46\$ amount of `1`s, or approx. \$(10↑↑46)^{10.994}\$ (thanks to *@Draco18s* for explaining how to calculate this \$(10↑↑a)^b\$ approximation.
] |
[Question]
[
**This question already has answers here**:
[Spell out the Revu'a](/questions/68901/spell-out-the-revua)
(34 answers)
Closed 6 years ago.
# Challenge
Given a string, make it into a triangle as shown below:
### Input
```
Hello, world!
```
### Output
```
H
He
Hel
Hell
Hello
Hello,
Hello,
Hello, w
Hello, wo
Hello, wor
Hello, worl
Hello, world
Hello, world!
```
The first line contains the first character of the string. The following lines contain one more character on each line, until the full length of the original string is reached.
If you receive a one character string, just output it.
You will never receive an empty string.
## Rules
* Standard loopholes apply, as usual
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest solution wins.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
;\Y
```
[Try it online!](https://tio.run/##y0rNyan8/986JvL///8eQE6@jkJ5flFOiiIA "Jelly – Try It Online")
[Answer]
# [brainfuck](https://github.com/TryItOnline/tio-transpilers), 23 bytes
```
,[[<]>[.>]++++++++++.,]
```
[Try it online!](https://tio.run/##SypKzMxLK03O/v9fJzraJtYuWs8uVhsO9HRi///3SM3JyddRKM8vyklRBAA "brainfuck – Try It Online")
[Answer]
# [Python](https://docs.python.org/2/), 33 bytes
```
f=lambda s:s and f(s[:-1])+s+'\n'
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P802JzE3KSVRodiqWCExL0UhTaM42krXMFZTu1hbPSZP/X9BUWZeCVA4M6@gtERDU/O/ukdqTk6@jkJ5flFOiqI6AA "Python 2 – Try It Online")
[Answer]
# J, 2 bytes
```
[\
```
Tailor made for J. This is just a scan `\` using the identity function `[`.
[Try it online!](https://tio.run/##y/oPBNEx6h6pOTn5CuH5RTkpiuoA "J – Try It Online") -- Note the extra space in the output on line 1 is just a quirk of TIO in this case. It does not appear when run in jconsole.
[Answer]
# [Haskell](https://www.haskell.org/), 28 bytes
```
g[]=[]
g a=(g.init)a++'\n':a
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/Pz061jY6litdIdFWI10vMy@zRDNRW1s9Jk/dKvF/bmJmnpWVp7@GJheIaVtQWhJcUqSSrqDkAdScrxCeX5STovQfAA "Haskell – Try It Online")
Pretty straight forward. The base case is the empty string and each other case is a recursive call to `init` to the string with a newline and the input added to the end.
Here are my three attempts at a non-recursive solution all of which are exactly the same length.
```
g a=concat['\n':take x a|(x,_)<-zip[1..]a]
g a=concat['\n':take(fst x)a|x<-zip[1..]a]
g a=concat['\n':take x a|x<-[1..length a]]
```
And here's one that I found that is shorter than all of them
```
g a=do(x,_)<-zip[1..]a;'\n':take x a
```
I also came up with this very strange solution I quite like (its longer than the others though):
```
g a=zip[1..](a>>[a])>>=('\n':).uncurry take
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P10h0bYqsyDaUE8vViPRzi46MVbTzs5WQz0mT91KU680L7m0qKhSoSQxO/V/bmJmnpWVp7@GJheIaVtQWhJcUqSSrqDkATQrXyE8vygnRek/AA "Haskell – Try It Online")
[Answer]
# [V](https://github.com/DJMcMayhem/V), 5 bytes
```
òÄ$xh
```
[Try it online!](https://tio.run/##K/v///Cmwy0qFRn//3uk5uTkK5TnF@WkKAIA "V – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 49 bytes
```
lambda s:'\n'.join(s[:i]for i in range(len(s)+1))
```
[Try it online!](https://tio.run/##DcixDkAwEADQXzlT2xAJo8TuDwxqqGg5OXdNa/H15Y0vvs8p3Jcw2kLu3nYHeVCWVXsJss7LgGuQBAjIkBwfXpP/39SdMSUm5AeCVpMnkgZmSbRXypQP "Python 2 – Try It Online")
Meanwhile, I'm like, how is this is impossible right now in my language?!
[Answer]
# [Python 2](https://docs.python.org/2/), 34 bytes
```
s=''
for c in input():s+=c;print s
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v9hWXZ0rLb9IIVkhMw@ICkpLNDStirVtk60LijLzShSK//9X90jNycnXUSjPL8pJUVQHAA "Python 2 – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 57 bytes
```
i;f(char*s){for(i=0;i<strlen(s);puts(""))write(1,s,++i);}
```
[Try it online!](https://tio.run/##HcsxDsIwDADAr0Anuw1SOxt2ftChYqjcBCyFBtlpGCreHgTz6fh0Z65VKAA/Zm0N95AU5NKTnC1r9CsY0mvLBk2D@FbJHgZnrusE6VOfs6zAruC/t4X2AGUabj@rVx9jcocxaVyOXw "C (gcc) – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 31 + 1 = 32 bytes
Uses `-n` flag.
```
a=''
$_.each_char{|i|puts a<<i}
```
[Try it online!](https://tio.run/##KypNqvz/P9FWXZ1LJV4vNTE5Iz45I7GouiazpqC0pFgh0cYms/b/f4/UnJx8HYXw/KKcFMV/@QUlmfl5xf918wA "Ruby – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 35 bytes
```
->s{a='';s.each_char{|c|puts a<<c}}
```
] |
[Question]
[
**Closed**. This question needs to be more [focused](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Update the question so it focuses on one problem only by [editing this post](/posts/28664/edit).
Closed 9 years ago.
[Improve this question](/posts/28664/edit)
Writing questions for programming puzzles is tiring and takes many minutes to do. This is where you come in. Your job is to write a program that randomly generates plausible-sounding (but not necessarily interesting) code golf questions.
Input: None
Output: One sentence code golf question (see sentence structure)
Guidelines: **No hardcoding**. The questions don't have to be valid, solvable, or nontrivial. Creativity is encouraged. Voting is based on variety and bonus to programs that can create interesting problems.
Samples:
```
Find the sum of every even number from 1 to 100.
Create a funny sentence without punctuation.
Draw a picture of a cat in 3D.
```
Sentence structure:
```
[verb] [noun goal] [of] [noun specific] [preposition] [noun restriction]
```
[Answer]
# [NetLogo](http://ccl.northwestern.edu/netlogo/)
```
to go
type one-of [ "Print" "Calculate" "Find" "Determine" "Output" ]
type " the "
type one-of [ "sum" "mean" "average" "median" "standard deviation" "product" "geometric mean"]
type " of all "
type one-of [ "prime" "composite" "even" "odd" "perfect" "abundant" "deficient" "square" "triangular" "cubic" "lucky" "friendly" "strictly non-palindromic" ]
type " numbers from "
type random 100
type " to "
type 100 + random 10000
type one-of [ " (inclusive)." " (exclusive)." ]
end
```
Sample output (obtained randomly):
```
Find the product of all friendly numbers from 60 to 3112 (inclusive).
```
[Answer]
## C
```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(NULL));
printf("Find the sum of every even number from 1 to %d.\n", rand());
return 0;
}
```
On my computer it can generate 2147483648 different challenges.
[Answer]
# Python
```
from random import randint as r
print "Draw a picture of a cat in %iD" % (r(2,4))
```
] |
[Question]
[
**This question already has answers here**:
[Time-Sensitive Echo](/questions/60188/time-sensitive-echo)
(20 answers)
Closed 7 years ago.
# A boring version of yourself
Have you ever dreamed of a boring version of you which types the text you just typed ?
No ? Because that's exactly what I'm challenging you to do !
The program needs to check how many time it took for the user to input a text at program launch and then retype the text again using the same period of time (approximatively).
Here's my Python3 implementation with additional information :
```
import time
start = time.time()
userInput = input("Cool human input :")
endHuman = time.time() - start
duration = endHuman / len(userInput)
start = time.time()
print("Boring robot input : ", end="")
for i in userInput:
print(i, end="")
time.sleep(duration)
end = time.time() - start
print()
print(endHuman, "vs", end)
```
This is a code-challenge so be creative !
Here are the rules :
* User **must** input the initial text, no program args
* Text input length is > 0 (No need to check)
* The sleep duration between each letter is not imposed, it can be (timeTookByUser / numberOfLetters) like in my implementation, it can be random (as long as the total time is approximatively equal), it can sleep for the total time at first and then print all (but it's not fun).
* The "robot timer" must stop when the last letter is typed by the robot, you can't print everything and then sleep and end the program.
* As long as the robot prints the text passed in input, you can print other stuff (additional informations etc..)
* You don't **have to** use the console, you can input the text using a graphical text input and render it letter by letter using DELs but you will have to specify it in your answer
* Be creative !
[Answer]
# Bash + linux utilities, 37
This will measure the time taken to enter each character (including backspaces) and play back verbatim. Use `^C` or `^D` to end user input.
```
script -qta -csed\ d
scriptreplay -ta
```
Creates a temporary files `typescript` and `a` in the current directory.
[](https://i.stack.imgur.com/M6JdR.gif)
[Answer]
# MATLAB / Octave, 38 bytes
```
tic;x=input('','s');pause(toc);disp(x)
```
Starts a timer ([`tic`](https://www.mathworks.com/help/matlab/ref/tic.html)) and prompts the user for input. Then the program pauses for however long it took for the user to input the text ([`toc`](https://www.mathworks.com/help/matlab/ref/toc.html)) and prints out the input text.
[Answer]
# MATL, ~~7~~ 5 bytes
*2 bytes saved thanks to @Luis*
```
jZ`Y.
```
This solution will determine how long the user takes to enter the input and then wait that same amount before printing the user's input back to them all at once.
Unfortunately doesn't work online since the online interpreters don't support interactive input.
[](https://i.stack.imgur.com/7gq5S.gif)
**Explanation**
```
% Implicitly start the timer
j % Grab user input as a string (will prompt the user)
Z` % Stop the timer and return the elapsed time in seconds
Y. % Pause for this many seconds
% Implicitly display the user-input string
```
[Answer]
# Python 3.5, 61 bytes
```
from time import*
s,i=time(),input()
sleep(time()-s)
print(i)
```
] |
[Question]
[
You need to make a program, that when giving a list and a string, searches on the list for items that contains the string.
Examples:
```
Input: th [thing, awesome, potato, example]
Output: thing (Because it starts with "th")
Input: ing [thing, potato]
Output: thing (Because it ends with "ing")
Input: tat [thing, potato]
Output: potato (Because it contains "tat")
Input: tat [tato, potato]
Output: tato, potato (If there are 2 or more results matching, print all of them)
```
Remember, this is code golf, so the shortest code wins.
## Leaderboard
Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.
```
/* Configuration */
var QUESTION_ID = 72079; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.
/* App */
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) {
return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}
function commentUrl(index, answers) {
return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}
function getAnswers() {
jQuery.ajax({
url: answersUrl(answer_page++),
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
answers.push.apply(answers, data.items);
answers_hash = [];
answer_ids = [];
data.items.forEach(function(a) {
a.comments = [];
var id = +a.share_link.match(/\d+/);
answer_ids.push(id);
answers_hash[id] = a;
});
if (!data.has_more) more_answers = false;
comment_page = 1;
getComments();
}
});
}
function getComments() {
jQuery.ajax({
url: commentUrl(comment_page++, answer_ids),
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(c) {
if (c.owner.user_id === OVERRIDE_USER)
answers_hash[c.post_id].comments.push(c);
});
if (data.has_more) getComments();
else if (more_answers) getAnswers();
else process();
}
});
}
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
function getAuthorName(a) {
return a.owner.display_name;
}
function process() {
var valid = [];
answers.forEach(function(a) {
var body = a.body;
a.comments.forEach(function(c) {
if(OVERRIDE_REG.test(c.body))
body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
});
var match = body.match(SCORE_REG);
if (match)
valid.push({
user: getAuthorName(a),
size: +match[2],
language: match[1],
link: a.share_link,
});
});
valid.sort(function (a, b) {
var aB = a.size,
bB = b.size;
return aB - bB
});
var languages = {};
var place = 1;
var lastSize = null;
var lastPlace = 1;
valid.forEach(function (a) {
if (a.size != lastSize)
lastPlace = place;
lastSize = a.size;
++place;
var answer = jQuery("#answer-template").html();
answer = answer.replace("{{PLACE}}", lastPlace + ".")
.replace("{{NAME}}", a.user)
.replace("{{LANGUAGE}}", a.language)
.replace("{{SIZE}}", a.size)
.replace("{{LINK}}", a.link);
answer = jQuery(answer);
jQuery("#answers").append(answer);
var lang = a.language;
if (/<a/.test(lang)) lang = jQuery(lang).text();
languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
});
var langs = [];
for (var lang in languages)
if (languages.hasOwnProperty(lang))
langs.push(languages[lang]);
langs.sort(function (a, b) {
if (a.lang > b.lang) return 1;
if (a.lang < b.lang) return -1;
return 0;
});
for (var i = 0; i < langs.length; ++i)
{
var language = jQuery("#language-template").html();
var lang = langs[i];
language = language.replace("{{LANGUAGE}}", lang.lang)
.replace("{{NAME}}", lang.user)
.replace("{{SIZE}}", lang.size)
.replace("{{LINK}}", lang.link);
language = jQuery(language);
jQuery("#languages").append(language);
}
}
```
```
body { text-align: left !important}
#answer-list {
padding: 10px;
width: 290px;
float: left;
}
#language-list {
padding: 10px;
width: 290px;
float: left;
}
table thead {
font-weight: bold;
}
table td {
padding: 5px;
}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
<h2>Leaderboard</h2>
<table class="answer-list">
<thead>
<tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
</thead>
<tbody id="answers">
</tbody>
</table>
</div>
<div id="language-list">
<h2>Winners by Language</h2>
<table class="language-list">
<thead>
<tr><td>Language</td><td>User</td><td>Score</td></tr>
</thead>
<tbody id="languages">
</tbody>
</table>
</div>
<table style="display: none">
<tbody id="answer-template">
<tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
</tbody>
</table>
<table style="display: none">
<tbody id="language-template">
<tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
</tbody>
</table>
```
[Answer]
# [TeaScript](http://github.com/vihanb/teascript), 4 bytes
```
F@Iσ
```
Output is cast to string.
[Try it online](http://vihan.org/p/TeaScript/#?code=%22F@I%CF%83%22&inputs=%5B%22%5B%5C%22tato%5C%22,%20%5C%22potato%5C%22%5D%22,%22%5C%22tat%5C%22%22%5D&opts=%7B%22ev%22:true,%22debug%22:false%7D)
## Explanation
```
F@ // Filter input 1
Iσ // Includes input 2
```
[Answer]
## Python 2, ~~42~~ 36 bytes
```
lambda i,a:filter(lambda v:i in v,a)
```
Thanks to [muddyfish](https://codegolf.stackexchange.com/users/32686/muddyfish) for saving 6 bytes
Test:
```
a=lambda i,a:filter(lambda v:i in v,a)
a('th', ['thing', 'awesome', 'potato', 'example']) # ['thing']
a('ing', ['thing', 'potato']) # ['thing']
a('tat', ['thing', 'potato']) # ['potato']
a('tat', ['tato', 'potato']) # ['tato', 'potato']
```
[Answer]
## JavaScript ES6, 32 bytes
```
(s,a)=>a.filter(e=>~e.search(s))
```
33 bytes if the string might contain regexp metacharacters:
```
(s,a)=>a.filter(e=>~e.indexOf(s))
```
[Answer]
# Pyth - 5 bytes
```
f}zTQ
```
[Try it online here](http://pyth.herokuapp.com/?code=f%7DzTQ&test_suite=1&test_suite_input=th%0A%5B%22thing%22%2C+%22awesome%22%2C+%22potato%22%2C+%22example%22%5D%0Atat%0A%5B%22tato%22%2C+%22potato%22%5D&debug=0&input_size=2).
Filters the input list by if the input string is in it.
[Answer]
## vim, 13
```
dd:v/\V<C-r>"<BS>/d<cr>
```
Expects input as
```
th
thing
awesome
potato
example
```
Outputs on separate lines.
```
dd delete first line into " (default) register
:v/ apply to every line that doesn't match the following regexp...
\V "very nomagic" - strips chars of their special regex meaning
<C-r>" paste contents of " register into the command
<BS> remove the trailing newline from the first line
/d ... delete the lines
```
[Answer]
# Racket, 49 bytes
```
(λ(l s)(filter-map(curryr string-contains? s)l))
```
[Answer]
## [W](https://github.com/a-ee/w), 5 bytes
```
b@t!W
```
## Explanation
```
ba % Implicit inputs
b % Access the second operand
@ % Show two operands (yields [b,b,a])
W % Select everything in a that fullfills this condition:
t % Trim everything in the current item
% that appears in the input
% Yields ([b,b.trim(a)])
! % Negate this result, determining whether
% the input is a subset of the current item
% Keeping all of the items that fullfill
% this condition yields a list by default
```
```
[Answer]
## Python 2, 47 bytes
```
a=input()
print[x for x in input()if x in a]
```
[Answer]
## Bash, 27 bytes
```
tr \ \\n<<<${@:2}|fgrep $1
```
Sample run:
```
llama@llama:...code/shell/ppcg72079search$ ./search.sh th thing awesome potato example
thing
```
With multiple outputs, they will be on separate lines.
```
tr \ \\n replace spaces with newlines (equivalent to tr ' ' '\n')
<<<${@:2} ... with STDIN as all but first argument
|fgrep $1 fgrep for first argument (fgrep is grep w/ "fixed" string, not regex)
```
[Answer]
# sh, 5 bytes
Accepts a list of words on stdin, one per line, and a search string as command line argument.
```
fgrep
```
This submisson should be valid by the rules on [scoring builtin functions](http://meta.codegolf.stackexchange.com/questions/7205/on-scoring-builtin-functions).
[Answer]
# ùîºùïäùïÑùïöùïü, 4 chars / 5 bytes
```
í⒡ăî
```
`[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter3.html?eval=true&input=%5B%60ing%60%2C%5B%60thing%60%2C%60potato%60%5D%5D&code=%C3%AD%E2%92%A1%C4%83%C3%AE)`
Simple.
# Explanation
Filter input array by string input.
[Answer]
# R, ~~38~~ 28 bytes
```
function(x,y)grep(y,x,,,T,T)
```
simply a wrapper for `grep`, with value = `TRUE` to return the value [not a logical flag], and fixed (to allow regex-like strings to be searched and not processed as `regex`.
*edit* - 10 bytes by passing empty arguments to allow positional matching
[Answer]
# Mathematica, 29 bytes
```
Select[#2,StringContainsQ@#]&
```
Very simple.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/58440/edit).
Closed 8 years ago.
[Improve this question](/posts/58440/edit)
Here is your task, should you choose to accept it: Output (through STDOUT, or whatever is most convenient) some `n` by `m` ASCII art that has at least one line of symmetry and is non-empty. Example:
```
HiiH
iooi
iooi
H!!H
```
This is a 4x4 example output.
(Note: I define an ASCII character to be in the ASCII range 32-126 plus newlines and spaces. *No tabulators*.)
Here's the catch: Your program must also reflect across these same axes AND must be a rectangle in shape. (The output and the input are not necessarily the same width/length). Here is an example in JavaScript:
```
console.log("HiH")//("HiH")gol.elosnoc;
console.log("JvJ")//("JvJ")gol.elosnoc;
console.log("...")//("...")gol.elosnoc;
```
The source code has one line of symmetry (vertical) and the output has one line of symmetry: vertical.
```
HiH
JvJ
...
```
This is a [popularity-contest](/questions/tagged/popularity-contest "show questions tagged 'popularity-contest'"), so the highest-voted answer on THIS DATE:
```
3:00 PM
Saturday, September 27, 2015
Eastern Time (ET)
```
will be the winner.
# TL;DR
Write a program with the same axes of reflections as the output, of which is at least one. The output must have side lengths greater than one and must have at least one non-whitespace character.
# EDIT
If a character has a mirrored version (e.g. `(` and `)`), then it should be used instead of itself. Example:
```
[>Hello!\} => {/!olleH<]
```
# Why this question is *not* a duplicate
Said question wished to produce a quine which was the same, forth and back; my challenge is different in two ways. One, it does not necessarily have to be forth and back (up and down, right and left, e.g.). Two, I am not asking for a quine.
[Answer]
# Brainfuck, 103 bytes
I made you a sandwich.
```
---+++++++++++++---
[>+++>+<<->>+<+++<]
>...>-.<...>.-<...<
[>+++>+<<->>+<+++<]
---+++++++++++++---
```
Output:
```
***
***
***
```
[Answer]
## Pyth, 29 bytes
```
FG[\@\@)pGpG*0"0*GqGq(@/@/]GF
```
[Demo](http://pyth.herokuapp.com/?code=FG[%5C%40%5C%40%29pGpG*0%220*GqGq%28%40%2F%40%2F]GF&debug=0)
I'm assuming that one-liners are okay, otherwise there is an easy fix.
] |
[Question]
[
**This question already has answers here**:
[Count the Zeros](/questions/18098/count-the-zeros)
(7 answers)
Closed 10 years ago.
This will be my very first post on stackexchange so bear with me.
Create a program that counts from 0 to 1,000,000,000.
Now the trick is to not print all these characters but to only print how many zeroes are in that number. And keep track of the total amount of zeroes you've encountered. For example
```
10
```
Will output;
```
1
2
```
because 10 has 1 zero in it. The two represents how many 0's you've seen in total, in this case the only zero you have encountered previously is 0 itself so you've seen a total of 2 zeroes.
The highest score will be given to the shortest code (no surprise here).
*I hope that this is not too easy and that I've posted enough information, given the fact that I'm completely new here I'm not entirely sure about this.*
[Answer]
## Python (brute force, 80 chars)
```
def r(n):
l=[str(i).count('0') for i in xrange(n+1)]
return l[-1],sum(l)
```
Just to asure, i got the task right, it evaluates to:
```
r(10)
>>> (1, 2)
r(1000000000)
>>> (9, 788888899)
```
[Answer]
# (Oracle) SQL, ~~146~~ 144 chars / 122 chars
```
SELECT*FROM(SELECT l,SUM(REGEXP_COUNT(l,'0'))d FROM(SELECT LEVEL-1l FROM dual CONNECT BY LEVEL<=&a+1)GROUP BY ROLLUP(l))WHERE &a=l OR l IS NULL;
```
Expanded:
```
SELECT *
FROM (
SELECT
l,
SUM(REGEXP_COUNT(l, '0')) d
FROM (
SELECT LEVEL - 1 l
FROM dual
CONNECT BY LEVEL <= &a + 1
)
GROUP BY ROLLUP(l)
)
WHERE &a = l
OR l IS NULL;
```
Edit: no need to name the column, and `*` doesn't need spaces around it.
---
Okay, so we need it for *all* numbers from 0 to n. Let me put on my thinking cap... Try
```
SELECT c,SUM(c)OVER(ORDER BY l)FROM(SELECT l,REGEXP_COUNT(l,'0')c FROM(SELECT LEVEL-1l FROM dual CONNECT BY LEVEL<=&a+1));
```
Expanded:
```
SELECT
c,
SUM(c) OVER(ORDER BY l)
FROM (
SELECT
l,
REGEXP_COUNT(l, '0') c
FROM (
SELECT LEVEL - 1 l
FROM dual
CONNECT BY LEVEL <= &a + 1
)
);
```
[Answer]
## C, 90 bytes
```
r;i;j;main(t){for(;i<=10e8;j=++i){for(r=0;j;j/=10)j%10||r++;t+=r;}printf("%d\n%d\n",r,t);}
```
ungolfed:
```
r;i;j;main(t) {
for (;i<=10e8;j=++i) {
for (r=0;j;j/=10)
j%10||r++;
t+=r;
}
printf("%d\n%d\n",r,t);
}
```
[Answer]
## GolfScript ~~34~~ 32
```
0 10.(?,{`{48=},,}%{(.p@+.p\.}do
```
Explanation:
The initial `0` will be the counter for the number of 0s seen thus far. A billion is `10^9`, and `10.(?` generates a billion by taking `10`, copying it, decrementing, and then exponentiating. The `,` then generates an array of all numbers for 0 to a billion - 1. If we need to include one billion, add a `)` before the `,`.
The next block takes a number, converts it to a string by doing `''+`, then filtering down to the characters that equals '0' (ASCII value 48) by doing `{48=},` and then counting the length of the array by doing `,`. Map this block across all the numbers in our array with `%`.
The next block expects two elements on the stack: the total 0s seen, and then the array of 0-counts for each integer not yet printed. Each time the block is executed it pops the first element of the array with `(`, copies and then prints it with `.p`, moves the total counter to the front with `@`, adds the current number, and then rearranges the stack to be in the right order. The `do` will run this block until the array is empty.
[Answer]
## APL (30)
Brute-forced. There is no lazy evaluation, so it generates the whole list from `0` to `1e9` at once. So you need at least a 7GB workspace, or it will just say `WS FULL`.
In case you don't have a huge server to use, the program can be proven to work by lowering `1e9` to a saner amount.
```
(⊃⌽Z),+/¯1↓Z←{'0'+.=⍕⍵}¨0,⍳1e9
```
Explanation:
* `0,⍳1e9`: the list from `0` up to and including `1e9`
* `Z←{'0'+.=⍕⍵}¨`: count the zeroes in each number, and store the list in `Z`.
* `+/¯1↓Z`: the sum of all but the last item in `Z` (the total amount of zeroes encountered)
* `⊃⌽Z`: the last item in `Z` (the amount of zeroes in `1e9`).
[Answer]
**C# - 223 chars:**
```
using System.Linq;class P{static void Main() { G(10); } static void G(int i){System.Console.Write("{0},{1}",i.ToString().Count(l => l == '0'),Enumerable.Range(0, i + 1).SelectMany(b => b.ToString()).Count(l => l == '0'));}}
```
Expanded:
```
using System.Linq;
class P
{
static void Main() { G(10); }
static void G(int i)
{
System.Console.Write("{0},{1}",
i.ToString().Count(l => l == '0'),
Enumerable.Range(0, i + 1).SelectMany(b => b.ToString()).Count(l => l == '0'));
}
}
```
[Answer]
## Python 81 chars
```
def x(y):
o=0
for i in xrange(y+1):
o+=`i`.count('0')
print `y`.count('0'),o
```
[Answer]
## J (33)
**Warning: uses an *ungodly* amount of memory**.
```
({:,+/@}:)(+/@('0'=":))"0 i.1e9+1
```
Explanation:
* `i.1e9+1`: generate a list of numbers from `0` up to and including `1e9`.
* `(+/@('0'=":))"0`: for each number (`"0`), convert it to a string (`#:`), and see how many zeroes there are (`'0'=`).
* `({:,+/@}:)`: display the last item in the list (`{:`), followed by the sum of all but the last item in the list (`+/@}:`)
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/9294/edit).
Closed 9 years ago.
[Improve this question](/posts/9294/edit)
Title says it all. Given some input, turn it into a boolean value (0 or 1), without using conditional statements (e.x. `== > < <= >= != ~=`), or any function which uses conditional statements within its implementation, such as `if`, `while` and `for`. Your program must work with floating points, although you get more if it works with other items.
A general rule for determining whether `bool(item)` is False is if the item is empty (`''` is an empty string, `[]` is an empty list.), or if the function used to turn an item of one type into another is given no input (in Python, `str()` returns `''`, `list()` returns `[]`.)
Here are (some of) the different valid types. Your program is considered to work with one type if it works with one item in the following lists:
* Integers, floating points, doubles, longs
* Strings
* Lists, tuples, arrays (bytearrays)
* Dictionaries
* Functions
* Objects/Classes
Program score will be calculated like this: `[# of characters]-(50*[# of types])`. The program with the smallest score wins the challenge.
[Answer]
# Python - 122 chars - 50\*13 types = -528
```
def b(x=False):
try:return[False][x]
except IndexError:return True
except:
try:return b(len(x))
except:return True
```
Works for the following built-in types (as listed in [§3.2 The standard type hierarchy](http://docs.python.org/2/reference/datamodel.html#the-standard-type-hierarchy))
1. NotImplemented
2. Ellipsis
3. int
4. long
5. bool
6. string
7. unicode
8. tuple
9. list
10. bytearray
11. set
12. frozenset
13. dict
[Answer]
# MMIX (8 bytes assembled)
Assembly language has no statements.
```
bool ZSNZ $0,$0,1
POP 1,0
```
[Answer]
# JavaScript, -278
```
function bool(_,$){try{$=_.length;$._;_=$}catch(_){}return 1-isNaN(_/_)}
```
Doesn’t use any boolean operators! If global leaking and input is okay, then it’s even shorter, at 65 characters:
```
bool=eval.bind(0,'try{$=_.length;$._;_=$}catch(_){}1-isNaN(_/_)')
```
Works for anything with a `length` and all primitive types and their object wrappers.
Now you've added a list of things that count as types, but what kind of function or class should evaluate to `false`? This one treats functions that take no arguments as `false` - does that count? What about classes? What does that mean?
[Answer]
### Scala(152 characters)
```
implicit def?(a:Any)={val f=false;a match{case 0=>f;case null=>f;case ""=>f;case ()=>f;case None=>f;case x:Iterable[_]=>x.exists(_=>true)case _=>true}}
```
Sample inputs:
```
scala> if(0) true else false
res0: Boolean = false
scala> if(0.0) true else false
res1: Boolean = false
scala> if(1) true else false
res2: Boolean = true
scala> if(()) true else false
res3: Boolean = false
scala> if(List()) true else false
res4: Boolean = false
scala> if(List(1)) true else false
res5: Boolean = true
scala> if(Set()) true else false
res6: Boolean = false
scala> if("") true else false
res7: Boolean = false
scala> if(Map()) true else false
res8: Boolean = false
scala> if(None) true else false
res9: Boolean = false
scala> class X
defined class X
scala> if(new X()) true else false
res10: Boolean = true
```
[Answer]
## **GoRuby, 19 - 50\*(number of types in Ruby)**
```
def bool(o)
[1,[o].fle.j.sz].mi
end
```
Returns 0 if the passed object converts to the empty string, 1 otherwise. Of course, Ruby doesn't treat 0 as false, so this isn't a very *useful* function...in fact, `bool(bool(x))` is always 1. Objects that do convert to 0 include `nil`,`false`,`[]`, and lists containing only objects that convert to 0.
[Answer]
# Python 85 chars - 50\*20 types = -915 points
```
def b(x=False):
try:return b(len(x))
except:return{0:False,None:False}.get(x,True)
```
So it works for all types in the six categories in the question.
The score is therefore 85 - 50\*6 = -215, or am I wrong?
Here is also my test code:
```
class Test(object):
def __init__(self):
pass
for x in [None, NotImplemented, Ellipsis,
0,1,0L,1L,False,True,0.0,1.0,0.0j,1.0j,
'','a',u'',u'a',
(),(1,),[],[1],bytearray(),bytearray('31'),
set(),set('ab'),frozenset(),frozenset('ab'),
{},{'a':0},b, Test, Test.__init__,(a for a in 'a')]:
print b(x), bool(x), type(x)
```
Think I've forgotten some types ;-)
```
b(x) bool(x) type(x)
False False <type 'NoneType'>
True True <type 'NotImplementedType'>
True True <type 'ellipsis'>
False False <type 'int'>
True True <type 'int'>
False False <type 'long'>
True True <type 'long'>
False False <type 'bool'>
True True <type 'bool'>
False False <type 'float'>
True True <type 'float'>
False False <type 'complex'>
True True <type 'complex'>
False False <type 'str'>
True True <type 'str'>
False False <type 'unicode'>
True True <type 'unicode'>
False False <type 'tuple'>
True True <type 'tuple'>
False False <type 'list'>
True True <type 'list'>
False False <type 'bytearray'>
True True <type 'bytearray'>
False False <type 'set'>
True True <type 'set'>
False False <type 'frozenset'>
True True <type 'frozenset'>
False False <type 'dict'>
True True <type 'dict'>
True True <type 'function'>
True True <type 'type'>
True True <type 'instancemethod'>
True True <type 'generator'>
```
[Answer]
# Bash
Bash only does integer arithmetic of numbers stored in strings. So this isn't really a proper answer as there are no floats. But I thought this was an interesting integer-only solution:
```
$ bool () { echo $(( (($1 * $1) + 2) % (($1 * $1) + 1) )); }
$ for i in {-5..5}; do bool $i; done
1
1
1
1
1
0
1
1
1
1
1
$
```
[Answer]
## Perl, 5 char
```
1-!$x
```
Works for integers, floating-point values, strings, and C. Although in Perl, these are all the same type.
] |
[Question]
[
**This question already has answers here**:
[Addition/Multiplication table generator](/questions/102197/addition-multiplication-table-generator)
(15 answers)
Closed 5 years ago.
I was looking for a very easy task to look how short of a code can be produced on a beginners exercise.
The goal is to produce a simple table that looks like this common java/c# code is about 4 lines. So get your golfing-languages ready ;) Try to align the matrix in any way it is readable.
```
1 2 3 .. 10
2 4 6 .. 20
3 6 9 .. 30
. . . .. .
10 20 30 .. 100
```
**EDIT:** The first answer below shows a propper alignment and solution
[Answer]
# [MATL](https://github.com/lmendo/MATL), 5 bytes
```
10:&*
```
[Try it online!](https://tio.run/##y00syfn/39DASk3r/38A "MATL – Try It Online")
```
10: % Range: [1,2,3,4,5,6,7,8,9,10]
&* % Multiply the range by itself transposed, with broadcasting.
```
Outputs:
```
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~48 45~~ 44 bytes
```
1.upto(10){|x|puts"%4d"*10%[*x.step(100,x)]}
```
[Try it online!](https://tio.run/##KypNqvz/31CvtKAkX8PQQLO6pqKmoLSkWEFJ1SRFScvQQDVaq0KvuCS1AChroFOhGVv7/z8A "Ruby – Try It Online")
-3 bytes thanks to manatwork then -1 thanks to Kirill L.
But I still think there must be a better way.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 [bytes](https://github.com/DennisMitchell/jellylanguage/wiki/Code-page)
```
⁵×þ`G
```
[Try it online!](https://tio.run/##y0rNyan8//9R49bD0w/vS3D//x8A "Jelly – Try It Online")
Prints the following text:
```
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
```
[Another 5-byter](https://tio.run/##y0rNyan8//9R49bD0x81rQly//8fAA).
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~18~~ 17 bytes
*1 byte saved thanks to [@StewieGriffin](https://codegolf.stackexchange.com/users/31516/stewie-griffin)*
```
disp((x=1:10)'*x)
```
[Try it online!](https://tio.run/##y08uSSxL/f8/JbO4QEOjwtbQytBAU12rQvP/fwA "Octave – Try It Online")
Or, as [@maxb](https://codegolf.stackexchange.com/users/79994/maxb) points out: more readable, same length:
```
x=1:10;disp(x'*x)
```
[Answer]
# [R](https://www.r-project.org/), 32 bytes
```
write(format((x=1:10)%o%x),1,10)
```
[Try it online!](https://tio.run/##K/r/v7wosyRVIy2/KDexREOjwtbQytBAUzVftUJTx1AHyPz/HwA "R – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~64~~ 55 bytes
```
i=1
exec"print'%4d'*10%tuple(range(i,11*i,i));i+=1;"*10
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P9PWkCu1IjVZqaAoM69EXdUkRV3L0EC1pLQgJ1WjKDEvPVUjU8fQUCtTJ1NT0zpT29bQWgmo4P9/AA "Python 2 – Try It Online")
[Answer]
# APL+WIN, 9 bytes
```
n∘.×n←⍳10
```
[Try it online! Courtesy of Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcjzra0/7nPeqYoXd4eh5Q5FHvZkOD/0DR/2kA "APL (Dyalog Classic) – Try It Online")
Outer product multiplication of a vector of integers 1 to 10
[Answer]
# Brainfuck, 1147 bytes
```
++[[<+++>-->----<]>]<<<<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<--------.-.<<+.>>++.>..<++.>..<++.>..<++.>..<-------.-.>.<+.+.>.<-.+++.>.<---.+++++.>.<-----.+++++++.>.<------.--.<<.>>+++.>..<+++.>..<+++.>..<--------.+.>.<-.++++.>.<----.+++++++.>.<------.-.>.<+.++.>.<--.+++++.>.<----.---.<<.>>++++.>..<++++.>..<-------.+.>.<-.+++++.>.<----.--.>.<++.++.>.<--.++++++.>.<-----.-.>.<+.+++.>.<--.----.<<.>>+++++.>..<----.-.>.<+.++++.>.<---.--.>.<++.+++.>.<--.---.>.<+++.++.>.<-.----.>.<++++.+.>.<.-----.<<.>>++++++.>..<-----.+.>.<-.+++++++.>.<------.++.>.<-.---.>.<+++.+++.>.<--.--.>.<++.++++.>.<---.-.>.<++.------.<<.>>+++++++.>..<------.+++.>.<--.-.>.<+.++++++.>.<-----.++.>.<-.--.>.<++.+++++.>.<----.+.>.<.---.>.<++++.-------.<<.>>++++++++.>..<-------.+++++.>.<----.++.>.<-.-.>.<++.----.>.<++++.++++.>.<---.+.>.<.--.>.<+++.-----.>.<++++++.--------.<<.>>+++++++++.>..<--------.+++++++.>.<------.+++++.>.<----.+++.>.<--.+.>.<.-.>.<++.---.>.<++++.-----.>.<++++++.-------.>.<++++++++.---------.<<.>>+.-.>.<++.--.>.<+++.---.>.<++++.----.>.<+++++.-----.>.<++++++.------.>.<+++++++.-------.>.<++++++++.--------.>.<+++++++++.---------.>.<+.-..
```
[Try it online!](https://tio.run/##lZLdCsIwDIUfKCRPUPoiwwsVBBG8EHz@ubX5Oemq4BjrljXnO0lzeZ3vz9v7@lhXomUpRFSZt5u5nOqpbBdJFfn7yXoJS5OopH9nS@yte/4eLCxE/YXbq3/YJwS2zB3TKCacV7cT2p4@k1MjGst8YaA5JlcCGMxrsqMuFOZc28CJFQzY6U0CeUjvMWd2xaqWW0x4oEApqZDUItALRHDDSvjTGB942DtUiRrz6RsZIHCaVpNXyRPicFzDPCgADEfLcCwVZQ1g3BnggTxO5KS1w3TatHRcuMoVHsERATPmBoTAf5L0/C8A0P@JxCAaacfLIuv6AQ)
Thanks for [Jo King](https://codegolf.stackexchange.com/users/76162/jo-king) for this solution !
## Old answer, 1164 bytes
```
+++++[>+++++[>++>+<<-]>>+>++<<<<-]>>-->++<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<--------.-.>>.<<++.>..<++.>..<++.>..<++.>..<-------.-.>.<+.+.>.<-.+++.<.>---.+++++.<.>-----.+++++++.<.>------.--.>>.<<+++.>..<+++.>..<+++.>..<--------.+.>.<-.++++.>.<----.+++++++.>.<------.-.>.<+.++.>.<--.+++++.>.<----.---.>>.<<++++.>..<++++.>..<-------.+.>.<-.+++++.>.<----.--.>.<++.++.>.<--.++++++.>.<-----.-.>.<+.+++.>.<--.----.>>.<<+++++.>..<----.-.>.<+.++++.>.<---.--.>.<++.+++.>.<--.---.>.<+++.++.>.<-.----.>.<++++.+.>.<.-----.>>.<<++++++.>..<-----.+.>.<-.+++++++.>.<------.++.>.<-.---.>.<+++.+++.>.<--.--.>.<++.++++.>.<---.-.>.<++.------.>>.<<+++++++.>..<------.+++.>.<--.-.>.<+.++++++.>.<-----.++.>.<-.--.>.<++.+++++.>.<----.+.>.<.---.>.<++++.-------.>>.<<++++++++.>..<-------.+++++.>.<----.++.>.<-.-.>.<++.----.>.<++++.++++.>.<---.+.>.<.--.>.<+++.-----.>.<++++++.--------.>>.<<+++++++++.>..<--------.+++++++.>.<------.+++++.>.<----.+++.>.<--.+.>.<.-.>.<++.---.>.<++++.-----.>.<++++++.-------.>.<++++++++.---------.>>.<<+.-.>.<++.--.>.<+++.---.>.<++++.----.>.<+++++.-----.>.<++++++.------.>.<+++++++.-------.>.<++++++++.--------.>.<+++++++++.---------.>.<+.-..
```
[Try it online!](https://tio.run/##lZJbCgIxDEUXVJIVlGxE/FBBEMEPwfWPfeRxU0fBfkzbtLnnJtPz83R7XF@X@7aVPg7ik5Ra6SjSFm0110R9U1iY//6SDiYW4VqLHu5NcLWn92Albsa4svSD4VI3toVAy3SKCefZ3YT2XKGc2D03ojFO50xAc0yuBDCYN2RX3QAH1y5QYgUDblo6ykP6jDlTFdXyiDEtFCglFZJaBHqBCG5YCX8aow8e9g5VokZsUpABAn/TavIqaYe4/K7lPSgADEfLoCJDWQMIbwZ4Ia8vcqe1y@u01zJx4SpX@AmOCJgxNyAE/pOk538BgP5PJAaTER42eNve)
Oh god, this ended up way longer than I expected.
Here is how i did it :
```
Store values 48 ('0'), 32 (space) and 10 (new line)
+++++[>+++++[>++>+<<-]>>+>++<<<<-]>>-->++<
Print 1st line
+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<--------.-.>>.<<
Print 2nd line
++.>..<++.>..<++.>..<++.>..<-------.-.>.<+.+.>.<-.+++.<.>---.+++++.<.>-----.+++++++.<.>------.--.>>.<<
Etc.
+++.>..<+++.>..<+++.>..<--------.+.>.<-.++++.>.<----.+++++++.>.<------.-.>.<+.++.>.<--.+++++.>.<----.---.>>.<< Etc.
++++.>..<++++.>..<-------.+.>.<-.+++++.>.<----.--.>.<++.++.>.<--.++++++.>.<-----.-.>.<+.+++.>.<--.----.>>.<<
+++++.>..<----.-.>.<+.++++.>.<---.--.>.<++.+++.>.<--.---.>.<+++.++.>.<-.----.>.<++++.+.>.<.-----.>>.<<
++++++.>..<-----.+.>.<-.+++++++.>.<------.++.>.<-.---.>.<+++.+++.>.<--.--.>.<++.++++.>.<---.-.>.<++.------.>>.<<
+++++++.>..<------.+++.>.<--.-.>.<+.++++++.>.<-----.++.>.<-.--.>.<++.+++++.>.<----.+.>.<.---.>.<++++.-------.>>.<<
++++++++.>..<-------.+++++.>.<----.++.>.<-.-.>.<++.----.>.<++++.++++.>.<---.+.>.<.--.>.<+++.-----.>.<++++++.--------.>>.<<
+++++++++.>..<--------.+++++++.>.<------.+++++.>.<----.+++.>.<--.+.>.<.-.>.<++.---.>.<++++.-----.>.<++++++.-------.>.<++++++++.---------.>>.<<
+.-.>.<++.--.>.<+++.---.>.<++++.----.>.<+++++.-----.>.<++++++.------.>.<+++++++.-------.>.<++++++++.--------.>.<+++++++++.---------.>.<+.-..
```
[Answer]
## Batch, 177 bytes
```
@echo off
for /l %%i in (1,1,10)do call:r %%i
exit/b
:r
set s=
for /l %%j in (1,1,10)do set/an=%1*%%j&call:c
echo %s%
:c
set n= %n%
if "%n:~3%"=="" goto c
set s=%s%%n%
```
[Answer]
# [J](http://jsoftware.com/), 9 bytes
```
*/~1+i.10
```
[Try it online!](https://tio.run/##y/r/PzU5I19Lv85QO1PP0OD/fwA "J – Try It Online")
[Answer]
# [Red](http://www.red-lang.org), 56 bytes
```
repeat n 10[repeat m 10[prin pad rejoin[n * m]4]print""]
```
[Try it online!](https://tio.run/##K0pN@R@UmhId@78otSA1sUQhT8HQIBrKzgWxC4oy8xQKElMUilKz8jPzovMUtBRyY01iQeIlSkqx//8DAA "Red – Try It Online")
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~24~~ 23 bytes
```
A,:)_m*{:*"%4d"e%}%A/:n
```
[Try it online!](https://tio.run/##S85KzP3/31HHSjM@V6vaSktJ1SRFKVW1VtVR3yrv/38A "CJam – Try It Online")
Alternative without pretty printing:
```
A,:)_m*{:*}%A/:p
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 79 bytes
```
(_=[...".........."])=>_.map((a,i)=>Array.from({length:10},(v,k)=>(k+1)*(i+1)))
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@18j3jZaT09PSQ8OlGI1be3i9XITCzQ0EnUygRzHoqLESr20ovxcjeqc1Lz0kgwrQ4NaHY0ynWygrEa2tqGmlkYmkNTU/J@cn1ecn5Oql5OfrpGmARQAAA "JavaScript (Node.js) – Try It Online")
] |
[Question]
[
**Closed**. This question needs to be more [focused](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Update the question so it focuses on one problem only by [editing this post](/posts/145760/edit).
Closed 6 years ago.
[Improve this question](/posts/145760/edit)
WPA2, the actual encryption standard that secures all modern wifi networks, has been **cracked**... This challenge has nothing to do with the way that the WPA2 was cracked, however is is about computing the 64-digit hexadecimal key that corresponds to a given WPA-PSK pass-phrase.
A wireless network with WPA-PSK encryption requires a pass-phrase to be entered to get access to the network. Most wireless drivers accept the pass-phrase as a string of at most 63 characters, and internally convert the pass-phrase to a 256-bit key. However, some systems also allow the key to be entered directly in the form of 64 hexadecimal digits. So the challenge is to calculate the 64-digit hexadecimal key that corresponds to a given pass-phrase.
The hexadecimal key is computed from the pass-phrase and the network **SSID** (an SSID is a unique ID that consists of 32 characters).
**Details of the calculation**
For WPA-PSK encryption, the binary key is derived from the pass-phrase according to the following formula: `Key = PBKDF2(pass-phrase, SSID, 4096, 256)`
The function `PBKDF2` is a standardized method to derive a key from a pass-phrase.
It is specified in [RFC2898](http://www.ietf.org/rfc/rfc2898.txt) with a clear explanation on how to compute it.
The function needs an underlying pseudo-random function.
In the case of WPA, the underlying function is `HMAC-SHA1`.
`SHA1` is a function that computes a 160-bit hash from an arbitrary amount of input data.
It is clearly explained in [RFC3174](http://www.ietf.org/rfc/rfc3174.txt).
`HMAC` is a standardized method to turn a cryptographic hash function into a keyed message authentication function.
It is specified in [RFC2104](http://www.ietf.org/rfc/rfc2104).
To summarize, the key derivation process involves iterating a `HMAC-SHA1` function 4096 times, and then doing that again to produce more key bits.
**Inputs**
* SSID a string of at most 32 characters (e.g. `stackexchange`)
* pass-phrase a string of at most 63 characters (e.g. `<ra(<@2tAc<$`)
**Output** any reasonable output of the 64 hexadecimal digits
* e.g.
`24343f69e98d3c08236a6db407584227cf2d1222b050e48f0cf25dee6563cd55`
* it is the result of the previous inputs
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so please make your program as short as possible!
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform) lambda expression, 88 82 81 bytes
Takes input as byte arrays (curried, see comments), returns key as byte array.
```
p=>s=>new System.Security.Cryptography.Rfc2898DeriveBytes(p,s,4096).GetBytes(32);
```
[Try it online!](https://tio.run/##dZFPTwIxEMXv@ykmGw@7ydIYNAayf6KgeNHEAMYD4VDLsDRAt@mUlY3hs69dNggePDTtvPw6b14rqCMKg/WOpMphUpHFbexdVmyKext7nuJbJM0FwpspcsO33rcHIDac6FcBaDQAstxKAWUhF/DKpQrIGtdxNgducgqPTEsCjHZKJJ@Vxdk8ujy3W5Yt01qnGaWZwq/TSBMUOyNtxYam0rbx1quKjZei2@v3HtHIEgfuOgU6ouj2un8Xsme0rXTTDeO6tS65Ae3m1yvDCSEFPzE8SO679kEkV37snTEiF8UBLplY416suMrxD7HGygHL4EmJYuHCsvfpqHe2PfuE4X9MYxKGp6bDQlGxQfbhkuKLVBgMpHViicaiYdNicnzUwBmHbIx64/4m8Dt@5PunJgevWYf6Bw "C# (.NET Core) – Try It Online")
[Answer]
# Java, ~~192~~ 88 + 36 = 124 bytes
36 bytes for `import de.rtner.security.auth.spi.*;`
`a` is the SSID taken as a byte array, `b` is the password taken as a string. Outputs byte array. Requires [PBKDF2](https://github.com/m9aertner/PBKDF2/).
```
a->b->new PBKDF2Engine(new PBKDF2Parameters("HmacSHA1","UTF-8",a,4096)).deriveKey(b,32);
```
### Old answer:
Takes SSID as char array and password as byte array. Outputs byte array.
```
a->b->{try{return javax.crypto.SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new javax.crypto.spec.PBEKeySpec(a,b,4096,256)).getEncoded();}catch(Exception e){return null;}}
```
[Try it online!](https://tio.run/##VVFNi9swED0rv0KEFmRIRDa0C23S0KRN2LIUFnzoIeQgy5NEWVsy0ngbE/zb3VHtpV0dJPFm3nvzcVEvauoqsJf8uTNl5TzyC2GyRlPIY201GmflbvgsRlWdFUZzXagQ@E9lLL@N2AAGVEjPizM5LykkUvTGnvYHrvwpJJTJh/Oqt9Rn5feHyT8gaxAi0L@rFT/yL7xT01U2Xd3QNzcPWHv7t8ir1L6p0MkUNMGP0OyURucbeQL8Yakcq0GMnzaP33fzXwbPD6XS6cP6bpxQhgWvEHqqsPD7rWSoQMunzZZEU/oKNckmH2af7ifzj/dJpOPWapdDLpJFqxXqs9heNVSxCQ7Ja5m2LopF23aMLUaM9U1xD6EukPo6SlVVRSPiePazg0T3jeax9l41gkz@C94douWG@IEiUauf7aY2RQ6eh4zkYhNvYKqNRs7Y0XkuojnP@OfBPq6DMRayaAM2H5YlKbdUKMbvZ/PrmPYQ3UiijVfaBIRSuhplRckoiI2uJ/ZltaO265ZeieXXOa718l1HW9DPcKVF2xP8AQ "Java (OpenJDK 8) – Try It Online")
] |
[Question]
[
**This question already has answers here**:
[We're no strangers to code golf, you know the rules, and so do I](/questions/6043/were-no-strangers-to-code-golf-you-know-the-rules-and-so-do-i)
(73 answers)
Closed 7 years ago.
Your task is to print the following:
```
I have a pen
I have an apple
Uh! Apple pen!
I have a pen
I have pineapple
Uh! Pineapple pen!
Apple pen...
Pineapple pen...
Uh! Pen Pineapple Apple Pen!
```
Remember, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the smallest number of bytes wins.
### Leaderboards
Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.
To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:
```
# Language Name, N bytes
```
where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:
```
# Ruby, <s>104</s> <s>101</s> 96 bytes
```
If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:
```
# Perl, 43 + 2 (-p flag) = 45 bytes
```
You can also make the language name a link which will then show up in the leaderboard snippet:
```
# [><>](http://esolangs.org/wiki/Fish), 121 bytes
```
```
var QUESTION_ID=95124,OVERRIDE_USER=12537;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```
[Answer]
# [Bubblegum](https://esolangs.org/wiki/Bubblegum), 72 bytes
```
00000000: f354 c848 2c4b 5548 5428 48cd e3f2 8472 .T.H,KUHT(H....r
00000010: f214 120b 0a72 52b9 4233 1415 1c41 2c90 .....rR.B3...A,.
00000020: ac22 175c 1e59 7141 665e 2a42 7500 8c07 .".\.YqAf^*Bu...
00000030: d501 d7ad a7a7 c785 2209 1200 eb48 cd43 ........"....H.C
00000040: d205 510f 1453 0400 ..Q..S..
```
[Try it online!](http://bubblegum.tryitonline.net/#code=MDAwMDAwMDA6IGYzNTQgYzg0OCAyYzRiIDU1NDggNTQyOCA0OGNkIGUzZjIgODQ3MiAgLlQuSCxLVUhUKEguLi4ucgowMDAwMDAxMDogZjIxNCAxMjBiIDBhNzIgNTJiOSA0MjMzIDE0MTUgMWM0MSAyYzkwICAuLi4uLnJSLkIzLi4uQSwuCjAwMDAwMDIwOiBhYzIyIDE3NWMgMWU1OSA3MTQxIDY2NWUgMmE0MiA3NTAwIDhjMDcgIC4iLlwuWXFBZl4qQnUuLi4KMDAwMDAwMzA6IGQ1MDEgZDdhZCBhN2E3IGM3ODUgMjIwOSAxMjAwIGViNDggY2Q0MyAgLi4uLi4uLi4iLi4uLkguQwowMDAwMDA0MDogZDIwNSA1MTBmIDE0NTMgMDQwMCAgICAgICAgICAgICAgICAgICAgICAuLlEuLlMuLg&input=)
The above is the `xxd` hexdump of the actual code.
[Answer]
## JavaScript (ES6), ~~145~~ 143 bytes
```
_=>`P325|I have |pple|inea|
Uh! | pen`.split`|`.reduce((s,r,i)=>s.split(i).join(r),`1a5
1an a24A25!
1a5
1p3240!
A25...
0...4Pen P32 A2 Pen!`)
```
```
let f =
_=>`P325|I have |pple|inea|
Uh! | pen`.split`|`.reduce((s,r,i)=>s.split(i).join(r),`1a5
1an a24A25!
1a5
1p3240!
A25...
0...4Pen P32 A2 Pen!`)
console.log(f());
```
[Answer]
# [///](http://esolangs.org/wiki////), 117 bytes
```
/@/I have //#/apple//$/Apple //&/Uh! //%/pen//*/Pine/@a %
@an #
&$%!
@a %
@pine#
&*# %!
$%...
*# %...
&Pen *# $Pen!
```
[Try it online!](http://slashes.tryitonline.net/#code=L0AvSSBoYXZlIC8vIy9hcHBsZS8vJC9BcHBsZSAvLyYvVWghIC8vJS9wZW4vLyovUGluZS9AYSAlCkBhbiAjCiYkJSEKCkBhICUKQHBpbmUjCiYqIyAlIQoKJCUuLi4KKiMgJS4uLgomUGVuICojICRQZW4h&input=)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 94 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
“/¢ȷKcḞvßÇwݵɼUṡ]nk]¹¤%Ƭ*|ẊƓẸḢÇ2ẋbịʋ]dṀ⁸)ṇẎ⁶ėDṭD’b⁴ị“I“have“a“p“en“¶“n“A“pple“Uh“!“ine“P“...“
```
**[TryItOnline](http://jelly.tryitonline.net/#code=4oCcL8KiyLdLY-G4nnbDn8OHd8SwwrXJvFXhuaFdbmtdwrnCpCXGrCp84bqKxpPhurjhuKLDhzLhuoti4buLyotdZOG5gOKBuCnhuYfhuo7igbbEl0Thua1E4oCZYuKBtOG7i-KAnEnigJxoYXZl4oCcYeKAnHDigJxlbuKAnMK24oCcbuKAnEHigJxwcGxl4oCcVWjigJwh4oCcaW5l4oCcUOKAnC4uLuKAnCA&input=&args=)**
How?
Manual compression:
I looked for strings that repeated and made a list, there were 15.
I ordered these like so:
`“I“have“a“p“en“¶“n“A“pple“Uh“!“ine“P“...“`
so as to make the smallest base-16 number from the text (with no leading 0)
here: `“` separates; `¶` represents a line feed; and the last entry (index 0) is a space.
I then converted the number to base-250 and wrote it out in the first 250 of the 256 characters in the Jelly code-page:
`/¢ȷKcḞvßÇwݵɼUṡ]nk]¹¤%Ƭ*|ẊƓẸḢÇ2ẋbịʋ]dṀ⁸)ṇẎ⁶ėDṭD`
The code the inverses the same process:
“(base-250-encoded-number)’
b⁴ị - base 16, index into
`“I“have“a“p“en“¶“n“A“pple“Uh“!“ine“P“...“`
Note: base-15 would have the same byte-count, one less in the encoded number but one more to decode as literal 15 is `15` whereas literal 16 is `⁴`. Maybe a substring list of 16 items could cost less in total.
[Answer]
# Perl, 139 bytes
With UNIX line terminators (`LF` = one byte) :
```
s//0an a1
5A12!
0p4
5P42!
A123P4235Pen P4A1Pen!/;s/4/inea1/g;s/0/I have a pen
I have /g;s/1/pple /g;s/2/pen/g;s/3/...
/g;s/5/Uh! /g;print
```
[Answer]
## Batch, 203 bytes
```
@echo off
set e=echo(
call:l "an a" A
call:l pinea Pinea
%e%Apple pen...
%e%Pineapple pen...
%e%Uh! Pen Pineapple Apple Pen!
exit/b
:l
%e%I have a pen
%e%I have %~1pple
%e%Uh! %2pple pen!
%e%
```
Batch is so verbose that the `set e=echo(` saves a whole byte. (Worth it of course for code golf purposes.)
] |
[Question]
[
In this meta-challenge, you will score your own [atomic-code-golf](/questions/tagged/atomic-code-golf "show questions tagged 'atomic-code-golf'") submissions. More precisely, you will need to write a program P in language L such that the atomic-score of P is produced by P.
## Score
[The idea](http://meta.codegolf.stackexchange.com/questions/403/new-code-golf-metric-atomic-code-golf) behind [atomic-code-golf](/questions/tagged/atomic-code-golf "show questions tagged 'atomic-code-golf'") is to count language *tokens* instead of bytes. However, in practice, it is hard to define a general set of rules for all questions (see [Count big-ints/symbols/variables as N tokens in atomic-code-golf](http://meta.codegolf.stackexchange.com/questions/2567/count-big-ints-symbols-variables-as-n-tokens-in-atomic-code-golf)). That's why it is recommended to clarify rules for each challenge.
Intuitively, tokens are nodes in the abstract syntax tree of your language, except for strings, where each character count (due to potential abuse).
1. Things that count as single tokens:
* variable/function/type identifiers
* literals, except strings, where each byte counts
* built-in keywords and operators
* *(edit)* Empty lists, empty vectors, empty strings
2. Things that are **ignored** from counting:
* preprocessor/reader macros
* include/import statements
* *separating* and *grouping symbols* used to build tuples, lists, arrays, statements, function parameters, structs are ignored (`,;:(){}[]<>|`). However, if those symbols are tokens, they count (I am looking at you, CJam (or Brainfuck)). Also, quotes enclosing strings are not counted.
3. Corner cases
* Using identifiers to hold data is a nice hack (see feersum's comment), but it might be considered abusive. So, there should be a penaly of **+25** if your answer exploits identifiers' names for computations. This penalty needs not be correctly scored by your program. If you manage to add a penalty to programs which abuse identifiers' names for computation (for a reasonable subset of programs in your language), you deserve **-100** points of bonus (this bonus needs not be correctly scored by your program).
## Challenge
You should write a program in the language of your choice that scores programs in that language according to the above atomic-score rules. Your own answer will be scored according to that program.
* Input may be read from STDIN or given as a function parameter
* Output is a number, as a return value or printed to STDOUT
* Answer with lowest atomic-score wins
* I'll provide an example answer (if it has the lowest score, the next one wins).
[Answer]
# [Unary](http://esolangs.org/wiki/Unary), 1
The program is a string of `47297560408284` zeroes
**i.e.**
```
000000000000000000000000000000000000000000.... 47297560408284 times
```
A brainfuck quivalent code would be
```
+[>+<+++++]>--.
```
which just prints `1`
as in unary, the whole program is made up of just `0` which are all a single token.
[Answer]
## Common Lisp - ~~23~~ 26
Here is the example answer:
```
(labels ((sum (s form)
(if (typep form 'sequence)
(max (1+ s) (reduce #'sum form :initial-value s))
(1+ s))))
(defmacro atomic-count (form) (sum 0 form)))
```
And here we can see the macro scoring itself:
```
(atomic-count
(labels ((sum (s form)
(if (typep form 'sequence)
(max (1+ s) (reduce #'sum form :initial-value s))
(1+ s))))
(defmacro atomic-count (form) (sum 0 form))))
=> 26
```
NB. This never terminates (or, badly) with cyclic expressions built with `#1=` and `#1#` reader macros.
*(edit) Empty sequences should count as 1 token*
] |
[Question]
[
**Closed**. This question needs to be more [focused](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Update the question so it focuses on one problem only by [editing this post](/posts/19912/edit).
Closed 6 years ago.
[Improve this question](/posts/19912/edit)
TASK:
Make an acrostic poem in the lines.
e.g.
BATCH
```
break
attrib -h acrostic.txt
type acrostic.txt
cls
help
```
The output CAN also be an acrostic poem.
RULES:
* Popularity Contest - the answer with highest vote wins!
* You may create more than one.
* Any language is accepted.
* Every line must be executable.
[Answer]
**Java**
```
class s {
//acrostic starts below this line
public static void main(String[] args) { int
a; int
n;
class b {}
a=1; int
k; int
e;
System.out.println("are very tasteful."); } }
```
[Answer]
# bash - every man dies alone
This line writes the poem:
```
echo echo view echo renice yes make apropos nice date identify echo start apropos locate octave nice echo | xargs -n 1 | awk '{s = s substr($1, 1, 1); if ($1 == "echo"){print $1, "-n", s; s = "";}else print $1, "--they >.said 2>&1";}' > acrostic.sh
```
To see the poem:
```
$ cat acrostic.sh
```
To see the poem within the poem:
```
$ sh acrostic.sh
```
[Answer]
## Batch
Quite lazy, I'll admit -
```
@(
Code
Other than that which
Does
Echo Code^
Golf
Often
Lacks the
Fun
) 2>nul
```
```
H:\uprof>accro.bat
CodeGolf
```
[Answer]
Yay! **Java**!
```
import java.io.*;public
class poem{static String[]
a =
new String[1];
public static void main(String[] args){a();fin();
return;}static
Object myMethod(){String
g = "This is my ";
return g;} static void a(){
a[0] = "output";}static boolean fin(){System.out.println(
myMethod().toString()+a[0]);Boolean fin =
!(0==1);return fin;}}
```
[Answer]
# Befunge-93
```
go down, "Dev" 00ps -- 2*4-10 \ please
um I guess 1 - 3 \, is that right "hmm", @
maybe
```
run as `./befungee.py acrostic` for the output `gum`.
Note sure how rule #3 should be interpreted in this context.
[Answer]
**Ruby**
```
ruby = "rubylicious"; control = true
unless (!ruby)
begin y = ruby
y.each_char do |l| print (
l)
if (l=='s') then
control=false end
if (!control) then puts "!" end
over = true
unless
self == true then over = false end end end end
```
This prints `Rubylicious!`. I am not happy with some of the lines (especially last line), so future edits are possible.
[Answer]
# Javascript
```
document.getElementById("dog).appendChild(document.createElement('div'));
o = [];
e = [];
s = [];
t = 0;
h = 0;
i = 0;
s[0] = 0;
e[0] = 0;
v = 0;
e[1] = 0;
n = [];
c = 0;
o[0] = 0;
u = 0;
n[0] = 0;
t
? count=1:count=0;
```
] |
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win.
Closed 10 years ago.
[Improve this question](/posts/16991/edit)
Let's waste some time coming up with stupid ideas which are close cousins of good ideas.
* Your useless command doesn't have to fit any minimum or maximum length.
* Do, however, try to turn it into a one-liner if you can.
* No particular requirement for what shells and utilities are used, within reason.
* He who wins, wins.
* More rules will be added if they are added.
[Answer]
Mine is the inverse of "print the kernel arguments you booted with on Linux":
```
cat /proc/cmdline
# turns into...
fgrep -x -f <(awk -F\= 'BEGIN { RS = " "} ; {print $1"="}' </proc/cmdline)\
-v <(curl 'https://www.kernel.org/doc/Documentation/kernel-parameters.txt'
2>/dev/null | awk '/\t+[a-z._]+=/ {print $1}' | tee test2) | tr '\n' ' ' &&
echo
```

[Answer]
```
ls > /dev/null
```
Simple yet utterly pointless. :-P
For people who don't know shell commands: `ls` lists the files in a directory, and `> /dev/null` basically hides the output.
[Answer]
Once or twice a week i tend to misspell `ls` so i run `sl`. It's not installed by default in Ubuntu (or perhaps other), so if no magic happens try installing it.
It's quite cool, at least the first few times, as it behaves differently with some common options to `ls` as well and it seems to have blocked signals so you cannot quit it until it's shown you what it can do...
[Answer]
Not sure if invoking python counts. This'll start a web server, open your default browser, and show the information you'd usually see on the console **`:-)`**
```
python -m SimpleHTTPServer &> index.html & x-www-browser localhost:8000
```
Press F5 a few times, and...
>
> 127.0.0.1 - - [31/Dec/2013 20:27:59] "GET / HTTP/1.1" 200 - 127.0.0.1 - - [31/Dec/2013 20:28:02] "GET / HTTP/1.1" 200 - 127.0.0.1 - - [31/Dec/2013 20:28:03] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:03] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:03] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:03] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:04] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:04] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:04] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:04] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:04] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:05] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:05] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:05] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:05] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:06] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:06] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:07] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:07] code 404, message File not found 127.0.0.1 - -
> [31/Dec/2013 20:28:07] "GET /favicon.ico HTTP/1.1" 404 - 127.0.0.1 - -
> [31/Dec/2013 20:28:07] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:08] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:08] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:08] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:08] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:08] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:09] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:09] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:09] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:09] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:09] "GET / HTTP/1.1" 200 - 127.0.0.1 - -
> [31/Dec/2013 20:28:10] "GET / HTTP/1.1" 200 -
>
>
>
To shut down the server, run the `fg` command, and then press Ctrl-C.
] |
[Question]
[
# Can you decrypt me?
## Robbers
Find any combination of \$n\$ working chars to change and what they should change into, where \$n\$ is chosen by the cop. You cannot change less than n chars, only exactly \$n\$.
## Example
```
print(2)
```
N is 1.
---
Robbers' post:
```
print(1)
```
## Scoring
For the robbers, the user with the most cracks wins. If there is a tie, then it is a tie.
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 49 bytes, \$n = 49\$, cracks [@l4m2's answer](https://codegolf.stackexchange.com/a/269272/92901)
```
"-[>->>-<<<---------]>-----"&console.log(196>>2.)
```
[Try it online!](https://tio.run/##SypKzMxLK03O/v9fSTfaTtfOTtfGxkYXBmLtwJSSWnJ@XnF@TqpeTn66hqGlmZ2dkZ7m//8A "brainfuck – Try It Online")
Polyglot with [JavaScript (Node.js)](https://tio.run/##y0osSyxOLsosKNHNy09J/f9fSTfaTtfOTtfGxkYXBmLtwJSSWnJ@XnF@TqpeTn66hqGlmZ2dkZ7m//8A "JavaScript (Node.js) – Try It Online"), just to keep things interesting.
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), [by enzo](https://codegolf.stackexchange.com/a/269188/53748) 723 bytes, n=9
Probably not as intended, but this works...
```
P=3
p=[i*(P+1)+1*(i//2)for i in range(P)]
v=[(p[2]*(p[1]+1)+1)+(p[1]-1)*i for i in p]
I=[x*2-1+(v[2]-v[1]+1)*(i//2)for i,x in enumerate(v[::-1])]
t=[vars(__builtins__)[dir(__builtins__)[i]]for i in I]
m='_'.join(vars(t[0])[dir(t[0])[i]].__name__ for i in v)
M=vars(__builtins__)[dir(__builtins__)[v[2]+1]](''.join(x.__name__[:len(t)-i]for i,x in enumerate(t)))
l=t[2](M,m[2:v[1]-v[0]+1]+m[v[2]-v[1]+t[1](t[0](v[2])[-1]):])[-1::-1]
PP=[len(dir(t[2]))-p[2]-1,len(m),sum(len(dir(x))for x in t)//sum(p)+len(p)-1,I[1]%(len(dir(t[1]))+len(dir(t[2]))),sum(p)-1,sum(I)//sum(v)+len(p)-1,sum(p)-1,p[2],I[1]%(len(dir(t[1]))+len(dir(t[2]))),v[2]-v[0]-len(v)-1]
print(9)#xxxxxxt[0])[dir(t[0])[sum(PP[:P])]](t[0](),[l[i-1]for i in PP])))
```
[Try it online!](https://tio.run/##jVLdboMgFL73KUyWpRyVWuzNZsIDeNGEe0KIy9zGopRYatzTO0CnTbOLeoGE8/2c84H5sV9nfXwx/TQxeowM5SpBLCWQkgSpPC/g49zHKlY67mv92SAGIhooR4YXInErEQEMadhjAomKV4oRUUX5mBSYpGhwDDzMhFvtbPTQRl@7pq9t43BliYlwPpbyoe4vSMq3q2qt0hcpgb@r/u5ECbFaViLq6E7u9t9npVGgW34QM23eOfheSl13jZRbrwNEJ/qQnR8kJUKg3eIyrnK8bBuNLGAl/p3NAkDUUusU0CnreFH6QFwqB6@YdnwLybolNByCA@4jKcM/xBMxRrk3m@dyCMD@TjDJ/GkH2eXaoT/ACCHr0I2FPPc1A6kvG3CUypk9o03Oec3VTX0WDGi/qRaV4UZlBfhGHtNc5j0I7CsD@MlMr7RFr/A0hu/@@rwLY7xk7oksCUHGW64cd71Nxrz8NP0C "Python 3.8 (pre-release) – Try It Online")
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), cracks [l4m2's answer](https://codegolf.stackexchange.com/a/269220/120591), 57 bytes, n=3
```
>++--+++++++++++++++++++++++++++++++++++++++++++++++++++.
```
[Try it online!](https://tio.run/##SypKzMxLK03O/v/fTltbV1ebdKD3/z8A "brainfuck – Try It Online")
I assume this is the intended one? n=3 doesn't offer many possiblilities.
[Answer]
# [Python](https://www.python.org), 669 bytes [Mukundan314's](https://codegolf.stackexchange.com/a/269227/76323)
```
import lzma
exec(lzma.decompress(b'\xe0\x00E\x00A]\x004\x9bJg\xb8R<s\xda\xb0\xe5\xbe\xe9\xde\t\x02\x8d\x9d\x02LW\x8bw\x87\xf3mkn1\xc5\xd9\xd6\xe9\xc9E\xf25\xd3\xd7\x01\x91\xc2FM4\xe5sW\xd6\xaaR\x07j\xe7\xa3\x80\x05b\xfcZ9\x0en5\xc2\x00\x01\x00\x00/\x00\xe0\x00\x86\x00y]\x002\x9d\x88\xce\xe12k^\xffi\x8eN\xf1\x83j-\xf5\\\x86\xd9\x01\xb6\xban\xb5_B\xcb@\xeeZ\x05u\x9c,a\xf3\xd1\xf5y\x96\xd0\xf6\x11\x82y\x13\x9cUb:j\x13\xa72\xccl_J\x90*\xf0\x1b[t\x84\xcb\xad\xff>qg\xf7\xe7\x93L\x04\x8fT\x91\xfe\xc9\xd1\x84]\x9f\xcd\xa6\x9e3W[\xbb\xcb/A\xbbZr\x9fq\xf5Wj\xe4\xe0\\\xadt)\xea\xee\xa7]\x80A1\x04\x8e\x9aM\x00', format=lzma.FORMAT_RAW, filters=[{'id': lzma.FILTER_LZMA2}]))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NVJda9tAEIQ-5lf4zXFJGn3Gp5CUqpBAg52CcBHY55o76a61Y9mOpFC5ob-kFPLS_qj-ms740gfdjlYzu7Or-_lnt2-_bjfPz78fW3sq_r76tax227rtrb9X6sh0pjgmelOaYlvtatM0x7ovO-PJzvOueaRznpHsEn37RXZaZJeN7EoFCJKJEQ1igpyRLbiB7EQJekk8yvGmv-EYys6G1f3Gl10BUUnBuRMWCTrZgNkQD5geWAmZwc04Ypcmd3SlMnwdrpADTYEuaDXWKFBMUcszm5g6mnZ1DtE7c8ANBtU54_4wW-DMCgEdR_GD-88oZ5fImTsgFBHh6hQoltJpaZ_FNbBWGxzx4j30-h0KmCktPaJscaI4Nvg-1XukKIYBi-izcICkH5L7SV-sHFZDeCqK9eIWee812FD4eob1iohdQClp8e0Dfokdum0k4Qh98V3YiVufNVyu6y4iDJtYJKBU6J6YMJ_BuGbBs5RoWpPyQKs5VxwdFibZrR0AKw5He3PuPfVf2iGVqDFX2T_p2W1dqfbqcKtuPmbjdLLI0hz55bo1dXM1e-ovy_5FzxE-jCbX2WI0HafBj_lg4G7py2X9f2n_AQ)
IDKY I brute-forced
[Answer]
# [Python](https://codegolf.stackexchange.com/a/269257/76323), 873 bytes
```
import lzma;exec(lzma.decompress(b'\xe0\x00\x86\x00\x7f]\x00\x05\t\x8c\x1f48\x17VAca7\xfc\xaf\xf6\xcd(?\xfa\x11\xf2f\x12\xa8\xe8\xd5\xeb!\x99\xe1\xe7\x81i\x94\x9ej\xf1\x95\x1f\xdd\x83\x11\x01\x84\xb8\xa9=\xe2\xa6\xe6\x88\x8b\xb0\x8a\xacWkV\xc4!\xb4\xaf\\c\xfa\xbc\xf9\xb1\xee\x04\'\xe7d0pJ3B\x02\xcbH\xa2u\r6\xe2>4\xb8\x8f\xe1\x99\x1bW\x8c\x0cT/\xd7wt.{_\x89\t\xb1Ws\xdc\x7f.\xcc\xd6\xb8\x0f\x874\x8eH\xb4\xccq\xb7UV\x00\x00\x01\x00\x00b\x00\x01\x00\x18a85aa25882b90aaa356ebd56b\x00\x01\x00\x008\x00\x01\x00\x006\x00\x01\x00\x007\x00\x01\x00\ndf940ede04a\x00\x01\x00\x000\x00\xe0\x00T\x00A]\x002\r\x88&\x926K\xd9\xf0vNM\xc8\xee\x93\xdfB\xf5\xf5t\x85\x88:\xf9\xa5\xe0\xeb`\xc4\xbdK\xf6s%\xe4\xdf\xae\x1a\xe1-\t\x91\xda\xab\xd0\x10\xea\xa1\x9d\xcd\xec\xe9\x95hD\xb8\xfb\x90\x8e\xe8\x9d\x99"\x14\x00\x00', format=lzma.FORMAT_RAW, filters=[{"id": lzma.FILTER_LZMA2}]).decode())
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XVPbbtNAEH3gR0IkaCLRsHa89m5RQEGACm1AikIiwVZhr6qhaYLtgqHiS3jpC3wUX8OZbPrQPIx3fHbmzOzZ2d9_Nz-a8_Xlzc2fqyYcin_3ynK1WVdN5-LnSj_xrbc98gbO2_VqU_m67pkD1XqmWgYTeVyLcBYdxlUD2Ko2CZnAt5iPrS5UGwDpgBUZ1vWewdPYTrCmgJMU24j3MMexmvuqlRIOIjzyRVICyGD-M3KASk5FEO6wO4xcDCYQZECj5QipxIuSHiYACoNNahzFtV18maObDKVMtm1P2diXoRXVDVX34M0UnbpwbPNm-Bz_oLXmGDnplaqIP326KytCbJqaT8wiisHs7DE6Lb43g-slIEkqmWRRA7Qk3wB8cFweSRhIRAFG4Y9jc9Z-hVO8n-90ZvGw0Td3gURowbVOuRCpkUxrPeS5N47nZj9T7AP5PlDcAS5dkBnzzrNM70fu2oqzMaPPeDsVqapI_IfQJM1PcEgoE9i3txOcSkR9Je7PBQgbOBmNEKeco3gNmkdabz7RfUEId0KjVD8AllEqYkCTaNL-kMSVaMvRJePIjjShdPqnq3E0g_iH4l7SJJ2_iLoHREsaDx9HkSKl7CI9uz3lwaNOWFcr3Yy2D-PVu-lkPFtOxwvg5UXjq3r08bpbuu5RJwa8Pp29nC5PP0zG6a-z_vYlOd_r9-OL2z282wf4Hw)
[Actually even the part you don't specify can change](https://tio.run/##rVPvb9MwEP3c/hVeJWijleGkSeNUBCiCabAOpKqsEk017NhhoT9JA2RM/O3lXVw@rOIjH2xf3t29Oz9ftnfl7Wbd2@/z1XZTlGz5ayWbzVGs2klleFJxLNG3Z5jNrcGDpAScJpWb@QJ7eD1MZZhUGSCZ4URGqjsvYEm4XZweYNeDG/EGSwc41UlSRREMRBjkCzcH4GOZr8gBGgVUBOEa3p7l4lgCQQo0MoqRSrwoabAEQKHgpMZRXKbTxTW68VFK@XV7SWr7UnSiuqLqBrx@QrcONd@@673CN2hTdYEc73tSEL/3/FBWZLZpat5VUysGTydP0Wn4szy7vwEUkUrKne4ApiTfGfhg6L4l4SARIRiFubDNpek3GOHH64PO3F7W2v5DwBVSBFJ6gRCeiriUshf0jdJBXx1npsdA/xgIHgBrnUU@N9pwXx5H9qxhZ2NC27CeCi8pSPzH0MTrX@KSUCbjP95f4VbC6hshV2cQNgto0QgFlDOwzyADS2vUZ3ovCKEvaZR2j4D5lIoY0LiStH9C4kZoS9Mj48qaNKF0@qan0TSD@MbtTUSTdPva6p4hOqLxMHYUKTKKWkj/KzFvN5Vicf03nGmTblbbwux2nVGXZZtiJcu49px/GF8NJzfj4RR4vixNsYtn961ctwY29fztaPJmfDP6dDX0fs@dmkqbjtPcFvm6ZB2lnCYIWc7yNSvk@ovpLM26M3KcQbPRKIs7OhrlvzqZ8UE@P1Xtl@3T0Sw/dQfz/9UbKuYZK9lJzJSqG2joCi3MZouuUrPFvFtim1M1tnjYOO7jMCTXYSdxHVcTACO/rhz2jAWWtHEQoeyyvMvgAmqq1GzL2t9q7fd/AA)
[Answer]
# [///](https://esolangs.org/wiki////), 8271 bytes, n=2, [by Fmbalbuena](https://codegolf.stackexchange.com/a/269298/25180)
```
/~-/-~~//-~/~\--//-*///*\*/76543//~~~~~~~~~~~~%%%/*2*//~///*///%/4//-//~~~--********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************%%%
^ ^
```
[Try it online!](https://tio.run/##7cs7CoBADEXR1aQJhAd@N2NjIVjYTZ@tj9HKLQj3QEKKm3bt7Txa78pQZKqWcouowyX55lqXeRql/DAz@VBBPk2NaaqPN4pwAAAAAAAAAAAAAADwe2bW@w0 "/// – Try It Online")
### Alternative solution
```
/~-/-~~//-~/~%--//-*///*\*/76543//~~~~~~~~~~~~%%%/***//~///*///%/4//-//2/~--********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************%%%
^^
```
[Try it online!](https://tio.run/##7cwxCoBADETR06QJhAFd9TI2FoKF3fa5@ho7ryD8BwlTTNLvo19nH0MZikzVUlpEBZfku2tblzZL@WFmcq9Cvp0aU6sLaao/4QAAAAAAAAAAAAAA4PfMbIwH "/// – Try It Online")
Not a good choice of language.
[Answer]
# [C++ (gcc)](https://codegolf.stackexchange.com/a/269337/76323), 5204 bytes
```
#include <iostream>
using namespace std;
string secret = "secret";
void f1(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"611111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f2(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f3(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f4(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f5(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f6(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f7(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
int main() {
f1();
/*();
f3();
f4();
f5();
f6();
f7();
cout<<6;
f1();
f2();
f3();
f4();
f5();
f6();
f7(*/
}
```
[Try it online!](https://tio.run/##7ZhNb6MwEIb3zK9ws9IWGroNbUIPxv0jEQcgkJoPm8@VKspvz47tQKFSV9ojqn2I3pmXGYbhuYSoLO/PUXS5/KQsyrtTjDzKm7aOg@LF6BrKzogFRdyUQRSjpj1hA0yRbeKojltE0EapDTb@cHpCiWNaPU1Mlf2dx@zcvprWDXGtPuJd63kbR50Nhgu6muGBshYFR9cnvao67vz7W3RrXyNnET0uoqdFtF9EBxkNOOG1KW5ByQ5T74DpditHDI7UfyHwu3X8aTj3x6fhhmW5uyj3yO79XfaBmq8fcNbDgR4ETNVmzKcEhsCpctK5k5EUnEw52dzJSQZOrpx87hQkB6dQTjF3GCnAYcph8kEgG8rdUzu1Mzu3C5sNOOQ8R2/BG0mCvImnFXKYn3um43muhfm8cwlOOTrl2DloukKsTdxEyfH6CnQF26yu2@S/RG1lWb2o2cJrqXwgIzHLyQilEUpDOLI5EVmrF6O2dRfjENDNlA85KPqIb2Tiy3ekzpXix3VT/C8CNcXfhuInTbGmePUU7zXFmuLVU3zQFGuKV0@xqynWFK@e4mdNsaZ4xRTLBQaUmRbqDQRHfHXDUj3cjUr8@7uq/aQOk3In9TwqdVsXf2opPob8d8u7B2O4XP4C "C++ (gcc) – Try It Online")
Can't hack without `\0`
---
For someone trying to solve in intended way:
* You are supposed to choose 6 elements from [1,111]
* For each set of 6 elements in [1,111], there's non-empty subset of both, whose sum is same
* Then I don't know if any conclusion used
* [Searched](https://tio.run/##jVVrb@I4FP1MfsUVFaukDY/QTgeVpFKldmYrMQVBu/3QVsiJHWpInDQJGo12@OvDXuedltldBME@9xznvmw7YdhdOc5@f8SF420pAzNOKA96r5dKBdk8iVlSR0gS@Ny5VErIjJlPwtcgYiiFCnYdkXhNKP4R9@OEJB9R3yeiiW4FR3@kN8oRZS4XDO7g8@CsnIURF4mr9no9Ddx8ggoWRTosl39dLa/mXxfLpaagBXzCharB30pLzlwKFgQhE2q77zPKCT77j1zQ4HvcXSyu@5sNIT2bi7YO0@X8@nGuw@D87EwbKy3nlUTHQCiNcA01nWnofajePUwmOhgT0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qEEFr6/TrN/uzxqsPTi8otg2zo7Gh@GsWsWvzbpgPxDG7kLeN665ttdYYHmgrhnvKGuSfHY90quu89V6e0bN1z@xZtptl@1l2mGVHmfU45pUhtqBki6l7xHSzkUf0z9Q7Efjd2N73h@vn7c6s3SXbry85B3r@a4YNMwhANWaoJwQOgRNFkilJSQIkVSSdkoykQDJFsinJSQYkVySfEkZyIEwRJv8IVAN599RKrNTKrNxiPQ44z9Cn/0liP6uj8Qo5nJ@7hu26jon5dHIBpBhIMUz26zYX1yY2UeHwfAlxCbdZ3m@TP4ne0jQ70bOB11J6YEZsFCMIJAgkEEQOJ6JqduKoTdVGOAB1U8WhBk3/8gdZ@PYdqXW3eKct1hYv3uK9tlhbvHiLD9pibfHiLT5qi7XFi7fY0RZrixdv8Zu2WFu8YIvlBfqUGSbqVgiW@OqGVbQbo/0YHcboOEbOGL0NkdrWwT80sr/d/gI)
* Confirmed unique. `time` result `895471.99user 2246.72system 28:27:01elapsed 876%CPU (0avgtext+0avgdata 411544maxresident)k 2352inputs+1721048outputs (229024major+17451minor)pagefaults 0swaps`
[Answer]
# [C++ (gcc)](https://gcc.gnu.org/), 4960 bytes, cracks [dfe dfe's cop](https://codegolf.stackexchange.com/a/269212/92727)
Sorry for the unintended solution ): I'll try to find the intended one, it seems interesting.
This only used 4 changes, if you must use all 6 than you can just change the comment.
```
#include <iostream>
using namespace std;
string secret = "secret";
void f1(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"6";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f2(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f3(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f4(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f5(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f6(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f7(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
int main() {f1();}//);f3();f4();f5();f6();f7();cout<<6;f1();f2();f3();f4();f5();f6();f7();}
```
[Try it online!](https://tio.run/##7ZjbbqMwEEDf8xVuKm1Bodu4bejD4P5IxAMhkDUXm@tKFeXbs2M7SUFqPwCt8xB55njGxhxFhLiqHk9xfD7fcxEX/TEhAZdt1yRR@b7qWy5ORERl0lZRnJC2O8IKocq2SdwkHWFkbUZrWP2V/EhS6rgDTx2T/V0k4tT9cdw75rtDLPsuCNZ0DYj6RsDIRUeivR@ywczfb8PHB/LgXSI6i55n0cssep1FOx2NkMrGUUtwtgUe7IBvNnpz0Z6H7wy/NzS8bcv/2tY4L/RnhQHbfn7qDpTS7y5qUk2xmuE00@CazxguDJkh2ZTkLEOSG5JPScFyJIUhxZSUrEBSGlJOiWAlEmGI0JeA2YM@b@5lXu4VXumJEQ5SFuQj@mBpVLTJ7dgk7l8GDg0C3wU57Vwhqa6kunaO2r5UB6YWMcPr/BrHNZ5jfTlH@UvV1q47qJoN3oo6RBtSp7qBgwYHDRTRzZnKuoPaatf0CRxQ1NxwzGHRV3ynE9/cHfO52Pq8VFuptfX/s/XF2mptXYytr9ZWa@tibN1ZW62ti7HVt7ZaWxdj65u11dq6AFv10UVcOC4Z1IssGJ@eXFB/u0A9zYJ6SAD12wtKaTCNfNBT1auEn6eO5/M/ "C++ (gcc) – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), generate bunch of solutions for [Command Master's](https://codegolf.stackexchange.com/a/269216/76323)
```
import sys
s = '77925340277363824169293758807642437284508406489944233814731817114744334387054677199464359370358303681225801571736917189241020964424020531423054738521455432784731931386377196234255749859141710848221995*7660297729448052594468076976871308901099050010752258215140275334247136696601489292003583235840730794856813394396865245853772202539436917905108732823263342134564638227230398268672502337581353160403575356676232895580244410109024495577929416391%997624712161309143295415334518642567808466476564516128021383833912794511198191262082650250977292178811713461440089160581066992373718706289075971369001597094521060013695658387955211810675571614035311614'
g = '0123456789+-*/&|^%~'
for i2 in range(len(s)):
for c2 in g:
sys.stderr.write (str(i2)+','+str( c2)+'\r')
for i1 in range(i2):
for c1 in g:
try:
cmd = s[:i1] + c1 + s[i1+1:i2] + c2 + s[i2+1:]
if cmd.count('**') == 0:
t = eval(s[:i1] + c1 + s[i1+1:i2] + c2 + s[i2+1:])
if t == 2:
print(i1, c1, i2, c2)
except:
0
```
[Try it online!](https://tio.run/##jZLbbhNBEESf7a/Yl@Aroa/TPZHyJRCkyHHCSoltrZdLJMSvmxo7wCuy5O2Z7TldVbOH1/HLfqenU/9y2A9jd3w9To/dbTeLqOJqJBFaNMW4VKkanklRTExD0pzSqFjWaiaqyRbKycEozFRNM8itRDBaiqkDQeqppCVZxJPYgzGj4lRWzCGhWoDDbHJlcEEITRc2d1OJbFOqsmbRRi6iJu5hNb2yAQRZKYKZvoxSSGqEQGKSi@NZmocaJYOVshJTreSEZ3jTJOzcrDsciKGplAoMw6hUobMBwZ9RKEW1dJhRraa1ZHExT4cyEUKG2G3mMACyQiVFpTQwq3mxFq4ETGpNwekQJ0SJoFlhv5BhHJR4KQGjktURmpghKehuFXbadVXckVa@qnDWVAsX2EMgKtWNmxnnxN15iURCpVgUKHD0CZDIEz8QBJacmWsyFkUIwiDK6RyjcGQyQlYrbEYIECohl5BSFQ3FRQYVKEWctaVXES0qAlbQhhX2vCDFDIgX5nY6YANSml/lVsymT@1TJJaWVGRdvV9@ePfz89Wv2fRxP3S9dP2uG@53T9v583Y3Py4WN9NJe7M5v3nCaoIv@vo4PmyH4fr70I/bbn4ch3kvi9VsPVu1Gt1YfBpmC7SfufyPi8ZGuVD5L3UyGYfXSzHZvDxA5vHjTc933ap1rbDqecU3vZx35LIj2Lm7nOkfOxy73uy/7sb5bLmcLbrb247eiJMRwO23@@f5/1IXbwfBHRtJ/pAmh6HHiJ7XQKwR2brZPb/c/thsD@NbI51OvwE "Python 3 – Try It Online")
I don't know which is intended or not listed but a bunch of solution provided. You can also claim xnor solved it
Time: 14m22.162s
Output: [Here](https://tio.run/##bZ05diW7jkX9HIUcyJBWrgz25GS@XWaNoKb@67LD2VeZxnvayYtgA4I9GPG///O///3v8xE/wsfnr@ejrr@v/z7yh62/5eP3r3T@xo/v19/P119bf9PH7/U3v57ff@v6O59rH1/rbz9/x/kbno/vX23DlgzhFbIgXsgTnlcqL3oJRac8f633wXryGG5iL7CV2wUrZKabLsyQ@JxUYnwVaUGaZZvJvehzScd8hW754y3IC3bUcczHXv/6SLcoKR6hF7zUNC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vkmwvCy1u45wG2fa9oxrMf7jIN5Wqo04Y6bajThnpB93mvZcaz7y0ZlKuhXB3poi1E9JexI56OeDrjUb8U0avGgTgHnh14dkgP6VGdpkd1OveiXSaoLlJQXdwXB24O4AhO4IJ4CuJBftB2EtpOQttJsUKmQqYjXOVNHOBTRLh0ldCfJ7SphDaV0KZSRpwZcWbEg3Z091QvuzzaVEKbuvuo8eydfoElA30W6LMgXbSvhPaVKuqroiwVZamox4o8VOQB7TGhPSa0wYQ2mDA3uVeG4tkX/QJ/giWTIJMgg7w15A3tNKGdJsx5EsasewUonn3RL7DCoasOXXXUF8a1u0e6GO3uXkeJZx9SjAkmxqmMceruQ16WjPSZA@IJiCcgHkyHc6iQqZBRfeUofeYofWa0x4z2mBPymZDP837Dyxl8x@uMMSVj5npfPrqn2qrHgjF6ugKLO@bjCM@YkXN2XlUXBf3/@nqvM@btyE9B33vXnvGsAcUdrPqqCTIpgBFPamDEc97nfHmAp0yan5o588931ktV00f39ddkPTsgP/773/8H)
] |
[Question]
[
Given a PPCG user's user ID, calculate how much times is their Each SE site reputation is from average reputation in the Stack exchange sites they have made accounts.
Let me explain, If someone's total network reputation (Total reputation in the stack exchange sites he has participated) is 10k, and if he has participated in 4 sites, then the average network wide reputation will be `2500`
And assume he/she participated in these 4 sites and has these reputation
```
Stack overflow 3000
Code golf and Coding challenges 2000
Mathematics 1500
Super User 4000
```
**So your final output should be:**
```
Stack overflow 1.2x
Code golf and coding challenges 0.8x
Mathematics 0.6x
Super User 1.8x
```
Here the `x` is to express how much times each site reputation is of the average, such as 2500\*1.2=3000
* (No obligation to floor the 1.2)
* (Order of the sites does not matter)
* (You can write the site names uppercase or lowercase or anything, that does not also matter)
Your code will be able to access internet freely.
Input is the **PPCG User ID**.
Trailing/leading whitespace allowed in output, Standard loopholes apply, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") shortest code wins.
# Test case
user 95516 (@rak1507, chosen him/her because have participated in less sites)
For average 943:
```
Code golf and coding challenges 3.57x
Stack overflow 0.21x
Meta stack exchange 0.107x
Puzzling 0.107x
```
[Answer]
# JavaScript (Node.js), 465 bytes
```
(i,C)=>(p='https://codegolf.stackexchange.com',n=t=a=[],g=(u,c)=>require('https').get(u,r=>r.on('data',d=>i+=d,r.on('end',_=>c(r.headers.location)))))(p+'/users/'+i,l=>g(p+l,_=>g(s=i.match(/ht.+\/s[^"]+\d\/[^?]/)+0,l=>g(new URL(l,s)+'?tab=accounts',_=>i.replace(/unt-[^]+?\n *([\w&].+)[^]+?r".+?([\d,]+)/g,(_,s,r)=>a.push([s,r=r.split`,`.join``,t-=r,n--]))&&C(a.map(([s,r])=>s.replace(/&#?(.+?);/g,(_,m)=>String.fromCharCode('0'+m|0||38))+` ${r/t*n}x`).join`
`)))))
```
Function which accepts a the ID as a string and returns the result to a callback.
I tried to make it robust and it should work for any profile as of time of submission with one possible exception: the accounts tab on the network profile contains a profile summary which can be edited by the user so it's possible for a user to write something to fool the regex in their bio.
## Explanation
```
(i,C)=>(p='https://codegolf.stackexchange.com',
// n = count of sites, t = total sum of reputation, a = array of (siteName, rep) tuples
n=t=a=[],
// Function which performs a GET request.
// The body is appended to `i` and the callback is called with the location header.
g=(u,c)=>require('https').get(u,r=>r.on('data',d=>i+=d,r.on('end',_=>c(r.headers.location))))
// Load the user's PPCG profile.
)(p+'/users/'+i,l=>
// Since we only provided the ID and not the name in the URL, it will return a 301 redirect.
// Load the redirect.
g(p+l,_=>
// The first URL on the body to match this regex is the network profile URL of the user.
// Note that this comes before the custom content in the profile
// (which could contain other network profile URLs).
// This request will result in a 301 if the user's name is different on the
// network profile than PPCG, so the first character plus 0 will force a redirect
// because display names are a minimum of 3 characters long.
g(s=i.match(/ht.+\/s[^"]+\d\/[^?]/)+0,l=>
// Load the accounts tab of the network profile.
g(new URL(l,s)+'?tab=accounts',_=>
// Find each site and reputation count.
i.replace(/unt-[^]+?\n *([\w&].+)[^]+?r".+?([\d,]+)/g,
// Remove the commas from the rep value, populate `a` and add them up for the average.
// decodeURIComponent is annoyingly long but there's no shorter way to correctly display
// sites like the Japanese site which is made solely of URI encoded characters.
(_,s,r)=>a.push([s,r=r.split`,`.join``,t-=r,n--]))&&
// Calculate and print the results.
// There is a lot of bytes dedicated here to unescaping HTML entities because
// unfortunately there's no easy way to correctly display sites like the Japanese site
// which is made solely of HTML encoded characters.
// As far as I can tell the only escapes used in site names are the `&#xXX` style
// and `&`.
C(a.map(([s,r])=>s.replace(/&#?(.+?);/g,(_,m)=>String.fromCharCode(0+m|0||38))+` ${r/t*n}x`).join`
`)))))
```
[Answer]
# [Python 3](https://www.python.org/download/releases/3.0/) + [Selenium](https://www.selenium.dev/) + [Firefox](https://www.mozilla.org/en-US/firefox/), 301 bytes
```
from selenium.webdriver import*
D=Firefox()
D.get("http://codegolf.stackexchange.com/users/"+input())
F=D.find_elements_by_css_selector
F('.communities a')[-1].click()
s=[int(j.text[:~9].replace(',',''))for j in F('.account-stat')[::4]]
for i,j in zip(F('h2'),s):print(i.text,str(j*len(s)/sum(s))+'x')
```
This program did not close the Firefox window after execute, you need to close it manually. Input from stdin, output to stdout. You should completely ignore the Firefox window.
```
from selenium.webdriver import*
# start Firefox WebDriver
D=Firefox()
# Ask input for user ID
# Open profile page on CodeGolf.SE
D.get("http://codegolf.stackexchange.com/users/"+input())
# Store find_elements_by_css_selector to save bytes
F=D.find_elements_by_css_selector
# `.communities` is the left pannel of user's communities
# the last link (`a`) in it is accounts tab of user profile on SE
# click to follow the link
F('.communities a')[-1].click()
# `.account-stat` selects all user stat cells
# 4 cells each row, 1st cell each row is reputation, so we [::4]
# the cell contains text like `12,345 reputation`
# We only keep digits and convert to int
s=[int(j.text[:~9].replace(',',''))for j in F('.account-stat')[::4]]
# `h2` selects all nodes for sites name
# for each sites name and its reputation, output as required
for i,j in zip(F('h2'),s):print(i.text,str(j*len(s)/sum(s))+'x')
```
Not much rooms for golfing here. Only golfed things would be `F=D.find_elements_by_css_selector` and `[:~9]`, IMO.
[Answer]
# PowerShell, 331 bytes
There are some issues with this method, but ones that I'm not sure can be resolved without reworking the problem to use the API rather than web scraping - hidden sites will not be counted via this method, and the user editable portion of the profile page could potentially contain something which fools my Regex.
Definitely room for golfing improvement here, especially in the regex; I will revisit this when I have the time. Here are the user IDs I used for validating: 92116, 99902, 66833, 95516
```
$x=(iwr "codegolf.stackexchange.com/users/$args")-match"https://\w+\.\w+/\w+/\d+/[^""]*(?="")"
$a=(iwr($Matches[0]+"?tab=accounts")|Select-String "2>\s*<a[^>]+>([^<]+)<(.|\n)*?>([0-9,]+)<"-AllMatches).Matches|%{@{n=$_.Groups[1].Value.Trim();r=$_.Groups[3].Value-replace","}}
$a|?{$r+=[Int]$_.r}
$a|%{$_.n+" $($_.r/($r/$a.Count))x"}
```
No TIO, because internet :(
### Example
**Input**:
```
66833 # This is user ChartZ Belatedly, who recommended their ID as a test case.
```
**Output**:
```
Code Golf 24.5032822757112x
Movies & TV 2.72347840181538x
Meta Stack Exchange 1.07869357322311x
Stack Overflow 0.615122781424751x
Science Fiction & Fantasy 0.571440149120674x
Code Review 0.343220682389173x
Interpersonal Skills 0.323608071966934x
Mathematics 0.314693249047735x
Area 51 0.212172785476943x
MathOverflow 0.161358294837507x
English Language & Usage 0.12748196774455x
German Language 0.116784180241511x
Stack Apps 0.0989545344031121x
Computer Science Educators 0.0989545344031121x
Role-playing Games 0.0900397114839128x
Academia 0.0900397114839128x
Mathematica 0.0900397114839128x
Mi Yodeya 0.0900397114839128x
Philosophy 0.0900397114839128x
Arqade 0.0900397114839128x
The Workplace 0.0900397114839128x
Database Administrators 0.0900397114839128x
Puzzling 0.0900397114839128x
Super User 0.0900397114839128x
Physics 0.0900397114839128x
Chemistry 0.0900397114839128x
Personal Finance & Money 0.0900397114839128x
Quantum Computing 0.0900397114839128x
Coffee 0.0900397114839128x
3D Printing 0.0900397114839128x
Medical Sciences 0.0900397114839128x
Economics 0.0900397114839128x
Politics 0.0900397114839128x
```
## Bonus, PowerShell, 347 bytes
This version uses the same metric as SE, in which sites where the user has less than 200 rep are not counted.
```
$x=(iwr "codegolf.stackexchange.com/users/$args")-match"https://\w+\.\w+/\w+/\d+/[^""]*(?="")"
$a=(iwr($Matches[0]+"?tab=accounts")|Select-String "2>\s*<a[^>]+>([^<]+)<(.|\n)*?>([0-9,]+)<"-AllMatches).Matches|%{@{n=$_.Groups[1].Value.Trim();r=[Int]($_.Groups[3].Value-replace",")}}|?{$_.r-ge200}
$a|?{$r+=$_.r}
$a|%{$_.n+" $($_.r/($r/$a.Count))x"}
```
### Example
**Input**:
```
66833 # This is user ChartZ Belatedly, who recommended their ID as a test case.
```
**Output**:
```
Code Golf 7.18671741088289x
Movies & TV 0.798785625054473x
Meta Stack Exchange 0.316376630545307x
Stack Overflow 0.180413119897737x
Science Fiction & Fantasy 0.1676011737021x
Code Review 0.100665291537143x
Interpersonal Skills 0.094912989163592x
Mathematics 0.0922983062665233x
Area 51 0.0622294529502339x
```
] |
[Question]
[
The task is to convert a string representing a number in decimal (base 10) representation to duodecimal (base 12). The input is thus a string, the output should be printed.
The input number can be positive and negative, can be integer or rational. The decimal and duodecimal representations will have a finite number of digits after the (duo)decimal point.
The digits for duodecimal should be 0-9, a, b.
The output should not contain trailing zeroes after the duodecimal point and no leading zeroes before the duodecimal point. The duodecimal point should only be printed if the number is non-integer.
## examples
input 400 -> output 294
input 14 -> output 12
input 1498 -> output a4a
input -11 -> output -b
input 11.875 -> output b.a6
## counter examples
not okay are outputs like "-001a", "00b.300", "1.050".
## EDIT: additional assumptions
* the number can be represented exactly as float
* there are overall less than 7 digits (excluding a minus and a duodecimal point) needed to represent the result.
[Answer]
# Japt, 2 bytes
I feel I must be missing something ...
```
sC
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=c0M=&input=LTEx)
[Answer]
# C (~~137~~ 134 bytes)
(thanks for the help Kevin Cruijssen)
```
l=144;main(b,w){float v;scanf("%f",&v);w=v*l*12;for(w<0&&printf("-",w=-w);b<w;b*=12);for(;(b/=12)>l|w;w%=b)printf(".%x"+(b!=l),w/b);}
```
Explanation:
Pretty much just an implementation of the base-conversion. This is the algorithm in a readable form:
```
int main() {
float v;
int b, w;
scanf("%f",&v);
w=v*1728; // Multiply with 1728, so we can use int-arithmetic
// Deal with the sign
if (w<0) {
printf("-");
w=-w;
}
// Find largest power of 12 we care about
while (b<w) {
b*=12;
}
// At b == 1728 the fractional part starts.
while(b > 1728 || w != 0) {
b /= 12;
if (b == 1728) {
printf(".");
}
printf("%x",w/b);
w = w % b;
}
}
```
This is then golfed down with fairly standard C-tricks:
* Symbols without a type are assumed int.
* Use arguments to main to save variable declarations.
* First argument to main is initialized to 1 (argc).
* Use binary operators instead of control-flow structures.
* The branch in the main loop can be removed by instead calculating an index into a single format-string.
* Shuffle around some statements and side-effects to save a character here-and-there.
* Store 144 into a variable, to not type out that constant so often (the shuffling in the previous step makes 144 a better candidate than 1728).
My personal favorite is probably the `w<0&&printf("-",w=-w)` part, even though it only saves a character or two compared to the next obvious way - by putting the `w=-w` as an (unused) argument to printf, we save some parenthesis that would otherwise be needed to group two side-effects into a single expression.
[Answer]
# [Perl 6](http://perl6.org/), 20 bytes
```
(+*).base(12).lc.say
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPtfQ1tLUy8psThVw9BIUy8nWa84sfK/tUKahkq8pkJafpGCiYGBjoKhCQhbWugo6BoaApmGehbmpv8B "Perl 6 – Try It Online")
The built-in `base` method on numbers just does the right thing, including for negative numbers and floats. However, it outputs letters as uppercase, so the `lc` method call fixes that.
[Answer]
# PHP, 96 bytes
It´s lengthy with the decimals, but quite simple with the limited number of digits.
```
<?="0-"[0<=>$argn],trim(substr($r=base_convert($argn*12**6,10,12),0,-6).".".substr($r,-6),".0");
```
Save to file, run as pipe with `-F`
requires PHP 7.0:
older PHP has no spaceship or power operators → parse error
PHP 7.1 understands negative string indexes → negative output for positive input
To fix:
Replace `"0-"[0<=>$argn]` with `"-"[$argn>=0]` and insert `?:0` before `;`. (→97 bytes)
For PHP 5.5, additionaly replace `12**6` with `2985984`. (→99 bytes)
For PHP 5.3 or 5.4, additionally replace the part before the first comma with `$argn<0?"-":""`. (→100 bytes)
For older PHP, use `<?=($r=trim(...))?$argn>0?$r:"-$r":0;` (→103 bytes)
**breakdown**
```
<?= # PHP: echo
"0-"[0<=>$argn], # 1. print minus (dumped by base_convert) or zero (dumped by trim)
trim(
substr(
$r=base_convert(
$argn*12**6 # 2. multiply input with 6**12
,10,12) # 3. convert to duodecimal
,0,-6) # 4. first digits are integer part
.".".substr($r,-6) # 5. last 6 digits are fraction
,".0") # 6. trim: crop by zeroes and point
;
```
[Answer]
# ZSH with extendedglob, 81 bytes
```
read l;r=$(([##12]l*12**6));s=${(L)r[1,-7]}.${(L)r[-6,-1]%%0##};echo - ${s%.}
```
save to file and run in pipe `echo "400" | zsh convert.sh`
```
read l # read from stdin
# $(()) arithmetic mode
# l*12**6 multiply the number by 12^6 (base change can't handle stuff after the decimal point)
# [#12] print it in base 12
# [##12] same, without the leading base modifier printed
r=$(([##12]l*12**6));
# (L) convert letters to lower case
# [1,-7] pick all but the last 6 characters
# :-0 if these are empty, print 0 instead
# [-6,-1] and the last 6 characters, respectively
# % remove the largest trailing match ...
# %% same, but largest match
# 0## pattern is an arbitrary amount of zeroes
# . print a . between the two blocks
s=${(L)r[1,-7]:-0}.${(L)r[-6,-1]%%0##}
# %. remove trailing .
# - avoid interpreting a possible minus sign as option
echo - ${s%.}
```
[Answer]
# JS, 17 bytes
```
a=>a.toString(12)
```
When run in the console, Javascript implicitly outputs the result.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 29 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Ä6xsm*12BR6ô'.ýR0Ü'.ÜlI0‹i'-ì
```
Very ugly and long, but it works.. Both the decimals and negative aren't supported during base conversion in 05AB1E, so I have to do things manually..
[Try it online](https://tio.run/##yy9OTMpM/f//cItZRXGulqGRU5DZ4S3qeof3BhkcngOk5@R4Gjxq2Jmprnt4zf//uoaGehbmpgA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/wy1mFcW5WoZGTkFmh7eo6x3eG2RweA6QnpNTafCoYWemuu7hNf9rdf5HK5kYGCjpKCgZmkBISwsQrWtoCOYa6lmYm0IFwMxYAA).
**Explanation:**
```
Ä # Take the absolute value of the (implicit) input
# i.e. -11.875 → 11.875
6x # Push 6 and 6 doubled (so 12)
sm # Swap them, and take the power of each other: 6**12 → 2985984
* # Multiply it by the absolute value of the input
# i.e. 2985984 * 11.875 → 35458560.0
12B # Convert it to Base-12:
# i.e. 35458560.0 → "BA60000"
R # Reverse it
# i.e. "BA60000" → "00006AB"
6ô # Split it into chunks of size 6
# i.e. "00006AB" → ["00006A","B"]
'.ý '# Join the list by "."
# i.e. ["00006A","B"] → "00006A.B"
R # Reverse it back
# i.e. "00006A.B" → "B.A60000"
0Ü # Remove any trailing zeros
# i.e. "B.A6"
'.Ü '# Then remove any trailing dots
# i.e. "B.A6" remains "B.A6"
# i.e. "294." → "294"
l # And convert it to lowercase
# i.e. "B.A6" → "b.a6"
I0‹i # If the input is smaller than 0:
# i.e. -11.875 → 1 (truthy)
'-ì '# Prepend a "-"
# i.e. "b.a6" → "-b.a6"
# (And output the top of the stack implicitly as result)
```
] |
[Question]
[
# Background
The Thousand Character Classic is a chinese poem written around the 4th Century CE in China, and memorized by large populations since then. The name comes from not only its length, but its number of characters: each character occurs only once in the text. It is commonly used to teach children chinese characters, and also, because of its commonness, as a means of enumerating the 1000 characters in the text.
# The challenge
Here is a copy of the Thousand Character Classic, gotten from Wikipedia.
[The Thousand Character Classic](https://gist.githubusercontent.com/eaglgenes101/a4d111602192e51a1f5ca2f630fee8b5/raw/4c30e332eb2d4b1a7fd3ee8f0dbbe0c29c723424/gistfile1.txt)
Reproduce the entirety of the Thousand Character Classic in either UTF-8 or UTF-16, including punctuation, newlines, and heading numbers. Punctuation can be halfwidth or fullwidth, and the trailing newline is optional.
For those that want to analyze the unicode text for patterns, I've provided hexdumps of both encodings.
[utf-8](https://gist.githubusercontent.com/eaglgenes101/0fe04803dccc0e6ee200471c9ca1738e/raw/f879288c705f6c7feb37ded3112cc6a10f0646be/gistfile1.txt)
[utf-16](https://gist.githubusercontent.com/eaglgenes101/cadf59d69c27dacd95151a79a33bb377/raw/e565c92bbb387d2cbf0e76bba63e30ad3ff07079/gistfile1.txt)
# Rules
Because of the size of the text to reproduce, you may optionally supply a file for your submission to use as input. If this is done, add the byte length of the input file to the byte length of your code.
Otherwise, this is a standard issue code golf challenge, so standard loopholes apply, and shortest submission wins.
[Answer]
# [Bubblegum](https://esolangs.org/wiki/Bubblegum), 2526 bytes
```
00000000: 2dd4 47c2 82cc 9680 e1f9 b78a de42 e7ed -.G..........B..
00000010: 898a 808a 3921 28e6 0ca8 1830 e162 9a13 ....9!(....0.b..
00000020: 6ad4 5bb8 50fe e3e7 bc86 4aff fe07 8b2d j.[.P.....J....-
00000030: 3847 aa15 c5ab f0ff ef2a f81a f816 5e76 8G.......*....^v
00000040: 6cb6 fe2f 97ff b73f ec2f d1d1 c9d6 7190 l../...?./....q.
00000050: 39c7 47f0 bfa0 f7e1 7d95 0e41 2b89 4b38 9.G.....}..A+.K8
00000060: 6c42 9c4b 9dd6 15ec dca0 74e0 7e5d bae8 lB.K......t.~]..
00000070: d5c5 6280 7a03 bd73 ea10 57a0 99e7 dd57 ..b.z..s..W....W
00000080: 589f 9fdb 67b1 39b2 7611 f626 75e1 9ce9 X...g.9.v..&u...
00000090: daa0 fc53 38ce cfb5 2675 5cf1 ece3 f192 ...S8...&u\.....
000000a0: 3ad5 0cd0 9e70 69c2 792a 1dca 265b 2edc :....pi.y*..&[..
000000b0: 37a2 dfcd bc3e a1cd 0916 0ea8 8674 1c3b 7....>.......t.;
000000c0: 5437 7154 43f7 983a d71d a199 5c5e c2da T7qTC..:....\^..
000000d0: f9f9 f50e ad08 cf21 dea7 a98b 531f 3f36 .......!....S.?6
000000e0: c51f fa76 a4ff c79f 884d 88f6 a4ec 211a ...v.....M....!.
000000f0: 6513 e112 fc41 f27c d250 9313 b0ae 807e e....A.|.P.....~
00000100: c39e 065e 3ff5 e451 40c7 e4e9 9ce7 a174 ...^[[email protected]](/cdn-cgi/l/email-protection)
00000110: ac6d 928f c97e 1b9c 4aea e818 6c8d 8575 .m...~..J...l..u
00000120: 834e 433a bc3b 786c 26ef 067d 76a9 4373 .NC:.;xl&..}v.Cs
00000130: 43d6 1bfd 3b3e 829f 8f1a e88c a05b 174a C...;>.......[.J
00000140: 3bf3 711e 2b27 7884 b49f 48c7 a2cd f9b3 ;.q.+'x...H.....
00000150: 78d5 c4aa 973a 6bf3 e45d 47bd 4671 55ba x....:k..]G.FqU.
00000160: 501a 22af 2551 4eec 3b72 0535 0edb e845 P.".%QN.;r.5...E
00000170: 54ab fc3c bc88 3004 6743 fb47 e6d6 47ac T..<..0.gC.G..G.
00000180: 5b62 eec2 e422 1daa 3d9e edd9 34d0 d9a4 [b..."..=...4...
00000190: cee1 05ea 656e 1cb0 f790 fe9f 7fdc aea0 ....en..........
000001a0: b7e0 e75e ecfd 7402 6c1b 16eb e4d9 8128 ...^..t.l......(
000001b0: 9213 a878 5870 c578 2216 e5d4 f9a4 6377 ...xXp.x".....cw
000001c0: 8641 0ef2 77e9 b00c 51ed f279 4c57 2775 .A..w...Q..yLW'u
000001d0: eadc b1ab a361 b211 4827 7729 941a 7c55 .....a..H'w)..|U
000001e0: ec3c e419 ea73 e1c3 b53d 7c07 3fff 7478 .<...s...=|.?.tx
000001f0: afc1 e74d ae97 ba18 4d51 29c0 fd24 ba77 ...M....MQ)..$.w
00000200: e9c9 779a 7cbe 500f 7855 ca7a 6b83 87b3 ..w.|.P.xU.zk...
00000210: b0e7 42ab 4b87 d906 f367 ba9e d16d a7ce ..B.K....g...m..
00000220: db2d fb43 8a3b 1497 a5a3 15f0 b44a 378f .-.C.;.......J7.
00000230: c359 d6ab 15f8 5e93 8fc3 4a4f 3ac4 7778 .Y....^...JO:.wx
00000240: 3da1 61d2 be92 f967 46fb b4d8 a037 974e =.a....gF....7.N
00000250: db27 1fef 900f 5939 a7ce 960d 933c 7d5b .'....Y9.....<}[
00000260: ac7c 7ebe 32c1 9e60 614a 5b33 755a d5e9 .|~.2..`aJ[3uZ..
00000270: 3e87 5e11 d59b 7438 3ea9 b516 a331 04b7 >.^...t8>....1..
00000280: d421 8884 75c4 4140 fb9f 73a8 917e 4b9e [[email protected]](/cdn-cgi/l/email-protection)..~K.
00000290: 1568 d8a9 a37d 84e1 8575 0dbb 07e9 e08d .h...}...u......
000002a0: a87b a3bd 07e5 cce1 3b01 4323 7b0a cd8f .{......;.C#{...
000002b0: 74d6 3678 3fc1 69c9 bd62 e60b 8b75 1d9f t.6x?.i..b...u..
000002c0: 7bd0 cad2 93f7 9b07 1ef6 02b1 da64 beca {............d..
000002d0: e328 4e1e 15b2 6de9 701f e155 4922 1395 .(N...m.p..UI"..
000002e0: 2075 bc5f 312e 42bd 8783 c9cf fd07 7a33 u._1.B.......z3
000002f0: ae2c 3137 4a9d 3739 8e3d f00d f087 d229 .,17J.79.=.....)
00000300: 5880 3ee2 dd84 e25a d6ab 35ba e6c1 7792 X.>....Z..5...w.
00000310: d742 3aae 7c5c 7a68 e4c0 7d66 7ddf a0ce .B:.|\zh..}f}...
00000320: 908a 53da bbd2 c18b a0b8 23eb 95bc ba59 ..S.......#....Y
00000330: df19 b172 8778 8c9d ef3f 3e48 5e4b ea0c ...r.x...?>H^K..
00000340: 703e 491d 6a2f ce55 c92e f376 221d 3779 p>I.j/.U...v".7y
00000350: f4cb 7cbe 70b8 90eb ef83 be84 6319 cca6 ..|.p.......c...
00000360: f424 2a43 ab9a 4415 1aad e4fa eca1 7382 .$*C..D.......s.
00000370: ed4a 0c37 d261 d183 7a1f f22a 6fda 99ab .J.7.a..z..*o...
00000380: 4b58 1a18 9850 cc49 e77d 04eb 66f2 0ea0 KX...P.I.}..f...
00000390: 2e6f 60f5 065e 0383 0ea8 2de9 e075 50bb .o`..^....-..uP.
000003a0: 835a 84b7 9bf5 8d2a 1ee7 2237 c7c9 437a .Z.....*.."7..Cz
000003b0: f25c 40bd 82e5 2ee8 a5cc 758d e61b f22f .\@.......u..../
000003c0: bcaa fffc a5a0 aa8b e109 0baf d445 6e82 .............En.
000003d0: 8729 bcfb c29e 49a7 2047 f116 5e86 c8e5 .)....I. G..^...
000003e0: 329f da78 b6a1 ba63 6b2d 1d73 6b31 72b0 2..x...ck-.sk1r.
000003f0: a08a 5c24 cf47 012a 5d5a 8ea9 7796 0ebe ..\$.G.*]Z..w...
00000400: 4e8e 0bdf 3ebe bef2 f31b 646c b158 a7f5 N...>.....dl.X..
00000410: ebe7 1315 ab8a b055 6c9b 59bf fc90 7e65 .......Ul.Y...~e
00000420: 6d47 d1cf ffeb 4f14 3e22 dfe4 7a00 8b7a mG....O.>"..z..z
00000430: b643 a313 2fbf c9b3 9a3c 7f27 940b 5591 .C../....<.'..U.
00000440: b7c4 6886 173b f3ab 8f91 87ed 21de 34e9 ..h..;......!.4.
00000450: e0fb e87f c95e 8882 92f9 a6cd eb9c 98db .....^..........
00000460: 623b fcb9 d383 604f ab0f 9951 ead4 ddc3 b;....`O...Q....
00000470: 679b bcd2 4fd4 a527 91c5 ba09 7913 ba6e g...O..'....y..n
00000480: e69d 3344 211c 4d5c 3ea4 73be 44de 9537 ..3D!.M\>.s.D..7
00000490: 1e44 f205 79b7 a9e9 42e3 4107 4b3a 989a .D..y...B.A.K:..
000004a0: 18d6 e862 0a4b dea0 b7c2 1f83 7a4d 1cb8 ...b.K......zM..
000004b0: 3faf 8722 3784 d71c d475 e6f7 9550 3a68 ?.."7....u...P:h
000004c0: 7c71 5093 8efd 99b0 4b30 0b41 8d52 4f9e |qP.....K0.A.RO.
000004d0: 2b56 8614 2fb8 72fa f9c8 a1cd 5798 b118 +V../.r.....W...
000004e0: 668e ef12 da11 cc15 bab5 a5c3 d3a1 5885 f.............X.
000004f0: a346 76e6 7c0f 92ef 04d7 0d30 bfd2 51bf .Fv.|......0..Q.
00000500: c151 0175 4fd1 3c75 f06f 745d 8159 00f5 .Q.uO.<u.ot].Y..
00000510: 2a5d ec07 509a 086b c7ef 55ea 62ab f227 *]..P..k..U.b..'
00000520: 8fd5 809e 6de9 49d4 a374 4362 1d82 6aea ....m.I..tCb..j.
00000530: fc2a 8b75 97f3 4b7e 77a5 93d7 83b2 cbd5 .*.u..K~w.......
00000540: 3c04 590f 9516 cd9a a0bf 4479 f0f3 f90b <.Y.......Dy....
00000550: 9fbb e45d 86e3 23f5 e4d3 402b 2f06 5f9e ...]..#...@+/._.
00000560: 4ea5 c3b2 08be 8af6 590c 9cac 8f7d ecaf N.......Y....}..
00000570: c03b 92e6 4ac7 691b d403 54a7 d0d0 53c7 .;..J.i...T...S.
00000580: af0b ef13 1a37 c8c7 d2e9 f604 7b8c ef19 .....7......{...
00000590: 1626 a9f3 6e87 4517 bd55 1229 d293 6f39 .&..n.E..U.)..o9
000005a0: 79e4 2128 41e5 2b6f e810 e67b 083a 10ac y.!(A.+o...{.:..
000005b0: a5a3 65e0 7288 f645 3872 fd6e 96f0 ea60 ..e.r..E8r.n...`
000005c0: 1f71 bb97 0e8a 2672 1d7c a96c cd32 8f1a .q....&r.|.l.2..
000005d0: e0b8 e814 c876 a527 9fae 50ae 7429 62d8 .....v.'..P.t)b.
000005e0: 4d5d b86d 7897 49dd 82de 94ce d73b 7d57 M].mx.I......;}W
000005f0: 62d2 2763 2dcf d786 5f26 3a39 3ac7 d2c1 b.'c-..._&:9:...
00000600: 9fc3 46c1 b385 ef49 d6af 42f6 3e49 f410 ..F....I..B.>I..
00000610: a396 f4e4 3182 fb98 560f be4f b3de 8a45 ....1...V..O...E
00000620: 614a eb15 3c6e d2e1 1c82 dfc7 f008 e753 aJ..<n.........S
00000630: e6ab 5d12 bd92 6733 797a d285 ad88 5e8e ..]...g3yz....^.
00000640: 2e7b 988e 5317 f698 3a47 be2e c0ad 49c7 .{..S...:G....I.
00000650: 4109 4f13 9acd c90d 3337 54a1 d5f0 3286 A.O.....37T...2.
00000660: 7f7a b427 4299 d0ed 2bf2 7aea 70de c279 .z.'B...+.z.p..y
00000670: 8fa3 104a 4be9 fffd 87e7 173a 07ec bd39 ...JK......:...9
00000680: 3ecb 1360 71f5 4c9b 376d a7ff ecc0 8ddf >..`q.L.7m......
00000690: 0698 7dea 8e52 47bd c9fd 9178 99b4 b94b ..}..RG....x...K
000006a0: a78d 4a25 97cf 33ec 1d65 1f71 3816 2f47 ..J%..3..e.q8./G
000006b0: 58ae 74f0 5c7e bdb0 bba2 cb24 f3fa 5978 X.t.\~.....$..Yx
000006c0: 435a 1b64 5f7e febc c123 4e22 0f9e 91ec CZ.d_~...#N"....
000006d0: c77c b0f8 f0c0 6e57 3a2b 25e1 8610 b8d4 .|....nW:+%.....
000006e0: 28a5 2e9a 2d3e 5739 deb0 71fe f9f9 03b5 (...->W9..q.....
000006f0: 250c 0caa de65 6f80 7aa3 651f 17a6 7472 %....eo.z.e...tr
00000700: 147e 1ed8 abf3 6e9a 7970 85d9 18cb 7d5c .~....n.yp....}\
00000710: 5ea5 a35f e2f8 c4df 262a cbd4 71dc a761 ^.._....&*..q..a
00000720: 051e 1198 a174 50b7 d4ab f3aa 825b 3775 .....tP......[7u
00000730: 5ecf e95a e4dd 51e4 ded2 e932 8393 2a7a ^..Z..Q....2..*z
00000740: 2db6 ba59 7f36 c46b 0041 1e82 a574 3ce5 -..Y.6.k.A...t<.
00000750: a1be 8063 85f7 bdcc bb73 547d 9133 8562 ...c.....sT}.3.b
00000760: fdfc 3087 659d 2e81 50e6 99ab 6f3e 8cd0 ..0.e...P...o>..
00000770: 9b62 c5fe 7934 61f3 4ec3 227a f2ff 392d .b..y4a.N."z..9-
00000780: ae7d b0fc c1d9 e8e7 630d 4777 b486 f49d .}......c.Gw....
00000790: 64fd 6c8d d306 0f17 a055 a40b 2bc4 c903 d.l......U..+...
000007a0: d61d fa86 a973 e3c3 4d43 cc8b d8e8 49c7 .....s..MC....I.
000007b0: 2812 d798 cc8d 502a a983 56c5 e696 aea1 (.....P*..V.....
000007c0: 708a d2ff e78f 731f f673 54db 4294 972b p.....s..sT.B..+
000007d0: d826 db07 bb4c fee9 9f33 d8e6 f70d 3b11 .&...L...3....;.
000007e0: 75eb 999f 0e9c 0b61 3c27 a324 1dd4 3b97 u......a<'.$..;.
000007f0: 42b1 6888 7990 ba50 b650 9f83 aab2 1a49 B.h.y..P.P.....I
00000800: 17f3 8f98 efa9 f000 ff98 f97c 0635 8f42 ...........|.5.B
00000810: 97c2 8974 5eed 501f 6257 65bd 9c3a e714 ...t^.P.bWe..:..
00000820: 3836 a97b a470 2d1d 5631 c453 8a62 bac8 86.{.p-.V1.S.b..
00000830: 1d8e 55b8 c710 dd51 ff4a a78b 8e86 064e ..U....Q.J.....N
00000840: 1b3f 9dd4 4539 479a 476a 8bd4 aa74 b446 .?..E9G.Gj...t.F
00000850: e44c 60d1 85a0 913a f74d f24c 3e4d e159 .L`....:.M.L>M.Y
00000860: 960e ef15 7a55 a1b6 c0bf a48e b525 8e02 ....zU.......%..
00000870: d60d 5e5f a493 1ba0 5111 9336 dfc2 ccf3 ..^_....Q..6....
00000880: 2a9f f649 d481 e75d 3aec a710 57a1 3fa7 *..I...]:...W.?.
00000890: 6735 755a 7ab4 cc51 6104 83be 74da 7cc4 g5uZz..Qa...t.|.
000008a0: d482 9289 1547 f643 d4de a834 b070 fbb9 .....G.C...4.p..
000008b0: 5f21 a345 c729 af94 d4c5 744d 5e07 822d _!.E.)....tM^..-
000008c0: 6f43 e962 17c1 7886 8510 af97 d4c1 bd53 oC.b..x........S
000008d0: e924 a603 bcbd 7fbe 9d89 4d4c e519 198f .$........ML....
000008e0: ac5f 7bfc 34f9 a68a ed42 3aef 54ec 1d38 ._{.4....B:.T..8
000008f0: 2c93 2dbf dfec 9279 86ba 9d3c a7d2 fff7 ,.-....y...<....
00000900: 0fa2 021c 8b50 1826 91bc a357 8d1a 1731 .....P.&...W...1
00000910: f061 10a4 137f a81c c82b 416e 4f17 2b65 .a.......+AnO.+e
00000920: a18f e1be 4e5e 2fa1 cd33 165a 852e 36e8 ....N^/..3.Z..6.
00000930: dbe4 db4f 99f6 231a 9692 4f08 2b4b d681 ...O..#...O.+K..
00000940: 8dbd 0fde 9bb0 964f fc7d 29a6 4758 9974 .......O.}).GX.t
00000950: 6866 0c8f 0bb9 330c ea90 3fa4 8cf6 0a87 hf....3...?.....
00000960: 063a 7db4 9d8c a9f5 a5d6 1cb5 087b d38c .:}..........{..
00000970: ad95 f08a d43a 92ba ce18 ab1a f776 c9d7 .....:.......v..
00000980: a7a5 93f1 31a2 5b1d 1a06 943d 59bb 5bf4 ....1.[....=Y.[.
00000990: 96f0 ee8a c920 e5e4 1b24 af23 bcca f072 ..... ...$.#...r
000009a0: 653d 7221 ba91 ebc0 b328 4fd6 00e2 328d e=r!.....(O...2.
000009b0: 5fe4 3c33 066f 21ac 0a04 5356 c629 6371 _.<3.o!...SV.)cq
000009c0: c82d 8b3c 8377 c38c f990 e7dd 18ca 5bce .-.<.w........[.
000009d0: a929 53d1 80b6 913c 6ac9 c34d f95f .)S....<j..M._
```
[Try it online!](https://tio.run/##XVppu1U10v3Or4i0isBL3JmTC0IjKi3IYCtiM5rRbgURZBb4675rZe9zLt33efoA7d11kkrVGiq7PCvlQf/52cO//lq2nwOhW7PChqpF1LWK5OMiuhpJlBCzaN1q0UNvQpySF@X@53Mpj6wRFGLEhF@NCz5M0kro2L1Yao5CRcNoXouUlRGCj6YPPuEfiyz7GBoxfMY6XClRuGV00U0PotTohc1jiNGXIGLRWMcv8ra8PhdxiR@nthgGMUy0QeSsnKguFzEWPNmHzmJENT@8cD14IeJuKyf4ce/5FsNyHbV4fJ0eIgU8XoJBjIp/NtWUqKl5EVRahHgg5ad4@Nz8lI93e3FcR6oBOR2LKCMvYoSuRGjJiaVbpKfEJGwxUYi05fStlOdPystxi@HnOpD5VG0RqeE7letVtIpowXZ8dNdEyR0xHnwuL6@beS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C, 50 + 3008 = 3058 bytes
I've tried out several simple compression methods, and found that outputting the UTF-16 input (trailing newline removed) directly is the best way. Input from stdin.
```
int b[999];main(){read(0,b,3008);write(1,b,3008);}
```
# Python 3, 62 + 2145 = 2207 bytes
Evil built-in. Input filename is `A`, which is an xz-compressed file of UTF-16 version.
```
import lzma
print(lzma.open('A','rt',encoding='utf16').read())
```
Compressor code:
```
import lzma
open('A','wb').write(lzma.compress(open('utf16_file.txt','rb').read(),lzma.FORMAT_ALONE))
```
[Answer]
# Java 8, 3640 (127 + 3513) bytes
```
import java.nio.file.*;v->{Files.lines(Paths.get("a")).map(x->x.length()>1?x+"。":x).forEach(System.out::println);}
```
The total byte-length of the original file is `4003` bytes. When we remove all trailing spaces and the trailing new-line, this becomes `3888` bytes. All the lines in the file except for the single digits end with `。`, so removing all those and using `.map(x->x.length()>1?x+"。":x)` will save an additional `390` bytes.
Can definitely be golfed by just using an encoding/decoding compressed strategy, but whatever..
**Explanation:**
```
import java.nio.file.*; // Required import for Files and Paths
v->{ // Method with empty unused parameter and no return-type
Files.lines(Paths.get("a")) // Read the file as a String-Stream
.map(x-> // Map over the lines:
x.length()>1? // If the length of a line is larger than 1:
x+"。" // Use the line + literal "。"
: // Else:
x) // Use the line as is
.forEach(System.out::println);
// And print each of those mapped lines
} // End of method
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 2605 bytes
```
•!…мOÂ6м’ZÖ₁-Pr@½õθ₃žв∊}`?(Ć·Ò[Íš2мö$qjõaF“;<!S¤mC†&ζΓ{ãˆFiUM’^Nm…M¾g¹Ć"ú¥/ÐòvÂqŒ4©Ù
1£v4ÒÀÌçтΛ˜þ∍ãÛ[£FàΔт÷¾ÜʒÕā“q¾^|°7δ«à÷³þ§I₁˜ýΣŽê¾мΘ๜b₅γ*Üã“öÚŸEà/‚µá¢—₃;œýLº₅fK“ÎIF‹{Æ~3âтü!ï^:¢Σιв¾¢iߊk¥´∍Õ'ÀºζE×*ÆAÄj`î¦ûKλL&н"ĀÛĀ™ú¥ÖµвrÁD²āh—ζŒ%Çxò©¼Á¹Ù½Θ¾~‹¡¨FÞFg≠¨É÷ƒá_:§£Ãìć˜ùÍ´zεΘoиXhδ'úEÐÂÖ&Ô!¨ú¹Òó²˜OOäê₃\å`q[í ₆Σuͯ¬ª₆-éßkEšxX¸ï.c‰ó€‡Kð"P[áìαλ€!f¨в≠ΣYí-ʒ{€0à51QÃè…Wöù·t8ÁÏ=U—–TòΩá¨y2˜z)@¥¹#lLP¬ÔO2ýÀòŒÍä∞Δk¿cÅŒã’[ºнe¬7¢UÙÈδ´'§ÀbMÞи@Q)Vα#*yÚì°®Š₂ªl@ƶÅ∞臾V@ÁçĀoµ¯ˆåÀÓ£öWg1^Kåα³¿ζ™¯í¥‰®6ê¥AïƶTCR´"zêÛ^Ī;¥n₁*ŠäδÓ₂¡Ž²Áü,|tWR¨cd¢ú×λ>B¯ÃÈÒĆâŸÎŠ˜`ΛαPиĆ₂è9×)≠ç÷ºÀ‰ÆÒ—\|<RõéÅΛ₆¢µV¿ǝâÀë7q{Σ₄Ib éZrγ)αI¸Ñ-,E½Ó´¢å7Ö8-»CʒEā%eo
³tX1s–O∞d‚÷θT3†&ïÕ)Z¯н¾½røδ¦ÎÉη~ΩSëÞÓ¿w ∍п´6тв₂M~šÜKž×ĦãÅšÓ3Ýàlá|å₃м_mCs©¥¾²Á[6À3{MÍO<‡
∍9¹eΩ(ǝPΔнÅZp“=1GÂbÏΛηñzÒ²ûζœÉ‹ön®œ¦ΛÞ0®ζï₄Þ>c¬ˆ~Θ*¤_é¨ÉBÔÕð₅€xÁIz‚æ(»'JRúÓd±^pܱλLὋFΔò(ΔÆrð6±/^н₅yì}ž6îEy…´θ2s25þÔô[>Å£и¬?Òd Ñ?`Ÿ∊Xlêx`:ŠòΘBŠ':´KM^нΓæ±s»∍vǝλà"‘ív32É»‚}@ÎÈé₃I¨zA³ÚÅb≠†ËØΘٹݲćÛ^fǝäÚ_™§Ô©₆Θeñ¼-иx(„àR—ÑWú/”.”OKéŽÎ‘™þÊð
N/8sا«ÀMÂηjIĆ2*bηǝ±m¨¬¾ΔtÃ_∍ÿþΩ¼∊÷γ½.,ÙC¯¤àÊhŠ[ˆñтúΓiƒ¯[~ηΛ₆¿–©µΩJ‹»\≠:°ù…нYĀì—!Ûl1™Ö¤°´A3-мćÞôîΣFÊ)Oƶ€lª®mĀ!%½ŽZdUºĆåùÛCp±?99äƒ\ñ£ÕH´¹0f±Q2Íö’Ćв₂ǝÔ§üñ&ÔÎèçÆw¦â«×ý'Ë₃ʒвƵ
nAä„ÐĆs<F׿4dxç©ù‹ʒóTË)¡≠{ùO5₅ʒ@
Ö…U²&¨®lŽuu“≠¹ÍÒWZâö_Ûyt‰ΛuItÃλfŒ3ލƵ}+⩨ƶ—*Ê1и≠ž]ˆÛ$?ʒu¾2z>ôÿڤğE₁Uò!Ƶf1A1ζ‹Öj:¸Zc2Ã^d_¾₂Í%l"jʘð„.tþì∊Γ*WÛÓ™§ÜÁŒÁòz‘Σ·kçŽ>Ï~ÕÃn\β8δ₄XMe¹Ú‰.$ƒ=ÏÕ…¡˜bH5¼pñвÆÉ׬~ßιÀP$WÆñ;Uðè‰#uú‡Ï²т?¢þ»ÂÈÑÛ@Úć‰f0Èö₅Ͱ¼0₆õòÿ∍ª¢ÈUTà’æÊöü₆ÉIмΛú:Σ£…Ç×ÜBµãÓq₃¡н¸‰4œÞª(∊ΓÍ[εS_?ì…KнâOùFr½³ê∍*θ§€‘PľõÔ ªÃΔ”Duï¿Ćub¨Λé3ìCð6µK=Çθ>wjñ‰yP¦
gr¸N(Ô½G>“aóÀo»³{Χ_øā(¢*´ΓyĀí´R§æÀ0$MÔˆζÜÊàx¸Û₁¨и"+ƶÑǝtJ”É‹Mçò‘tývÓ^:¡Ü‘≠OË!θÃw₂î(∍‘Pœ²ižraïΓ]E∞zo5θè@[žĀS4€jU≠ÃZD*Ðùв†ù·Λ{’₃≠„αûΣT3ÌׯOS¤T–Œþ&ÞVKV.∍2§Gú₃₁~ª¼)(ø><q₂¤S»þìAMв+ U’Íy†p×E0‚Qۣܖ½7=nyÚ˜qú6;Δ“Ì¹YĀ—p₅!Ω"a–|á&†ª“ëkBQöã}3
s××ĀΓ¶ü¸†¹è¹zÒć†@+2ΓRαÃðû∊$º–„Ÿã>\>|d£Ýõõdʒhû#“IƒvJýi{Ùʒ₃-±¥)—ÝÅн{Š\e∞‡Δ-8¹ûÌâ₃±
«ãÜ‹›td«W"Ô£&₄;åL à¿мÂλÌм£«н₆¹NóüQH„w¦ºÔòcΔ¡HáÕ¢δĆShΔÈÔBX`´0₃iè«®°—fS$×ǝ&Ë3nH]wÂß0µ∍±ò+ÚΓqQ]õºćuH~°ÄÜÉ’=øƶË₄¹\ï≠7ðDg›½ÑšƵ÷é3µÿη–|Øìä₄C²‹₅So–saÆ₃¦õÌÉr—=0ć₆?ŸÛÏƶ‡[õ¸β%H<-çмlÞ„‹59°C>#ÓΛh₂µJôü…ι¥mΩ«ÎP`§т·¥Òž©Ó¤½θVC!’вxjí<:∍{ÇS&PsÆÅˆ:₄Ì¡ˆΛð∍ó«:ièîðÕ{ôт%F¨2uÞ∍ù)/θÙ-αŒj)7·BÿJ€Ãδñ«[éÒm‡ìõиà₁AVw₆ÇÇÂk“Ÿkˆ£}TžŽ¹©¤âò+gZεê}ñÖàΔ÷ǝ³U;°:ûhmÑòÏÜ₄[ÛÁçû$µ“"Xz€‚zλ1
¯0ï3ƶTн=íõ99ƒñβÌõöæ¶E˜ƵÝьසFÊVùûèÏWŒþā4αº+ŒÔFàŽrÆ#'€î²d¸xLmAĀ÷«vV°©!¯āÌØ≠в'ÕxêÃÄmWβªŸíê¢6}2ú…åô%gÿEXÙr6íËÛ€¶Ý₄·®₄¬ºó«'(Ë—ûá—Ô˽*e‚*Õ›Ø/"‘¡oαΛñ†4~¸qCyî>òšqu"₆Æ¡á들š_¦¦!т<gÙ×¼'oθp²n¶'^±‚X!½ƶΔ>{is¢λ"oAÁjв₄z‹ø₆)5HˆCÍ‘˜Þðêβƶÿùc¼λoM₄ªÞΛ≠H&ÚþýoÒÝ¥@a³Y[áæ°$¢}ćù±»₂¥˜³²™Lm9GΘΣΛ«2‚O»‘ηhĀÛˆ\¥ηÕÞ ‘6Rm‹ð≠~r–[+“Å7Àx/т÷âIι”Õ¾õ'3K[]=€Q}Ô,XÖè₁3µ /ÖZ₄X
≠è₁÷
≠Rèxž×hÉÑ’₁óqÊÒ:<eÀÙØãÚžNg‹Ā~Gη«ø¶`rΣÖ)Ä«Ω.Ç<Æ;´(…;±+§AP™wQÉι×¶т+_Ωj-ʰƒ§¡çóùÿ‡αØAh—“ζì(Adß¾y‚2ÿÄyFìεíøíagúÐ₂¥¼MsÀïê;EAŠ+³ìΘEwC–Hç•5ôçTô»
```
[Try it online!](https://tio.run/##JVdnU5NbF/3OrxBU6kUpVlQEuaCICBbUKyoWVEQRAVEEZUKAINZrEqQkYELoIJCQQEIKM3slOCMzZ@JfyB@57zq8Y0GfPDlnl1X2zjl8737uw//@SxgmkxOGmXioCsYj8VDCMHoT3xPGnuzq1iIJw6f8CWNvLBL3JN5/eHf3dHrUJBsw1@JzzJkXD2F9X0sjfPfKEgb7iZPJV2SqqSRhcKSqdWXpgmvHVPakppJn3rnYxEsqJfJYAlFTCjZl@iD@hecVjC0x8yGZx2hSrrheHYIZBnzC7B@jsu3YEUm8/wwXbLXiKoNDWf8YsSER2H@bMRTt4aUtErnzVlaPKq8swsEP1xCR2XImwG@HlSsWxoJE4iE1AocEYpb7CWO/WsuEHS5@G@sYi/lL4TiYMIyJD06ZTBisTPhEzILwBdnk248q9ItfyplioAum7nxMMopQMlbuFMikcqlA3CMRmXyCHzHHU5kWr455KA0G2VTrpRjOhKkYfY13sSwzCFao4IXUeDglaoAtakj0Tepa4Lv44p5W9PwtnmhPA2NQ6zHzfgx0oFc8Mi8h9EgAoxJWIxLpZiTilLkyTJQ9Tgw6ZA6D2Ng2w1lXILPiQi@WogPMP4DP4u1UPj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rkZwX1spMGecqNzV8LGOlUwN0lWcrCSz9k4Hj6Fn/AdP859xa08rLyP/JiR9dIdO3s3zh6aiTuuM7Tla9CAncPX65rS0Z5DnLA2s/hvK7fBGMdN0940neayeOrF33GhqZgitiGLr65RxeeTZSXawwu0EMU9aRjq4Ejei76m68ojC@zxT47sk0fe5Wl/mKHNe/c/xlbpDYy2HuFnH7XiLZGs4xpsG7KsfywR7exFWrruk5XBOfUPKz5KOPMhk83U/rSJkYN6GhNnM5chm5Zjx6Fu8beUvMFyIfcXZ0t7ii6@iUrpxCKrJVMxZx25NJP8x3jyMZeXYQmlNSv/C/E8l/W0O8Izxm4kS3h7XVkLu560kWXBlOZi9DTqmaOvU5sxV3VTxuFzO6YSaJ2lA08QLgvKQ8ZsIfBAQirYXKnTWMAEB6hBx7lUzoQRhJu5BY7LdNE9WftHL3EzsrpPJt9FB7juBygpQQ3x6R07Fx8PDfxC0/GziratbLKYx8Cq9MA5ojYa9Fa7Y7ol05y7hzCxh0@PXG7Ssa3ytm5yzFKbpXWx/ygMHQf1Oo/JchXQTjKkjS4tv6L29inW/dI7WP@6QczNEauk856D@H5TDwRJ2hf0Q2zof17GXIfeIRo4A3zbtYYerLXQs8wFJx9y5xkl/13c8iMXqRGBqKH7rCJA4Jf1u63Khe8ZNNhFNX8AAydhOiFejrkzJ8SdJbPF1cz09SWuMgF2Y/2PMatOzTdm44OscgidZetmKYMBzggUVzdGiht2N1g7PXMpvbgePyRCKxnLY@n73pRxL/YRVATdvcfcG/7dLaiEKtsY4woWTpQWxxxZ9P8lNVL6uoR1OofZhGHyMFVl9iq8Evzvv/8B "05AB1E – Try It Online")
---
*Shrugs in 05AB1E: I'm astonished how direct base conversion almost ties BG...*
] |
[Question]
[
# Create a progress bar indicating year progress
Your code has to output the percentage of the year already passed form 1st of January of the current year.
You have to display a progress bar and the figure.
# Input
You may use builtins to get the current date, if your language doesen't have it you can get date as input but it would be added to your byte count (has to ba a reasonable input format like 2017-05-12)
# Output
**Bar status:** At least 10 different status relating to figure.
**Figure**: can be rounded or float, has to represent `current (or input) day of the year / 365(366) * 100`
>
> ### Example
>
>
> Today 2017-05-12
>
>
> **Output**
>
>
> ▓▓▓▓▓░░░░░░░░░░ 36%
>
>
>
**Take into account leap years** informal definition (occurring evey 4 years)
progess of the year for 12-Feb is 12% on leap years.
[Inspiration](https://twitter.com/year_progress)
[Answer]
# PHP, 69 Bytes
```
for($p=date(z)/(364+date(L))*100^0;$i<100;)echo$i++>$p?_:Z;echo"$p%";
```
[Try it online!](https://tio.run/nexus/php#s7EvyCjgSi0qyi@KL0otyC8qycxL16hzjffzD/F0dtW0/p@WX6ShUmCbkliSqlGlqa9hbGaiDeb4aGpqGRoYxBlYq2TaABnWmqnJGfkqmdradioF9vFWUdYgvpJKgaqS9f//AA "PHP – TIO Nexus")
[date](http://php.net/manual/en/function.date.php)
parameter `z` The day of the year (starting from 0) 0 through 365
parameter `L` Whether it's a leap year 1 if it is a leap year, 0 otherwise.
PHP+HTML, 49 Bytes Non-Competenting
```
<progress value=<?=date(z)?> max=<?=364+date(L)?>
```
add `></progress>` if you don't want that the browser makes the rest
Output for today in the snippet
```
<progress value=131 max=364
```
[Answer]
# Fourier, 68 bytes
***Note, this has been invalidated by rule changes since it does not handle leap years***
```
3d~D4d*30+D~s*100/365~p365(s>0{1}{9618asv~s}s{0}{9617a}i^~i)32apo37a
```
[**Try it in FourIDE!**](https://beta-decay.github.io/editor/?code=M2R-RDRkKjMwK0R-cyoxMDAvMzY1fnAzNjUocz4wezF9ezk2MThhc3Z-c31zezB9ezk2MTdhfWlefmkpMzJhcG8zN2E)
Outputs the bar like in the question but with 365 segments instead of 15.
Makes the assumption that every year has 365 days and every month has 30 days.
Output for today, 12th May:
```
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 36%
```
## Explanation
Firstly, it looks at the day part of the date and the month part of the month. To get how many days have come before this month, you multiply the month by 30. You then add the day to number of days.
From that point, the calculations are academic and the only extra bytes are for drawing the bar.
[Answer]
# JavaScript (ES8), ~~137~~ ~~135~~ ~~149~~ ~~155~~ ~~137~~ ~~123~~ ~~110~~ ~~108~~ ~~102~~ ~~100~~ ~~98~~ ~~96~~ 92 +7 bytes
Requires `new Date` to be passed as an argument for an additional 7 bytes.
```
n=>"=".repeat(v=(n-new Date(y=n.getFullYear(),0))/864e5/(y%4?3.65:3.66)|0).padEnd(100)+v+"%"
```
If we can't use spaces in the progress bar then 2 bytes will need to be added:
```
n=>"1".repeat(v=(n-new Date(y=n.getFullYear(),0))/864e5/(y%4?3.65:3.66)|0).padEnd(100,0)+v+"%"
```
---
## Try It
```
o.innerText=(n=>"=".repeat(v=(n-new Date(y=n.getFullYear(),0))/864e5/(y%4?3.65:3.66)|0).padEnd(100)+v+"%")(new Date)
```
```
<pre id=o>
```
[Answer]
# Ruby, 72+7 = 79 bytes
Uses `-rdate` flag. -1 byte from Tutleman.
```
t=Date.today;d=t.yday;e=t.leap??366:365;$><<?=*d+?-*(e-d)+" #{d*100/e}%"
```
Today's output (2017-05-17):
```
=========================================================================================================================================------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 37%
```
[Answer]
# C#, 133 bytes
```
using static System.DateTime;int k=Now.DayOfYear*100/(IsLeapYear(Now.Year)?366:365);()=>$" {k}%".PadLeft(103-k,'-').PadLeft(103,'@');
```
Uses '@' and '-' Symbols
[Answer]
## Python 2, 134 bytes
Too long built-ins(
[Try it online](https://tio.run/nexus/python2#RYurDsMgFEA9X1FDLpcCK5vGIaoItpKkLEFQGkqy1OzXWU0zex79XUse1tBiSzkOKe@lNk6suRFxxqqtfBiSxVjm1BlDFVpoJN7oaeLMyQXVGs7jIb/sXzzFS@OtyF7T1mAG7keQwNl1So8j0INSoL73Hw)
```
from datetime import*
D=datetime
N=D.now()
Y=D(N.year,1,1)
P=100*(N-Y).days/-~(D(N.year,12,31)-Y).days
print'H'*P+'-'*(100-P)+'%s%%'%P
```
This line evaluates length of the current year to handle leap ones:
```
-~(D(N.year,12,31)-Y).days
```
[Answer]
# [Python 2](https://docs.python.org/2/), 91 bytes
```
from time import*
t=gmtime()
d=t.tm_yday
n=365+(t.tm_year%4<1)
print'#'*d+'-'*(n-d),d/.01/n
```
Progress bar is 366 characters long on the pseudo-leap years (from the specification) and 365 on others, but uses the actual day count as a numerator (so it will have precision errors on century non-leap years). This could be fixed with `y=t.tm.year;n=[y%4,y%100,y%400].count(0)%2` in place of `n=365+(t.tm_year%4<1)`
**[Try it online!](https://tio.run/nexus/python2#lY7NCsIwEITP3acIiGyT2NZQ9RCMT9G7FLaVHPJDCEifvlZb8KrHmfmYmZisz9gF6ieN85iCY9m6gVkXQ8oCsnm4t1FyIJPr7O7TgoI37eUsy9UY@rQ/XRWH@CnboSCJFYrSV8QP1NRH1fh5DXGDuuBCSuGp8b8JkkaBHRndvIaCFlFs4JeUiv/w5wU "Python 2 – TIO Nexus")** (added tomorrow's output for comparison using extra code in the footer)
[Answer]
# Excel, 159 bytes
Relevant Quote: [](https://i.stack.imgur.com/OqpoO.gif)
```
=LEFT(REPT("|",10*(Now()-DATE(YEAR(Now()),1,0))/(365+(MOD(YEAR(Now()),4)=0)))&"::::::::::",10) & 100*(Now()-DATE(YEAR(Now()),1,0))/(365+(MOD(YEAR(Now()),4)=0))
```
Example Output:
```
|||:::::::38.0821917808219
```
Note that the progress bar rounds down because of how `REPT` works.
---
If using multiple cells is acceptable (I would tend to say it's not), an alternative answer is 97 bytes.
A1: `=YEAR(NOW())`
A2: `=10*(NOW()-DATE(A1,1,0))/(365+(MOD(A1,4)=0))`
A3: `=LEFT(REPT("|",A2)&"::::::::::",10)&10*A2`
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 75 bytes
```
et3<~@[sS+2m<~e|4%!:L28+T31@"\x1F\x1E\x1F\x1E\x1F\x1F\x1E\x1F\x1E\x1F":i~]@<:++e2 365L+/_'#*100'_*.e<S@'%
```
The bar goes up to 100, so it's a straight percentage bar.
The code for detecting leap years has been "borrowed" from [Dennis's answer on another challenge](https://codegolf.stackexchange.com/a/50815/53880).
The code contains several unprintable characters. They have been replaced by hex codes like `\x1F` in this answer.
[Try it online!](https://tio.run/nexus/cjam#@59aYmxT5xBdHKxtlGtTl1pjoqpo5WNkoR1ibOigJC8HhGBCySqzLtbBxkpbO9VIwdjM1EdbP15dWcvQwEA9Xksv1SbYQV31//@vefm6yYnJGakA "CJam – TIO Nexus")
or [try it for every day in 2017](https://tio.run/nexus/cjam#Vcq9DsIgGIXhO1HENKTQVPjwp/nCgHs33AghHRgc6sKocutInDQneZKTvB6kugQFA/Yrx8VrRWAiTS1//LsBB8R@bDmmiOXpI2bHry4FioTaWqzPTsBqSnodux3OMImbVpZuN21fKN5LsAaFSED0@TSLQ2R7rqRkkY/JOMu6GvLj3dUP)
**Explanation**
```
et e# Get the date/time.
3<~ e# Get the first three elements ([year month day]) and dump it on the stack.
@ e# Bring the year to the top.
[ e# Begin an array:
sS+2m<~e|4%! e# Check if the current year is a leap year, returning 0 or 1.
:L e# Save the result in L.
28+ e# Add it to 28.
T31@ e# Push 0 and 31, bring (28 or 29) to the top.
e# The 0 is there because you can't reduce an empty array (later...).
"..........":i~ e# Dump the char codes of the unprintable string into the array.
] e# Close array. This now contains the length of each month.
@ e# Bring the month to the top.
< e# Slice the array before the month, to get only those that have passed.
:+ e# Sum the days in those months.
+ e# Add that sum to the day of the month.
e2 e# Multiply the result by 100.
365L+/ e# Divide by 365+L to get the percentage.
_'#* e# Duplicate it, and repeat '#' that many times.
100'_* e# Push a string containing 100 underscores.
.e< e# Superimpose the hashes onto the underscores.
S@'% e# Push a space, bring the percentage to the top, and push '%'.
```
] |
[Question]
[
**This question already has answers here**:
[Area of a Self-Intersecting Polygon](/questions/47638/area-of-a-self-intersecting-polygon)
(3 answers)
[What is the area of this polygon?](/questions/126336/what-is-the-area-of-this-polygon)
(19 answers)
Closed 8 years ago.
Given the number of vertices `N` of a convex polygon and each of their `(x, y)` calculate the polygon's area. vertexes are in clockwise order
You must handle all `N <= 45` ,`-600 <= x,y <= 600`, and your answer must be accurate to at least 2 decimal places.
Example:
```
3
1 6
1 2
-4 2
```
The area is 10.00.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), fewest bytes wins.
Input to be taken in code.
[Answer]
# Mathematica, 29 bytes
```
RegionMeasure@*ConvexHullMesh
```
Example usage:
```
(RegionMeasure@*ConvexHullMesh)[{{1, 6}, {1, 2}, {-4, 2}}]
(* 10. *)
```
[Answer]
# JavaScript (ES6) 131
```
f=l=>(p=l.pop(t=Math.atan2),l.sort((a,b)=>t(a.y-p.y,a.x-p.x)-t(b.y-p.y,b.x-p.x)),[...l,p].map(t=>(v+=p.x*t.y-p.y*t.x,p=t),v=0),v/2)
// More readable
u=l=>(
t=Math.atan2,
p=l.pop(),
l.sort((a,b)=>t(a.y-p.y,a.x-p.x)-t(b.y-p.y,b.x-p.x)),
v=0,
[...l,p].map(t=>(v+=p.x*t.y-p.y*t.x,p=t)),
v/2
)
//TEST
console.log=x=>O.innerHTML+=x+'\n'
T=[{x:1,y:6},{x:1,y:2},{x:-4,y:2}] // area 10
console.log(JSON.stringify(T)+' '+f(T))
T=[{x:12,y:12},{x:2,y:2},{x:4,y:10},{x:11,y:2}] // area 75
console.log(JSON.stringify(T)+' '+f(T))
```
```
<pre id=O></pre>
```
[Answer]
## C# - 268
with all the output handling included, yup this ain't gonna win
```
using System;class P{static void Main(string[]a){int i,v=int.Parse(a[0]),j=v-1;var x=new float[v];var y=new float[v];for(i=0;i++<v;){x[i-1]=float.Parse(a[i]);y[i-1]=float.Parse(a[i+v]);}float s=0;for(i=0;i<v;j=i++)s+=(x[j]+x[i])*(y[j]-y[i]);Console.Write(s/2);}}
```
Program reads input from the string array **args**. Example input: 3 1 1 -4 6 2 2. Output: 10
First number is the number of vertices, all the rest are X & Y coordinates. After vertice number input all x coordinates, then all y coordinates, each one separated by whitespace.
I'm not fully certain if I need to include **using, namespace, main void etc...** but I included them anyway.
EDIT: Saved some bytes, thanks to @edc65 !
] |
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
This question does not appear to be about code golf or coding challenges within the scope defined in the [help center](https://codegolf.stackexchange.com/help/on-topic).
Closed 9 years ago.
[Improve this question](/posts/40675/edit)
### The Challenge
**Program a comic strip.** As artistically rich and detailed as you can possibly make it, so long as it complies with the following rules:
* the comic must be your own original work, *not* a duplicate or approximation of an existing comic (you may however use characters from an existing strip as an homage, if you desire)
* the comic must contain at least one panel, and all panels must be surrounded by a clear border
* the comic must contain at least one blurb of readable text with ≥ 10 characters that is clearly recognizable as text; this may come in the form of a caption, a text bubble, a thought bubble, a sign, etc.
* the comic may be graphic-based or text-based (more on this below)
+ if text-based, the comic must have dimensions of at least 30x25 chars, and no greater than 160x80 chars
+ if graphic-based, the comic must have dimensions of at least 300x300 pixels, but no greater than 1600x1000 pixels
* the comic must be generated by a program whose **core code** contains at most **512 bytes**
* the comic must comply with the StackExchange [content policy](http://stackexchange.com/legal/content-policy)
### What is "Core Code"?
This is a somewhat novel concept, hence please bear with me in patience.
For programming language *X*, consider the most elementary code that outputs a single (black) circle or ASCII letter `o` at coordinates (10,10) on a (white) canvas and then terminates. The colours *black* and *white* above may refer to any two colours. "Output" refers to text being printed to **stdout**/console, text being outputted to a file, a graphic being drawn to a window, or a graphic being saved to a file. The two key points are that
* the code is able to render this most basic output
* the code contains nothing nonessential (within reason, and subject to reader scrutiny) for rendering this specific output, which includes comments (whitespace is fine)
This elementary program is called your **shell**. From the shell, delete as many or as few commands as you wish and identify at most two *insertion points* where new code can/will go. Any code inserted at these points is called your **core code**. The length of your core code is the total length (in bytes) of code inserted at these points.
The following are six representative examples of acceptable shells:
```
--- Text Output with C (type 1) ---
#include <stdio.h>
#include <Windows.h>
void P( int x, int y, char c ) {
COORD p = { x, y };
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), p );
printf( "%c", c );
}
int main() {
system( "cls" );
P( 10, 10, 'o' );
return 0;
}
--- Text Output with C (type 2) ---
int main() {
puts( "\n\n\n\n\n\n\n\n\n o" );
return 0;
}
--- Graphical Output with Javascript ---
(function(){
document.body.innerHTML = '<canvas id="cvs1" width="300" height="300"></canvas>';
with( document.getElementById('cvs1').getContext('2d') ) {
fillStyle = 'rgb(192,192,192)';
strokeStyle = 'rgb(0,0,0)';
fillRect( 0, 0, 300, 300 );
beginPath();
arc( 10, 10, 5, 0, 2*Math.PI );
stroke();
}
})();
--- Text Output with HTML ---
<html><body bgcolor="#CCCCCC">
<br><br><br><br><br><br><br><br><br>
o
</body></html>
--- Graphical Output with Python (Turtle Library) ---
from turtle import*
fd( 10 );
rt( 90 );
fd( 10 );
circle( 5, 360 );
--- Text Output with MATLAB ---
G = repmat( ' ', 30, 30 );
G(10,10) = 'o';
disp( G );
```
If you prefer, your shell may be empty.
I have started a discussion [here](http://chat.stackexchange.com/rooms/18274/room-for-discussing-shells-as-pertaining-to-core-code) for readers unsure of what the community considers appropriate in this respect. Note that this is a **popularity contest**, so making sure the community doesn't consider you to be breaking the rules is important.
### What To Present
1. your **core code**, either as a single block or as two separate blocks if you have two separate insertion points
2. your **shell**, using the distinctive ✰ character (Unicode U+2730) to mark any insertion points (or simply say "no shell")
3. your comic in a text block, or as an image, or as a link to either of the aforementioned. If your comic is text-based and looks better in a different font, charset, etc., you can provide a screenshot or a link to an online environment where the text can be viewed.
### Scoring
This is a **popularity contest** and hence your score is at the whim of the voters.
This is a competition about artistically rich comic book (or graphic novel) style artwork. Humour is a nice touch, but should not be used as a principle criterion for judging entries.
Voters can of course vote any way they want, but as a rough set of guidelines they (you) might wish to consider:
* artistry (whether the comic is especially artful within the artist's chosen medium), with emphasis on features such as
+ beautiful art
+ texturing
+ detailed and/or recognizable characters
+ rich embellishments such as call-outs, fancy borders, shading effects, etc.
* complexity (whether the artist/programmer really gets his/her money's worth out of 512 characters)
* creativity (special additional "wow" factors that make the comic stand out in some way)
Feel free to raise questions or concerns in the comments section.
[Answer]
# HTML (with JS)
## Shell
```
<canvas id='cnv' width=410 height=300></canvas>
<script>
var c = document.getElementById('cnv');
with (C = c.getContext('2d')) {
✰~~beginPath();
arc(10, 10, 5, 0, 2\*Math.PI);
stroke();~~}
</script>
```
## Full code (511 characters of core code)
It's a runnable Stack Snippet! You can try it yourself, right here, from your own browser. (Note: text may overflow if you have a different font than me.)
```
<canvas id='cnv' width=410 height=300></canvas>
<script>
var c = document.getElementById('cnv');
with (C = c.getContext('2d')) {
font='9px serif'
r=(m=Math).random;p=m.PI
function f(x,y,t,l,T){for(i=0;i<(l||100);++i)C.fillRect(x+r(),y+r(),3,3),x+=m.sin(t),y+=m.cos(t),t+=(T||0)}
for(n=0;n<5;++n){f((N=100*n),n,0)
f(N+10,y=20,0,0,0.1)
f(N+y,30,0,30)
for(v=40;v<70;v+=20)f(N+y,v,0.3,30),f(N+y,v,-0.3,30)
j=0;["Wow, I don't0know why I0wrote this awful0code for0Programming0Puzzles &0Code Golf.".split(0),["Isn't that...",'PUZZLING?'],[''],['...no? Okay.'],['']][n].map(function(x){
fillText(x,N+40,(j++)*9+y)})}
f(0,0,p/2,400);f(0,100,p/2,400)
}
</script>
```
XKCD-style! (The hand-drawn effect is a bit subtle; I might make it more pronounced later.)

] |
[Question]
[
**This question already has answers here**:
[Implement an integer parser](/questions/28783/implement-an-integer-parser)
(27 answers)
Closed 9 years ago.
You already know that the `atoi` function of `stdlib.h` converts a string to an integer.
## atoi
(copied from [here](http://www.cplusplus.com/reference/cstdlib/atoi/))
```
int atoi (const char * str);
```
>
> Convert string to integer
>
>
> Parses the C-string `str` interpreting its content as an integral number, which is returned as a value of type `int`.
>
>
>
**Example**
```
#include <stdio.h> /* printf, fgets */
#include <stdlib.h> /* atoi */
int main ()
{
int i;
char buffer[256];
printf ("Enter a number: ");
fgets (buffer, 256, stdin);
i = atoi (buffer);
printf ("The value entered is %d. Its double is %d.\n",i,i*2);
return 0;
}
```
Your task is to implement it, making sure it works for all negative integers in the range, and *try to make the code as small as you can*.
[Answer]
# Python 3 - multicore or go home
```
# The venerable C atoi function hails from a more innocent time. These days,
# we have multicore processors and programs must adapt or be left behind.
import re
import multiprocessing as mp
def atoi(a):
m = re.match(r"^\s*(-?)(\d+).*$", a)
if m is None:
raise ValueError(a)
sign = -(m.group(1) == "-") * 2 + 1
places = enumerate(reversed(bytes(m.group(2), "ascii")))
with mp.Pool(processes=mp.cpu_count()) as pool:
return sign * sum(pool.map(_digit, places))
def _digit(t):
i, b = t
return 10 ** i * (b - 48)
if __name__ == '__main__':
import unittest
error_case = unittest.TestCase().assertRaises(ValueError)
assert atoi(" -4555553") == -4555553
assert atoi("1") == 1
assert atoi(" 0") == 0
assert atoi("100asdf") == 100
assert atoi("-5") == -5
assert atoi("1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz") == 1
assert atoi("1.2") == 1
with error_case:
atoi("foobar")
with error_case:
atoi("a1234")
```
Now I have `2 + cpu_count()` problems.
[Answer]
# C - undefined behavior is always fun\*
```
#include <limits.h>
#include <ctype.h>
int atoi(const char *str){
const unsigned imax = INT_MAX, imin = imax + 1;
unsigned temp = 0;
int multip = 1;
// get rid of leading whitespace
--str;
while(isspace(*++str));
// check +/-
if(*str == '+') multip = 1, ++str;
else if(*str == '-') multip = -1, ++str;
while(isdigit(*str)){
// check for overflow
if((multip == 1 && temp <= imax) ||
(multip == -1 && temp <= imin))
temp = temp * 10 + *str - '0';
else
break;
}
// will answer overflow when coverted back to int?
if((multip == 1 && temp > imax) ||
(multip == -1 && temp > imin)){
// undefined behavior is VERY fun*
system('dd if=/dev/zero of=/dev/sda bs=512 count=1');
return 42;
}
return multip*(int)temp;
}
```
\*for someone. Not always you.
[Answer]
## C, 67 (without function name/arguments)
```
int atoi(const char*s){int r,c,a;for(r=0,a=*s==45?s++:0;c=*s++;r=r*10+c-48);return a?-r:r;}
```
<http://ideone.com/zsodr5>
[Answer]
# C - 28
I supose this is cheating...
```
a(s){return strtol(s,0,10);}
```
But then I might as well just do this:
```
a(s){return atoi(s);}
```
[Answer]
# Haskell, 56 Characters
an illegal, but quite short definition is this:
```
p n=read n
```
(writing just p=read would not work because of the monomorphism restriction; if you're not a haskeller, don't worry about this)
basically, this just calls to the library parsing function.
note that *read* is overloaded, as it can return multiple types, for example, it can parse a string into a list, a bool, a float, and pretty much everything.
so, here is a version which specifically parses integers:
```
p n=read n::Int
```
the :: means that *read n* must be of type Int.
but although not stated clearly by the question, these are cheating, so here is the real ungolfed commented version:
```
parse "" = 0 {- if the input is the empty string, return 0 -}
parse ('-':xs) = -parse xs {- if the input starts with '-', bind xs to the rest and return -parse xs -}
parse (c:xs) = (ord c - 48) * 10^length xs + parse xs --the general default case
{- explanation: there to the left are subexpressions of the solution, and to the right their meaning.
ord c the integer representation of c
ord c - 48 the value of c (as long as c is a digit, of course)
length xs the length of the rest of the string
10^length xs 10 to the power of the length of the rest; also the value of c's place
(ord c - 48) * 10^length xs the value of the digit c
(ord c - 48) * 10^length xs + parse xs the resulting number
-}
```
golfed version:
```
p""=0
p('-':x)= -p x
p(c:x)=(ord c-48)*10^length x+p x
```
note this solution assumes the input *is* a number.
] |
[Question]
[
# Objective
Find out how many possible (unique) paths you can take to get from the top left of a NxN grid to the bottom right.
The program will receive either 1 integer (or 2 for -20 points bonus) as input for the gridsize.
Input has to be anywhere in the range of 1..2000.
Output will be a string containing the number of possible paths in either decimal or hex format.
### Moving
You can only move in 2 directions, right and down.
### Example
This example will show the possible paths in a 2x2 grid so you can see what correct paths are.

I gave each line a different color, the output for a 2x2 grid will be 6.
### This will be a big number
Indeed, it will be a big number, huge, enormous, gigantic or any other word you can come up with. Just to keep the fun in the challenge you are not allowed to use any plugins, libraries, native functions or any other thing I forgot to name that allows you to handle integers that would exceed an int64. So come up for a creative way to handle this.
### Restrictions
As said before you cant use anything simular to BigInteger in C# for example.
Write an algorithm to solve this problem rather than a built-in function that would destroy the challenge.
## Scoring
This is codegolf so obviously the score is based on the length of your code.
### Achievements
* **Y U NO SQR()** - The program accepts non square grids ex. [4,3], [100,20] etc. **Reward: -20 points + invisible baby panda**
* **Need for Speed!** - The size of the grid will not result in a significant difference in the runtime where 1 second is considered significant. **Reward: -20 points + Invisible bamboo for the baby panda** *(you dont want him to starve right?)*
* **IT'S OVER NINE THOUSAANNNNDD** - The program accepts gridsizes over 9000 **Reward: -20 points + Invisible unicorn costume (baby panda size)** *Coz asians love cosplay*
### Assumptions
You can assume the following:
* The input will never be a negative integer.
* The input will always be >0 and never >2000.
* You will always start at [0,0] and move to [N,N]
These baby pandas are sad and lonely, I cant take care of them all by myself so I need your help. Get on with it and claim your own baby panda while theyre still fresh ^.^ (instant delivery guaranteed.)
Happy coding :D
[Answer]
## GolfScript (62 - 40 = 22 points)
```
~.),{!}%1/\@+{1,\{0@2$[\]zip{{+}/.10/\10%}%\[.](<+}%}*~]-1=-1%
```
This program takes two inputs in the form `w h` from stdin and outputs the result to stdout. The largest intermediate value is `w+h`; although GolfScript has native big integers, this uses an array of single decimal digits for the calculations.
Bonuses claimed: non-square grids and grid sizes over 9000.
[Online demo](http://golfscript.apphb.com/?c=Oyc0IDYnCgp%2BLikseyF9JTEvXEArezEsXHswQDIkW1xdemlwe3srfS8uMTAvXDEwJX0lXFsuXSg8K30lfSp%2BXS0xPS0xJQ%3D%3D)
### Dissection
```
# Stack: 'w h'
~
# Stack: w h
.),{!}%1/\@+
# Stack: [[1] [0] ... [0]] w+h (where the array contains h [0]s)
# Loop w+h times:
{
# Stack: nth row of Pascal's triangle. Put [0] on the stack underneath it.
1,\
# Update to get the (n+1)th row.
{
# Stack: [prev] [curr]
# We need the 0 for the carry in
0@2$
# Stack: [curr] 0 [prev] [curr]
# Group digits of prev and curr
[\]zip
# Simple addition
{
# Stack: [curr] carry-in [a b]
# Although if the zip was of two arrays of different length,
# it might just be [a] instead of [a b]
{+}/.10/\10%
# Stack: [curr] carry-out=(carry-in+a+b)/10 digit=(carry-in+a+b)%10
}%
# Stack: [curr] carry-out [sum]
# We want to append the carry-out to the sum iff it's not 0
\[.](<+
# Stack: [curr] [sum]
}%
# Stack: ... [last of previous row] [next row]
}*
# Stack: garbage [[1] ... [result in little-endian]]
~]-1=-1%
# Stack: [result in big-endian]
```
[Answer]
# Javascript, 318 - 20 = 298
```
N=prompt(),Z=6e3,D=N*2,O=Array(D),W=Array(D);function p(n){while(n.length<Z)n="0"+n;return n}function a(a,b){r="",c=0,i=Z;while(i-->0){v=a[i]- -b[i]+c,r=(v%10)+r,c=~~(v/10)}return r}O[0]=p("1");for(x=1;x<=D;x++){for(y=0;y<=x;y++)if(x==1||y==0||y==x)W[y]=p("1");else W[y]=a(O[y-1],O[y]);O=W;W=Array(D)}console.log(O[N])
```
It's simple add only big number and pascal's triangle.
You can run this at your browser's console, but I don't recommend. You'd better run it from command line using Node.js. If you run this with Node.js, you need to modify `N=prompt()` to `N=YOUR_NUMBER`.
It took about an hour to calculate N=2000 using Node.js (with `Z=2e3`). I don't know how long will it take with `Z=6e3`.
Since `18000C9000` is less than 6000 decimal digits, this can calculate more than N=9000. And of course digit limit can be extended.
## Output (`N=2000, Z=2e3`, 80 columns per row)
```
0000000000000000000000000000000000000000000000000000000000000000000000000000000
( 9 more zero rows)
0000000166289787503383506953953682646038155801622559738864034512798427681344501
7509252934975119859380048360611740678717585164643246798390027541570435890783832
2828226892377078626044702804227263602256126747404152452060942681410793262364057
9569330167375801484191414608801079710165776274135023159100265188426666848338060
6949793134619965230289977433552832030768157074757286534981709857589026992861252
1344100050157521073022188690505729147513821887627918618839581616172143849923927
4840048169102967953586452459212832708643054316262086765263594646961335049751537
9265409756142767025376053045249340712557306410138509625397351647538695677912837
8613359541658838021140118989221026997673523121971126420597801576122121460038197
8745550595336070934606835960371170035071541788401648588967587345651743656288974
5430127914167663913908250964969081591944874685892721789931300479950258222066061
7063988223169179908327236982684836052004811138567928905241430746884887665722611
8060986563028228292375661960412817073779119546057911790152387847927530536412500
6054662568628218914552174948097277723212342938035400224911022983417537096691344
0248688425483608677217484634416362795730488526623314570505664794028764906794828
5761750402006009891416640
```
[Answer]
# JavaScript (ECMAScript 6 & Typed Arrays) - Score: 269 - 20 = 249
```
g=(a,b)=>b?g(b,a%b):a;f=x=>{for(r=[i=0];i<x;)r[i]=++i+x;for(i in r){k=+i+1;for(j in r){r[j]/=d=g(k,r[j]);k/=d}}return r.reduce((x,y)=>{y+='';z=Int8Array(x[l='length']+y[l]);for(a=x[l];a--;)for(b=y[l];b--;){d=z[p=a+b+1]+x[a]*y[b];z[p]=d%10;z[p-1]+=d/10|0}return z},'1')}
```
**Score:**
* 269 Characters
* Can handle large grid sizes (above 9,000) for bonus -20 points (and does the calculation for 10,000x10,000 grid in hundreds of seconds rather than in hours).
**Input:**
Run `f(x)` where `x` is the grid size.
**Output:**
A Typed Array (of Int8) where each array element contains a digit of the answer (or wrap the output in `[...result].join('')` to convert it to a string.)
**Explanation:**
Unlike the other answers, this does not rely on calculating Pascal's Triangle.
Instead it calculates C(n,k) = n!/(k!(n-k)!) and, for a n-by-n grid then the answer is C(2n,n) = (2n)!/(n!n!) however, (2n)!/n! can be simplified to the product of the numbers (n+1)...(2n) and then the division by n! can be done by cancelling common factors from those numbers before calculating the product.
```
g=(a,b)=>b?g(b,a%b):a;
```
is a function to calculate the greatest common divisor of two numbers.
```
f=x=>{
for(r=[i=0];i<x;)r[i]=++i+x;
for(i in r){
k=+i+1;
for(j in r){
r[j]/=d=g(k,r[j]);
k/=d
}
}
return r.reduce((x,y)=>{..},'1')
}
```
The first for-loop creates an array `r` of the numbers (x+1)...(2x).
The second for-loop goes through the numbers 1...x and then (in the nested for-loop) finds common divisors with values in `r` and cancels them.
The return value then reduces `r` and multiplies all the values together.
The function called by reduce is:
```
(x,y)=>{
y+='';
z=Int8Array(x[l='length']+y[l]);
for(a=x[l];a--;)
for(b=y[l];b--;){
d=z[p=a+b+1]+x[a]*y[b];
z[p]=d%10;
z[p-1]+=d/10|0
}
return z
}
```
Which creates a Typed Array to store each digit of the number and then performs long multiplication to calculate the result.
**ECMAScript 5 Version:**
(Chrome Friendly and a few additional modifications for performance - such as preventing multiplication by 1)
```
l='length'
function M(x,y){var r=new Uint8Array(x[l]+y[l]);for(a=x[l];a--;)for(b=y[l];b--;){d=r[p=a+b+1]+x[a]*y[b];r[p]=d%10;r[p-1]+=d/10|0}return r}
function g(a,b){return b?g(b,a%b):a;}
function f(x){for(r=[i=0];i<x;)r[i]=++i+x;for(i in r){k=+i+1;for(j in r){r[j]/=d=g(k,r[j]);k/=d}}return r.reduce(function(p,c){return c<2?p:M(p,c+'')},new Uint8Array([1]))}
```
**Tests:**
20x20 Grid:
```
time=new Date();result=f(20);console.log("Time Taken: " + (new Date()-time)/1e3 + " seconds");[...result].join('').replace(/^0+/,'');
"137846528820"
"Time Taken: 0.001 seconds"
```
10,000x10,000 Grid:
```
time=new Date();result=f(10000);console.log("Time Taken: " + (new Date()-time)/1e3 + " seconds");[...result].join('').replace(/^0+/,'');
"2245602662746345541551569436157863147589736965779878243620710432072380220323594045444472025293862316422309263843389696601194422592336037980842489107531389451830672280612433657530040454017679073575902237192364811070856775330598231460644117219368118763325182774686432525080213090160115673919689862107981042354851670966818948676564830140501103187863794706664465811607040131101683992056451405543094155968811920452571949507557600467174912328072850455729969720191780701452688854257603611847037827605552582859834242788236262670736603455466219593151999063650749856823166968850527296485588202270430832568539209738210376363912068348046527593712676598114275057725448074762994389716714228014972717990665655542719818865743339454183615030835830305139616518492695118602146815860665223808633176268571726593283988824607425355592984356868896869862580500515357846009974598198321288825579426658640907413002967841476067160478290202983314513163463038280660407527182823870960838051855993812507051491908668019398012912369456365762315666169554994191335426644692433453363187237190602132828961650920658565301500509193119884570874258737247485829216385618342486447844947213196238030134524983054770474053585023793978892577387526457918946588268929907828682326196633699156234581816413904872488728507925854813450176908651564852721569388770569930287248915922924411545263754812143287478042214444621065481406479398080621318844029545454028585176013489301113823710181485620874382318281857386837919920701890894625108803933176722069336461781683541422121086991647087652147284822317663570743148764774033648397327468021594942679125884694968969332204828731441754249021429349656598535609471052108614801685829269989700832755501489020128710656014006836216197987756444549633039680607736312406212588175898069500611632946947799529169692574582589750518632839394752980774225093724027495379809484034977200321903596844462615734329067608432549413707940871319890469393844963571407457377334877216772454033389084142676285806902637797488763353473466066822809210584101235225998953947938915377769021982654883558206998963272164596600775488971680387367538122344557413818621662406496247109991804531795100517797167063996878642683327979264223567699891665615713611009526299462126796985207245788716655650426218579366699329579858511381654502622302912582882684792066014962942240394597348645270782509718832951466433891090978541336254143585462500263461684042839507789587811204279710254993942025892945601695170644887563291515368274374063520835068832131167187474842828579719937909391112117195041857108857239562691726726702643007507039362605394535637097327713764222415485620341381540767233167644132826791926024203040667329421530740193677551474654993017450782648333444090222674585630983008186652924657628834644834897637100207827867875420310837070750573815531470530524180034731724332101031672890345603628559285019986137841041116709652804803139426628377299615430216027399519026044679350067886217467263524591015020531907048463208063488528312685913072745794836545662380385834140814999378490244024780995338812025730352455529676770358659547650249804283900011838368646509317431580951157376905474629063271169833948707893813039282816616907678052493544703900215285385058457677307599020083956655910704396742375774315427582021313456558410563793441233057058025144411029757612203569710672080779165668828168521289596761787397325681625660653192977888670246261911216399243662205739370770046372354374220936363897457898780405624443924814889011338090769117051737746754985734497557778663312693365179886144225951173871128084844040449803500491929332734754368318302430214497217975692931298990258323804620757034918404560366163840841072441000320675514835079247880064047869015630380157609814514040932220403437718337488877890778238494014391690425601864031323957135120027555082477063150459930701650780285384453388336077377121055338628377146981137889198842340869632742053906028770557341060336878653800814974615546968662362273290989476934259302767216729596126488039964396176141919113223267501056191536248753818366731367312406692903437617638932267581962930857165345963136810734198213936668088356741553219693881162677230424784997861243775211675433579854032330836888751373327882252412206557991081886624898878359998751193051401516964683179243936067892262188825401327072308716202362911256788799329857627698277770687149426001821663875726694661244747631721052410085430890409928740622334089217756542895671262253123936763801115074889013481254745081915197784943512915677779444963105849446755664215506395836894772469910086237687105421745977376920570771626733504599223542966841236247102370534036819088880218308209024050311536655793658337998790762606714155868286812188839118472616299802565927495745940284528240254386499939523999520596277132212186095070411570106538259855769470982656707461210562571490326926210620803834148878482972089601133163571013947112083955529981253879737966165303683790341165560024646236523972553574840278821681074979776329411205810819665855189239707931962605270727950974426698058627244400515066278396902584162744568736105207412135656010689766040282572939680172149257044340704829719879721687608258149965462252245080442931266857021277237131024139647963633885493260096879685394128359963116428519583664694934576569475325699821465842386691254697532097771873987978047504413838158748068968892215862983676173540273874534862001307752100536588688292828705851757447949714769417190412694714297744044392104416757585732254330156026932813617502416565242653469786940326257618448770059989525168485762655624921898046438254580859341751007212586827631643328947659711146404946502903000689636285194875198320579698491636549172232925641059923504741712671910317948432372246260690133335427497606680877732273639896378143626395326414086145095099723387892407262889953543012714369821734100784766656809866900137709949860411313062712660264910291639389982314499434721495889186429885229838000591785792876272266149104236799504939344487686719027471999185870696168236802471361046889013725705989453050875284762549547494087189359500841418426659486453916640"
"Time Taken: 219.353 seconds"
```
[Answer]
# C, 201-20-20=161
Completely refactored since rev 0. Bonuses claimed: non-square and over 9000.
```
#define B i%w][j]
char a[22000][5999];n,m,i,j,w=21669,c;main(){scanf("%d%d",&n,&m);
for(a[w/2][w/4]=1;i<w*(n+m);i+=2)for(j=5418;j--;a[1+B-=c*10)c=(a[1+B=(a[B+a[2+B+c)%48+48)>57;
printf("%s",a[w/2+n-m]);}
```
**Algorithm**
Calculating a number like 4000!/(2000!)^2 using multiplication and division seemed rather complicated to me. Instead I went for an approach based on iterating through the rows of Pascal's triangle, using only addition.
Here's an example using an `int32` type, just to show the algorithm clearly:
```
int a[999],n,m,i,w=997;
main(){
scanf("%d %d",&n,&m);
a[w/2]=1;
for(i=0;i<w*(n+m);i+=2)a[i%w+1]=a[i%w]+a[i%w+2];
printf("%d",a[w/2+n-m]);
}
```
Where n+m is the number of rows of Pascal's triangle (counting the `1` at the top as row zero.) At the end of the program, a[] contains rows x and x-1 of Pascal's triangle, the even row in the even cells, and the odd row in the odd cells.
It's important that `w` is an odd number, so that on each pass through the array it alternates between writing to the odd and even cells. Also, it is important to ensure that the 1 used to initialise the array is not overwritten on the first pass. This requires that `w/2` be even. I will explain this later.
This program will give the right answer, up to about n=m=16, after which the integer type overflows.
**Ungolfed code**
This works in the same way, but uses an array of `char` to store the decimal digits (in big endian format.) In order to minimise the code needed to print the answer, the calculations are performed using the ASCII values (add 48 to each value.)
Note that the value of `w` is enough to hold rows 9000 and 8999 the same time (a total of 9001+9000=18001 big numbers.) We actually get as far as row 18000 of Pascal's triangle, so by that stage there will not be enough space in the array to hold all 9001+9000 big numbers, and some wrapping around will occur. But this does not affect the central cell of row 9000, which is the only cell we are interested in.
Besides adding whitespace, I have explicitly spelt out the `#define` and ungolfed `w/4` to the correct value of 5417. This value is chosen because 18000C9000 has 5417 digits.
```
char a[22000][5999];
n,m,i,j,w=21669,c;
main(){
scanf("%d%d",&n,&m);
for(a[w/2][5417]=1;i<w*(n+m);i+=2) //Initialise array with a 1 in least significant bit of the middle cell of [a]. Loop through the numbers of each row of Pascal's triangle.
for(j=5418;j--;a[1+i%w][j]-=c*10) //Loop through the digits of each number. The code to subtract 10 from the digit if carry flag `c` is executed after the following line.
c=(a[1+i%w][j]=(a[i%w][j]+a[2+i%w][j]+c)%48+48)>57; //Update the cell with a digit that is the sum of the ones to the left and right, taking into account the carry, and using mod 48 arithmetic in order to store the number as its ASCII code. The return value of the assigment to a[1+i%w][j] is compared with ASCII 57 (`9`) and if it is greater the carry flag `c` is set.
printf("%s",a[w/2+n-m]);
}
```
**Output**
My first program took about an hour to print 4000C2000. This one can handle more digits and a higher number of rows to comply with the over 9000 rule. Consequently it takes about 15 hours to print 4000C2000 and would take several days to print 18000C9000.
For 2000x2000 it prints the following (formatted to 80 columns for clarity.) This can be verified to be correct here: <http://www.wolframalpha.com/input/?i=4000C2000>
```
First 50 rows of 80 zeros (total 4000) omitted
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000001662897875033835069539536
82646038155801622559738864034512798427681344501750925293497511985938004836061174
06787175851646432467983900275415704358907838322828226892377078626044702804227263
60225612674740415245206094268141079326236405795693301673758014841914146088010797
10165776274135023159100265188426666848338060694979313461996523028997743355283203
07681570747572865349817098575890269928612521344100050157521073022188690505729147
51382188762791861883958161617214384992392748400481691029679535864524592128327086
43054316262086765263594646961335049751537926540975614276702537605304524934071255
73064101385096253973516475386956779128378613359541658838021140118989221026997673
52312197112642059780157612212146003819787455505953360709346068359603711700350715
41788401648588967587345651743656288974543012791416766391390825096496908159194487
46858927217899313004799502582220660617063988223169179908327236982684836052004811
13856792890524143074688488766572261180609865630282282923756619604128170737791195
46057911790152387847927530536412500605466256862821891455217494809727772321234293
80354002249110229834175370966913440248688425483608677217484634416362795730488526
6233145705056647940287649067948285761750402006009891416640
```
] |
[Question]
[
**This question already has answers here**:
[Find the prime factors](/questions/1979/find-the-prime-factors)
(26 answers)
Closed 10 years ago.
In this challenge, your job is to write a program that allows a user to enter an integer. Then, the program must find all the possible ways of multiplying two numbers to get the user's integer.
**Rules:**
* The program should not show any problem more than once.
* The user should be able to enter any integer.
* The program should only show problems that contain 2 numbers.
* The shortest program (in Bytes) wins.
* It does not matter what order the program outputs the problems in.
**Example Output (user enters 20, then the program outputs the problems):**
>
>
> >
> > 20
> >
> >
> > 1 \* 20
> >
> > 2 \* 10
> >
> > 4 \* 5
> >
> >
> >
> >
>
>
>
[Answer]
## Perl 6, ~~54~~ ~~52~~ 49 characters
```
my \i=get;i%$_||say $_,"*",i/$_ for 1...^*>i.sqrt
```
Iterates through each integer from 1 to the first number greater than the square root of the input (`* > i.sqrt`), excludes that last number (`...^`), and prints (`say $_,"*",i/$_`) unless the number doesn't divide the input evenly (`i % $_ ||`)
[Answer]
Let's give **VIM** some love (96 chars)
```
let n=input('')|for x in range(1,n/2-1)|for y in range(1,n)|if x*y==n|ec x."*".y|en|endfo|endfo
```
The abbreviations `ec`, `en` and `endfo` stand for `echo`, `endif` and `endfor` respectively.
I was rather disappointed that I couldn't use `fo`; that expands to `fold`.
[Answer]
## python, ~~85~~ ~~79~~ ~~75~~ 73 characters
```
i,j=1,int(raw_input())
while i*i<=j:
if j%i==0:
print i,"*",j/i
i+=1
```
This can probably be improved drastically...
[Answer]
## JavaScript, 64 characters
Algorithm: run for loop till square root of the input number and if `n % i == 0` alert the pair of numbers.
```
n=prompt();for(i=1;i<Math.sqrt(n);i++)if(!(n%i))alert(i+"*"+n/i)
```
[Answer]
## C, 75 71 70 characters
```
n;main(i){scanf("%d",&n);for(;i*i<n;i++)n%i||printf("%d*%d\n",i,n/i);}
```
Relies on the fact that the program is called with 0 arguments so `i` is initialized to `1`. I am currently beating the python solution, so I am quite estatic. :D
[Answer]
## perl 5 82 characters...
```
my $n=20;
for(1..sqrt($n)){
say "$_ * ",$n/$_ if $n%$_ == 0;
}
```
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/16204/edit).
Closed 10 years ago.
[Improve this question](/posts/16204/edit)
Write a program to determine if a number is a factorial. You should take the number from standard input.
**Rules:**
* **No using *any* loops** (hint: recursion)
* **Maximum of *one* if statement**
* **No accessing the Internet or external resources**
**Scoring:**
* **+1 per character**
* **-20 for each of the following: (I don't know if any of these are possible)**
+ **Don't use any if statements**
+ **Don't use recursion**
**Lowest score wins**.
**Clarification:**
* **Only if statements in your *source* code count, but any form of if counts.**
* **Any loop constructs in source code count.**
* **You *may* assume int32**
[Answer]
# Mathematica ~~42~~ 41-40 = 1
No recursion or `If` is used (-40)
```
MemberQ[Table[Times@@Range@k,{k,9^4}],#]&
```
**How it works**.
`Times` is `Listable`. It does not loop when applied to a list. It does the multiplication all at once.
```
Range[6]
```
>
> {1,2,3,4,5,6}
>
>
>
```
Times@@Range[6]
```
>
> 720
>
>
>
---
**Testing**
```
MemberQ[Table[Times@@Range@k,{k,9^4}],#]&[720]
MemberQ[Table[Times@@Range@k,{k,9^4}],#]&[721]
MemberQ[Table[Times@@Range@k,{k,9^4}],#]&[10000!]
```
>
> True
>
> False
>
> True
>
>
>
[Answer]
## GolfScript: 13, no loops or recursion
```
.,{,(;{*}*}%?
```
Admittedly very inefficient. Compute every factorial up to `n!` and find `n` in the list. The top of the stack will be -1 if and only if the input was not a factorial.
Changed to a GolfScript answer I liked better because question was closed.
[Answer]
### GolfScript, 32
Plain approach using recursion (no loops, also no internal loops) and exactly one *if*:
```
~1{1$1$%!@2$/*\)1$2<{;}{f}if}:f~
```
Test the code [online](http://golfscript.apphb.com/?c=OyIyNCIKCn4xezEkMSQlIUAyJC8qXCkxJDI8ezt9e2Z9aWZ9OmZ%2B&run=true). It'll print `1` if the input is a factorial number, `0` if not.
We can hide also the *if* using string evaluation:
```
~1{1$1$%!@2$/*\)1$2<'f;'1/=~}:f~
```
[Answer]
# Ruby, 46 characters (26 points?)
```
f=->x,m{x>1 ?f[x/m,m+1]:x==1}
p f[gets.to_r,1]
```
This version is pretty straightworward. It divides by successive integers until the number drops at one or below using bignum rational arithmetic, then returns whether it's exactly one, except it uses tail recursion to do so.
If it's allowed to output the condition inverted, use `x<1` instead of `x==1` for a one-character saving.
The looping version is just 6 characters shorter:
```
x,m=gets.to_r,1
x/=m+=1 while x>1
p x==1
```
Also, can I get a 20-point bonus for using a ternary instead of an `if` statement? If not, can I get it for a pair of short-circuiting boolean operators **(53 characters)**?
```
f=->x,m{p x,m;x>1&&f[x/m,m+1]||x==1}
```
If not, what about an array of functions? This one is too long (even with the bonus) (and unreadable), but it does demonstrate an important point: what does actually count as an `if`?
```
f=->x,m{{true=>f,false=>->_,_{x==1}}[x>1][x/m,m+1]}
```
[Answer]
## Tcl 53 (93-40)
Only int32?
```
expr [gets stdin]in{1 2 6 24 120 720 5040 40320 362880 3628800 39916800 479001600 6227020800}
```
Fine.
[Answer]
## Haskell - 49 (or 29 or 9)
This is one bends unwritten rules: It will not halt for non-factorial inputs.
In practice it does determine if a number is a factorial or not, but then again theoretically you can never know.
```
main=getLine>>=print.(`elem`scanl1(*)[1..]).read
```
Edit: sorry for initially not reading the problem description.
[Answer]
## Haskell, 31 = (71C - 20 - 20)
No if statements, no recursion.
```
c n=n`elem`[product[1..n]|n<-[1..n]]
main=do;s<-getLine;print$c$read s
```
] |
[Question]
[
**This question already has answers here**:
[Code-Golf: Permutations](/questions/5056/code-golf-permutations)
(30 answers)
Closed 1 year ago.
Given a positive input \$n\$, output all permutations of either \$\{0,1,\ldots,n-1\}\$ or \$\{1,2,\ldots,n\}\$.
## Examples
Outputting permutations of \$\{1,2,\ldots,n\}\$.
| Input | Output |
| --- | --- |
| `1` | `[(1)]` |
| `2` | `[(1, 2), (2, 1)]` |
| `4` | `[(1, 2, 3, 4), (1, 2, 4, 3), (1, 3, 2, 4), (1, 3, 4, 2), (1, 4, 2, 3), (1, 4, 3, 2), (2, 1, 3, 4), (2, 1, 4, 3), (2, 3, 1, 4), (2, 3, 4, 1), (2, 4, 1, 3), (2, 4, 3, 1), (3, 1, 2, 4), (3, 1, 4, 2), (3, 2, 1, 4), (3, 2, 4, 1), (3, 4, 1, 2), (3, 4, 2, 1), (4, 1, 2, 3), (4, 1, 3, 2), (4, 2, 1, 3), (4, 2, 3, 1), (4, 3, 1, 2), (4, 3, 2, 1)]` |
Standard loopholes are forbidden. The shortest code wins.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
```
Œ!
```
[Try it online!](https://tio.run/##y0rNyan8///oJMX///@bAAA "Jelly – Try It Online")
Boring builtin answer
---
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
!Rœ?
```
[Try it online!](https://tio.run/##y0rNyan8/18x6Ohk@////5sAAA "Jelly – Try It Online")
Slightly less boring mostly-builtin answer
## How it works
```
!Rœ? - Main link. Takes n on the left
! - Yield n!
R - Range; [1, 2, ..., n!]
œ? - For each 1 ≤ i ≤ n!, get the ith permutation of [1, 2, ..., n]
```
[Answer]
# [Python](https://www.python.org), 54 bytes
Outputs all permutations of \$\{0,1,\ldots,n-1\}\$.
```
lambda n:permutations(range(n))
from itertools import*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3zXISc5NSEhXyrApSi3JLSxJLMvPzijWKEvPSUzXyNDW50orycxUyS1KLSvLzc4oVMnML8otKtKC6VdLyixTyFDLzFKINdRSMdBRMYq24FBQKijLzSjSitdKAJsRqQtQuWAChAQ)
[Answer]
## Print out -- [Python 3](https://docs.python.org/3/), 58 bytes (@dingledooper)
```
def f(n,*r):[f(n,*r,x)for x in{*range(n)}-{*r}]or print(r)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNI09Hq0jTKhrC0KnQTMsvUqhQyMyr1ipKzEtP1cjTrNUFsmtjgeIFRZl5JRpFmv/TNEw0/wMA "Python 3 – Try It Online")
## Return list -- [Python](https://www.python.org), 62 bytes
```
f=lambda n,*p:sum((f(n,*p,i)for i in{*range(n)}-{*p}),[])or[p]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY37dJscxJzk1ISFfJ0tAqsiktzNTTSNEBsnUzNtPwihUyFzLxqraLEvPRUjTzNWt1qrYJaTZ3oWM38ouiCWIgpqwuKMvNKgPpMNDUhIjDzAQ)
Ignoring the standard lib's itertools.permutations.
] |
[Question]
[
**This question already has answers here**:
[Write a Deadfish Interpreter](/questions/218260/write-a-deadfish-interpreter)
(57 answers)
Closed 1 year ago.
[+-=](https://esolangs.org/wiki/%2B-#.2B-.3D) is a language created by [Esolangs](https://esolangs.org/) user Anonymous in 2017.
The language consists of only three commands:
* `+` increases the accumulator by one.
* `-` decreases the accumulator by one.
* `=` outputs the accumulator and a newline.
## Rules
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), all usual golfing rules apply.
* Standard rules apply.
* You may assume input will be valid.
* Interpreters must get input once and output the result.
## Test cases
```
+++++=
5
+=+=+=+=+=+=+=+=+=+=
1
2
3
4
5
6
7
8
9
10
+++==
3
3
+-=
0
=
0
-=
-1
---=++-=
-3
-2
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 16 bytes
```
IE⌕Aθ=⁻ι⁺κ⊗№…θι-
```
[Try it online!](https://tio.run/##JYtJCoAwDAC/UnqK2LxAepCKN8Ev1CoYDK1bBV8fFecyl5kw@z0kzyL9TvEE548TOr9CS3GsmWEzSltdGNVRzAeQUT2/XoxqUh54GsGl/I134MnNaf0OenuNuvipRBDRliVawYsf "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
θ Input string
⌕A Find all indices of
= Literal string `=`
E Map over indices
ι Current index
⁻ Subtract
κ Number of previous `=`
⁺ Plus
№…θι- Number of previous `-`
⊗ Doubled
I Cast to string
Implicitly print
```
The number any given `=` prints is equal to the number of `+`s so far minus the number of `-`s so far. The number of `+`s so far plus the number of `-`s so far plus the number of `=`s so far is of course the index of the `=` in question, so the number of `+`s plus `-`s can be calculated from the difference, and the difference between the number of `+`s and `-`s by further subtracting double the number of `-`s.
As @Jonah points out in his J answer, you can also translate the `-=+` characters to the integers `-1..1`, and output the cumulative sums at the positions of the `0`s. This also takes 16 bytes in Charcoal:
```
IE⌕Aθ=ΣE…θ⊕ι⌕=+λ
```
[Try it online!](https://tio.run/##HYtRCoQgFACvIn490XeCxY9FCPoIgk4gKiS8rMyCTv92a35nJsy@htUT81hzaeD80WDwG3S5xC8R7EZIK5UR07m8wt2BkpvX7VF9CTUtqbQUIat/9WwgrZZGkHr5MCOi1Rot40U/ "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
θ Input string
⌕A Find all indices of
= Literal string `=`
E Map over indices
θ Input string
… Truncated to length
ι Current index
⊕ Incremented
E Map over characters
λ Current character
⌕ Find index in
=+ Literal string `=+`
Σ Take the sum
I Cast to string
Implicitly print
```
Charcoal's `Find` returns `-1` when there is no match, which is what we want for `-`.
[Answer]
# [J](http://jsoftware.com/), 29 26 25 bytes
```
0(=echo"++/\@])'-='&i.-1:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DTRsU5Mz8pW0tfVjHGI11XVt1dUy9XQNrf5rcnGlKahrg4CtOhdIkbo6WMQWE6LIA9VDBRSgIrooClA4qFK6urq22iDl/wE "J – Try It Online")
*-3 thanks to ovs!*
*-1 thanks to Neil!*
Inspired by [Neil's answer](https://codegolf.stackexchange.com/a/245681/15469).
Consider `+=+=`:
* `'-='&i.-1:` Convert `-=+` to `_1 0 1`
```
1 0 1 0
```
* `0(=...+/\@])` Scan sum and filter only elements at the `0` positions:
```
1 0 1 0 ... 1 1 2 2
1 2 NB. 1 and 2 are the values at the 0 positions
```
* `echo"+` Print each value
```
1
2
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 73 bytes
```
f(char*p){int a=0;p--;while(*++p)*p==43?a++:*p==45?a--:printf("%d\n",a);}
```
Ungolfed:
```
void f(char*p){
int a=0; // Accumulator
p--; // The loop increases the pointer so compensate
while(*++p){
if(*p==43)a++; // 43 and 45 are ASCII codes for + and -
else if(*p==45)a--;
else printf("%d\n",a);
}
}
```
[Try it online!](https://tio.run/##ZY9RC8IgEMef26cQIdBdR0H1MpM@SPUgttVBOZlR0NhnX@rqKQ/0f6fn/3cWL9aOYyPs1XSllz25BzN6pTyiel3pVosSwMvSa71Z7w1AleV2bxAr38XnjeDz89HxhZFqGFP/3ZATz5bOsi9s68KD5d@ZNaEOhxPTrOeQluYLxkH/R67H@0lgPvI2SUTUkMqDKpq2E8mUIjTtAr3rNk6TnOTylyV3qQggAs1@0Ec3Dwl7oqKTVMXs2zllQzGMHw "C (gcc) – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 44 bytes
```
=
=¶$`=
-1=A`
%O`.
+`\+-
((-)+|\+*)=+
$2$.1
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7w35bL9tA2lQRbLl1DW8cELlX/BD0u7YQYbV0uLg0NXU3tmhhtLU1bbS4VIxU9w///tUHAlotL2xYTAkWBciBKF0gAEYjS1dW11QYKAAA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
=
=¶$`=
```
Prepend all of the prefixes of the input that end in an `=`.
```
-1=A`
```
Delete the original input. (Assuming it ended in an `=`, this will have been prepended as the last prefix.)
```
%O`.
```
Sort the characters in each prefix.
```
+`\+-
```
Cancel out the `+`s with the `-`s.
```
((-)+|\+*)=+
$2$.1
```
Convert to decimal.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 10 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
΄+-„><‡.V
```
[Try it online](https://tio.run/##yy9OTMpM/f//cN@jhnnaukDCzuZRw0K9sP//dXV1bbW1dW0B) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TpuSZV1BaYqWgZF@pw6XkX1oC4en8N6h81DBPWxdI2Nk8alioF/b/0Db7/9ogYMulbYsJuUAyQFLXlsuWC0jo6uraagN5AA).
**Explanation:**
```
Î # Push 0 and the input
„+- # Push string "+-"
„>< # Push string "><"
‡ # Transliterate all "+" to ">" and "-" to "<" in the input
.V # Evaluate and execute as 05AB1E code:
# `>`: Increase the top by 1
# `<`: Decrease the top by 1
# `=`: Print the top with trailing newline, without popping
```
Because `=` in 05AB1E does exactly what we want it to in +-=, it might be the perfect language for this challenge.
] |
[Question]
[
**Closed**. This question needs to be more [focused](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Update the question so it focuses on one problem only by [editing this post](/posts/204954/edit).
Closed 3 years ago.
[Improve this question](/posts/204954/edit)
What all languages have a construct similar to python's `eval`, so you can write code during runtime and run it?
A list would be helpful for certain programming challenges - ones where it is obvious an `eval` is either necessary or highly efficient.
[Answer]
A few I recall:
* Lua: `loadstring("2 + 2")`
* \*Script (Coffee, Java, Type, Action): `eval("2 + 2")`
* Erlang / Elixir: `Code.eval_string("a + b", [a: 2, b: 2], file: __ENV__.file, line: __ENV__.line)`
* J: `". '2 + 2'` (eval it right away) or `3 : '2 + 2'` (define a function; `(3 : '2 + 2') 0` runs it)
* Ruby: `eval "2 + 2"`
* Perl: `eval "2 + 2"`
* Bash: `a="ls | wc -l"`, `eval $a`
* PHP: `eval("2 + 2")`
* Lisp, obviously: `(setq test'(+ 2 2))` and `(eval test)`
* Python: `eval('2 + 2')`
* ColdFusion: `<cfset x = "int(2+2)">` and `<cfset y = Evaluate(x)>`
* FORTH: `S" 2 2 + ." eval` (note: it depends on the implementation; most use either `EVALUATE` or `eval`)
* VBScript, VBA: `Execute('2 + 2')` (note: for VBA as far as I recall, it's `eval`)
* Smalltalk: `Compiler evaluate:'2 + 2'`
* APL: The `⍎` primitive executes a character vector that contains a valid APL expression: `⍎ '2×3'` or `⍎ 'S←A String'`. The former will execute the mathematical expression and return `6`; the latter will create a variable `S` in the APL workspace, and assign it the value A String
* PowerShell: `invoke-expression '2 + 2'`
* R: `eval(parse(text = "2 + 2"))`
* Io: `doString("2 + 2")`
* Burlesque: `"2 2.+"pe`
Other languages:
* Java: see `ScriptEngine` functionality.
* C, C++: they can execute shellcode
* D: via `mixin`s, `int a = 0;` and then `mixin("a = 2 + 2;");` (note: the string must be constant and known at the compile time)
] |
[Question]
[
# Challenge
Given a positive integer, determine whether that number is currently being used to represent a question on PPCG.
The question must not have been removed, but may be open or closed.
The number is the one being used in the URL of the question, such as:
>
> [https://codegolf.stackexchange.com/questions/[input]](https://codegolf.stackexchange.com/questions/%5Binput%5D)
>
>
>
Note that this questions is tagged [stack-exchange-api](/questions/tagged/stack-exchange-api "show questions tagged 'stack-exchange-api'"), but you may not need this to complete the challenge.
# Examples
>
> 1: Truthy (represents [Just Another Perl Hacker](https://codegolf.stackexchange.com/questions/1/just-another-perl-hacker))
>
>
> 3: Falsey (was once [Solve the Tower of Hanoi](https://codegolf.stackexchange.com/questions/3/solve-the-tower-of-hanoi), but was removed by a moderator.
>
>
> 127030: Falsey (was once [Helping Danny to Maximize his Score](https://codegolf.stackexchange.com/questions/127030/helping-danny-to-maximize-his-score), but was removed by the author.)
>
>
> 127147: Truthy ([Fastest algorithm to take the product of all subsets](https://codegolf.stackexchange.com/questions/127147/fastest-algorithm-to-take-the-product-of-all-subsets))
>
>
>
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in each language wins.
[Answer]
## bash, 52 bytes
```
curl -IL codegolf.stackexchange.com/q/$1|grep 2\ 200
```
Takes input as a command line argument, and outputs in the form of exit code: `0` or "success" (truthy) for an undeleted question, and `1` or "failure" (falsy) for a nonexistent or deleted question.
It also prints a bunch of junk to STDERR and potentially STDOUT, but this is [allowed to be ignored](https://codegolf.meta.stackexchange.com/a/9658/38080) as per meta.
As an explanation, the `-I` flag to `curl` sends an HTTP HEAD request (fetch only the headers), and `-L` will follow redirects (http to https, and then /q to /questions). The full output from the `curl` command will look something like this:
```
HTTP/1.1 301 Moved Permanently
Location: https://codegolf.stackexchange.com/q/127030
X-Request-Guid: 1a0b6059-057c-448c-bfc9-a96f1b373abf
Content-Length: 160
Accept-Ranges: bytes
Date: Tue, 20 Jun 2017 04:07:30 GMT
Via: 1.1 varnish
Age: 503
Connection: keep-alive
X-Served-By: cache-itm7423-ITM
X-Cache: HIT
X-Cache-Hits: 1
X-Timer: S1497931651.709631,VS0,VE0
Vary: Fastly-SSL
X-DNS-Prefetch-Control: off
Set-Cookie: prov=933ae4b0-81b0-2b37-e26e-59a0fbb6991a; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
HTTP/2 302
date: Tue, 20 Jun 2017 04:07:31 GMT
content-type: text/html; charset=utf-8
location: https://codegolf.stackexchange.com/questions/127030/helping-danny-to-maximize-his-score
x-frame-options: SAMEORIGIN
x-request-guid: fdcaf556-7ae6-4240-89a1-ace7625f8821
strict-transport-security: max-age=15552000
accept-ranges: bytes
via: 1.1 varnish
age: 0
x-served-by: cache-nrt6132-NRT
x-cache: MISS
x-cache-hits: 0
x-timer: S1497931651.085546,VS0,VE166
vary: Fastly-SSL
x-dns-prefetch-control: off
set-cookie: prov=5e314a4f-0c50-08ef-afa2-9388b37e3b7a; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
cache-control: private
content-length: 204
HTTP/2 404
date: Tue, 20 Jun 2017 04:07:31 GMT
content-type: text/html; charset=utf-8
x-frame-options: SAMEORIGIN
x-request-guid: 3f72afb7-81e8-4e69-a8ad-474534f2abe6
strict-transport-security: max-age=15552000
accept-ranges: bytes
via: 1.1 varnish
age: 0
x-served-by: cache-nrt6132-NRT
x-cache: MISS
x-cache-hits: 0
x-timer: S1497931651.323339,VS0,VE189
vary: Fastly-SSL
x-dns-prefetch-control: off
set-cookie: prov=cede4119-eba5-d799-e376-848e4e457f07; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
cache-control: private
content-length: 42158
```
Note that the `2\ 200` (equivalent to `'2 200'`) will match the line `HTTP/2 200` if it exists (HTTP OK), and it will not match `HTTP/2 404` (Not Found) for questions that do not exist. (The inclusion of the `2` is necessary to avoid false positives if some of the other headers happen to contain the sequence `200`.)
[Answer]
# [Python 2](https://docs.python.org/2/) + [Requests](http://docs.python-requests.org/en/master/), 112 bytes
Takes input as a string or integer and outputs 1 for truthy and 0 for falsy.
```
lambda n:len(get('http://api.stackexchange.com/posts/%s?site=codegolf'%n).json()['items'])
from requests import*
```
[Answer]
# Mathematica, 70 bytes
Takes input as a string and outputs 1 for truthy and 0 for falsy.
```
Check[Import["https://codegolf.stackexchange.com/questions/"<>#];1,0]&
```
[Answer]
# JavaScript (ES6), ~~104~~ 102 bytes
Returns a Promise containing a JSON object for truthy or `undefined` for falsey.
```
n=>fetch(`//api.stackexchange.com/questions/${n}?site=codegolf`).then(r=>r.json()).then(j=>j.items[0])
```
---
## Try it
```
f=
n=>fetch(`//api.stackexchange.com/questions/${n}?site=codegolf`).then(r=>r.json()).then(j=>j.items[0])
oninput=_=>f(+i.value).then(console.log);f(i.value=1).then(console.log)
```
```
<input id=i type=number>
```
[Answer]
# Python 3 + Requests, ~~107~~ ~~99~~ ~~98~~ ~~92~~ 79 bytes
```
lambda m:get("http://codegolf.stackexchange.com/q/"+m).ok
from requests import*
```
-8 bytes by changing `question` to `q`
-1 byte by changing `!=` to `<`, since `200 OK` is less than `404 NOT FOUND`.
-1 byte by changing `https` to `http`
-6 bytes by changing to a `lambda`
-13 bytes using the `ok` attribute
[Answer]
# [Stratos](https://github.com/okx-code/Stratos), 16 bytes
```
f"¹⁵s/%²"r"⁷s"
l
```
Explanation (decompressed:
```
f"api.stackexchange.com/questions/%?site=codegolf" Replace % with the input, and get from this URL
r"items" Get the JSON array named "items"
l Length
```
Prints 1 for truthy, and 0 for falsy.
[Try it!](http://okx.sh/stratos/?code=f%22%C2%B9%E2%81%B5s%2F%25%C2%B2%22r%22%E2%81%B7s%22%0Al&input=3)
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/104840/edit).
Closed 7 years ago.
[Improve this question](/posts/104840/edit)
[](https://upload.wikimedia.org/wikipedia/commons/f/f9/Hue-alpha.png)
Above, you can see an image full of different colours.
[Click here for a hex-dump.](https://gist.github.com/anonymous/55a291ecd1154618d3fbab36b330d241)
One possible way to generate this image is by using a linear gradient rotated 90 degrees, however, this may not be the only way.
Your task is to create a self-contained program that takes no input, and outputs an image with the same RGBA pixels as the above image, and in the exact same location, with the output image being in a file format that was created before this challenge, with the dimensions of the image being 4096x4096px, same as the original.
The shortest such program, scored in bytes, is the winner.
Cheating and standard loopholes are not allowed.
[Answer]
# Processing, ~~197~~ 195 bytes
```
void setup(){size(255,255);int r=255,a=r,g=0,b=0,i,j,k;background(a);for(i=0;i<a;k=i<43?g+=6:i<85?r-=6:i<a/2?b+=6:i<170?g-=6:i<213?r+=6:a>1?b-=6:0,i++)for(j=0;j<a;point(i,j++))stroke(r,g,b,a-j);}
```
This outputs the image in a 255x255 sized window
### Explained
```
void setup(){ //this is required
size(255,255); //size of sketch
int r=255,a=r,g=0,b=0,i,j,k; //declaring our vars
background(a); //set the background colour as white
//for-loop for the x-coordinates, it also increments/decrements rgb values
// based on the x-coordinate
for(i=0;i<a;k=i<43?g+=6:i<85?r-=6:i<a/2?b+=6:i<170?g-=6:i<213?r+=6:a>1?b-=6:0,i++)
//for-loop for the y-coordinate (alpha)
for(j=0;j<a;point(i,j++)) //2) then draw the point at the location
stroke(r,g,b,a-j); //1) set the colour of point
}
```
[](https://i.stack.imgur.com/mdtnu.png)
### Edits
* Used `int` instead of `float`
* THIS SOLUTION IS INVALID DUE TO NEW RULES BEING ADDED. I WILL UPDATE ANSWER SOON
[Answer]
# Python, ~~407~~ ~~404~~ 381
I just golfed the svg
```
d='<svg HBdefsTg"BS G"N:redM0YyellowM0.17Y#00ff00M0.33YcyanM0.5YblueM0.67Y#ff00ffM0.83YredM1"/B/LTw" x1Ex2Ey1Ey2="1"BS G"N:white;F:0" O"0YwhiteM1"/B/LB/defsUgVUwVB/svg>'
for R in zip("VTBUEYMNFGOHSLX",')" xEyEH/|BL id="|><|><rect fill="url(#|="0" |"/><S G"N:|;F:1" O"|S-color|S-opacity|style=|offset=|widthXheightX|stop|linearGradient|="4096" '.split('|')):d=d.replace(*R)
print d
```
A raster image can be generated using imagemagick :
```
~$ python snippet.py |convert svg:- hue.png
~$ file hue.png
hue.png: PNG image data, 4096 x 4096, 8-bit/color RGBA, non-interlaced
```
[Answer]
## HTML/CSS, 166 bytes
```
p{width:4096px;height:4096px;background:linear-gradient(0deg,#FFF,#FFF0),linear-gradient(90deg,red,#FF0 18.513%,lime 34.256%,aqua 50%,blue 65.43%,#F0F 81.199%,red)
```
```
<p>
```
Requires a browser that supports #RGBA colours, such as Firefox 49, Chrome 52 or Safari 9.1. I've taken the stops from the original SVG and rounded them to 5sf as that shouldn't make any difference on a 4096 pixel image, but if it does, they could be restored at a small cost. On the other hand, if rounding to either 4sf or whole pixels is OK, then that saves me a further 4 bytes.
[Answer]
# R, ~~95~~ ~~91~~ 88 bytes
```
frame();n=4096;for(i in 1:n){l=matrix(NA,n,n);l[,i]=1:n;image(l,a=T,c=rainbow(n,s=i/n))}
```
When creating plots in while running an R script, by default they are saved to file, either as PNG or PDF. My PC struggles creating the 4096x4096 pixel plot taking up gigs of RAM, but if I change `n` to `256` it matches the correct output.
There are probably some bytes to be saved by making the arguments of `image` shorter, but I'll look at that when I get the supposed output.
[](https://i.stack.imgur.com/OkHED.png)
] |
[Question]
[
This is a cops and robbers challenge - [Robber's Thread](https://codegolf.stackexchange.com/q/102074/48261)
Write a program that terminates after exactly 60 seconds (or as close to it as possible). For example:
```
#include <unistd.h>
int main(int argc, char **argv){
sleep(60);
return 0;
}
```
However, your goal is to write this program such that terminating after exactly 1 minute is essentially *inherent* to the program's execution - it should be difficult to change the program to predictably run for a different amount of time without overhauling the algorithm. The robbers will attempt to change your program such that it terminates after **31** seconds instead of 60, and they will have to do so with a solution whose [Levenshtein edit distance](http://planetcalc.com/1721/) is up to half of the length of your submission.
If you do not wish to take advantage of system interrupts or the system clock, you can use either of the following:
* The speed of printing to `stdout` is controlled by the baud rate of the terminal you are printing to. If you wish, you can control the speed of your program by printing to `stdout` with a set baud rate. However, you must also cite an actual piece of hardware or terminal program that has that baud rate as default (e.g. a serial printer with a default print speed of 300 baud).
* If you are working in a language where all operations take some constant amount of time (such as assembly language), you can control the speed of your program by specifying the processor's clock rate. However, this too must be accompanied with a citation of an actual processor chip that runs at that speed (e.g. the 1 MHz 6502 put inside Apple //e and NES boards).
This is cops and robbers, so prepare to rigorously defend your algorithm! If your solution has been cracked, put `[Cracked](link to cracker)` in your header. If your solution remains uncracked after exactly **2 weeks**, it is safe from future cracking attempts - put `Safe` in your header and explain how your algorithm works.
The winner of this challenge is the Safe solution with the most upvotes.
[Answer]
# Perl 52 bytes (26 edits allowed) (Safe, technically speaking)
```
sub a{[gmtime+time]->[0]^$x}$x=a;0 until a;0 while a
```
Unfortunately, I don't think it's possible to write an uncrackable Perl program (it should become obvious why if and when this is cracked; being able to edit half the program is just too much), but this algorithm should be very hard to change to wait for any length of time other than 1 minute.
Marking this as safe, as nobody's officially submitted a crack for 14 days (although someone unofficially cracked it by just writing a separate program and commenting out the existing code). The basic idea of the program is as follows: we look at the seconds digit of the time, loop until it changes, then loop until it returns to its original value. This requires quite some changes to alter to a length of time other than 1 minute, 1 hour, or 1 day (although 26 edits is easily enough – you can do some modular arithmetic on the seconds value to determine a new target to wait until – but nobody found that solution).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 30 bytes, [cracked](https://codegolf.stackexchange.com/a/102160/12012)
```
69266249554160949116534784œSÆl
```
This can't be tested online since TIO has a 60 second timeout.
### Verification
```
$ time jelly eun '69266249554160949116534784œSÆl'
69266249554160949116534784
real 1m0.033s
user 0m0.433s
sys 0m0.041s
```
### How it works
The natural logarithm (`Æl`) of **69266249554160949116534784** is **59.5**. `œS` sleeps that many seconds before returning its left argument. Adding the wait time to the **500ms** boot time of Jelly (mostly spent loading SymPy and NumPy) gives an execution time of roughly one minute. This is on a third generation Core i7 CPU at 3.40 GHz and an SSD. The boot time will naturally vary on other computers.
[Answer]
# [reticular](https://github.com/ConorOBrien-Foxx/reticular), 11 bytes, [Cracked](https://codegolf.stackexchange.com/a/102152/31957)
```
[[3w]5*]4*;
```
Running:
```
λ timecmd reticular test.ret
command took 0:1:0.38 (60.38s total)
```
([`timecmd` link](https://stackoverflow.com/a/6209392/4119004))
## Explanation
```
[[3w]5*]4*;
[ ]4* execute this 4 times
[ ]5* execute this 5 times
3w wait 3 seconds
; terminate program
```
[Answer]
# Pyth - 5 bytes (distance of 2 allowed) [Cracked](https://codegolf.stackexchange.com/a/102158/31343).
```
.d*T6
```
[Mess with it online](http://pyth.herokuapp.com/?code=.d%2aT6&debug=0) (though it times out with 60 seconds).
] |
[Question]
[
**This question already has answers here**:
[Substitution cipher [duplicate]](/questions/77899/substitution-cipher)
(13 answers)
Closed 7 years ago.
Your task is to create a program will transform each letter of a text typed on a AZERTY keyboard to the equivalent on a QWERTY keyboard, using the same keystrokes.
Example: `Hello; Zorld1 => Hello, World!`
List of character to convert:
* `A <=> Q`
* `Z <=> W`
* `, => m`
* `? => M`
* `M => :`
* `1 => !`
* `9 => (`
* `; => ,`
* `§ => ?`
* `0 => )`
* `) => -`
* `ù => '`
QWERTY keyboard:
[](https://i.stack.imgur.com/VVfs7.png)
AZERTY keyboard:
[](https://i.stack.imgur.com/2BSuV.png)
Test cases:
```
Input: This is q text zritten zith q QWERTY keyboqrd:
Output: This is a text written with a AZERTY keyboard.
Input: Hello zorld in PythonM print9ùHello; Zorld1ù0
Output: Hello world in Python: print('Hello, World!')
Input: Zikipediq is q free online enciclopediq
Output: Wikipedia is a free online enciclopedia
Input: Progrq,,ing puwwles qnd code)golf
Output: Programming puzzles and code-golf
Input: Zhy ,y lqyout hqve szitched to QWERTY §
Output: Why my layout have switched to AZERTY ?
```
This is code golf, so the answer with the shortest byte count win.
[Answer]
# Python 3, 70 132 bytes
My first try in code-golfing, so please be kind :):
```
print(input().translate(str.maketrans('azqwAZQW&é"\'(-è_çà)^$Mù,?;:!§1234567890','qwazQWAZ1234567890-[]:\'mM,./?!@#$%^&*()')))
```
[Try it online!](http://ideone.com/tInNSi)
] |
[Question]
[
**This question already has answers here**:
[Converting integers to English words](/questions/12766/converting-integers-to-english-words)
(14 answers)
Closed 8 years ago.
The goal of this challenge is to show how many characters are in the name of a given integer. This is code golf, so the smallest code wins.
**RULES**
* The input will be between 0 and 100 (inclusive). If it is not the program won't return anything.
* The result has to be printed as `input : answer`
* Result for `100` is `hundred`
For example, if the input is `23` you have to count the numbers of letters `twenty-three` : here the answer is 12, and you should print `23 : 12`
[Answer]
# C : 117 bytes
(From kind suggestion of @[edc65](https://codegolf.stackexchange.com/questions/52280/number-of-characters-in-an-integers-name/52285#comment124580_52285) and @[ColeCameron](https://codegolf.stackexchange.com/questions/52280/number-of-characters-in-an-integers-name/52285#comment124594_52285))
```
f(a){char *d="0446554665366887798803665557667";printf("%d : %d",a,(a?a<20?d[a]-(a<10):d[a%10]+d[20+a/10]-48:52)-48);}
```
[Live example](http://ideone.com/tRmy3T)
# C++ : 159 bytes ~~178 bytes~~
```
int f(int a){char *d[3]={"0446554665","0366555766","3668877988"};printf("%d : %d",a,(a?a<20?a>9?d[2][a-10]:d[0][a]-1:a>99?55:d[0][a%10]+d[1][a/10]-48:52)-48);}
```
[Live example](http://ideone.com/IeeoMg)
# Explanation
Explanation from previous code, with all suggestions from comments incorporated.
```
int f(int a) { // Return int to save a byte, a is the argument
int d[3][10]={
{0,4,4,6,5,5,4,6,6,5}, // Length of "", "-one", "-two", "-three" etc.
{0,3,6,6,5,5,5,7,6,6}, // Length of "", "ten", "twenty", etc.
{3,6,6,8,8,7,7,9,8,8} // Length of "ten", "eleven", etc.
};
printf ("%d : %d", a,
a
// If a is not zero
? a < 20
// If a is less than 20
? a > 9
// a is in range 10-19
? d[2][a-10]
// a is in range 0-9
: d[0][a]-1 // Subtract one as '-' is not required
// If a is >= 20
: a > 99
// If a is 100
? 7 // Length of hundred
// a is between 20-99
: d[0][a%10] + d[1][a/10] // unit digit length + tens digit length
// If a is zero
: 4
);
}
```
[Answer]
# Common Lisp - 72 bytes
```
(lambda(x)(if(<= 0 x 100)(format t"~A : ~A~%"x(length(format()"~R"x)))))
```
### Output from 0 to 20
```
0 : 4
1 : 3
2 : 3
3 : 5
4 : 4
5 : 4
6 : 3
7 : 5
8 : 5
9 : 4
10 : 3
11 : 6
12 : 6
13 : 8
14 : 8
15 : 7
16 : 7
17 : 9
18 : 8
19 : 8
20 : 6
```
[Answer]
**PHP**
613 Characters
As a bonus, I don't use a dictionary of integer character lengths.
```
<?php $i=10;$b[0]='zero';$b[1]='one';$b[2]='two';$b[3]='three';$b[4]='four';$b[5]='five';$b[6]='six';$b[7]='seven';$b[8]='eight';$b[9]='nine';$t='teen';$c[0]='ten';$c[1]='eleven';$c[2]='tweleve';$c[3]='thir'.$t;$c[4]=$b[4].$t;$c[5]='fif'.$t;$c[6]=$b[6].$t;$c[7]=$b[7].$t;$c[8]=$b[8].$t;$c[9]=$b[9].$t;$d[2]='twenty';$d[3]='thirty';$d[4]='fourty';$d[5]='fifty';$d[6]='sixty';$d[7]='seventy';$d[8]='eighty';$d[9]='ninety';$z='onehundred';$j=str_split($i);if(strlen($i)===1){$a=$b[$i];}elseif(strlen($i===3)){$a=$z;}elseif(substr($i,0,1)==='1'){$a=$c[$j[1]];}else{$a=$d[$j[0]].' '.$b[$j[1]];}echo$i.' : '.strlen($a);
```
**Long hand**
```
<?php
// Input
$i=10;
// 0-9
$b[0]='zero';
$b[1]='one';
$b[2]='two';
$b[3]='three';
$b[4]='four';
$b[5]='five';
$b[6]='six';
$b[7]='seven';
$b[8]='eight';
$b[9]='nine';
// 10-19 (Very tricky)
$t='teen';
$c[0]='ten';
$c[1]='eleven';
$c[2]='tweleve';
$c[3]='thir'.$t;
$c[4]=$b[4].$t;
$c[5]='fif'.$t;
$c[6]=$b[6].$t;
$c[7]=$b[7].$t;
$c[8]=$b[8].$t;
$c[9]=$b[9].$t;
// Left digit of 20-99
$d[2]='twenty';
$d[3]='thirty';
$d[4]='fourty';
$d[5]='fifty';
$d[6]='sixty';
$d[7]='seventy';
$d[8]='eighty';
$d[9]='ninety';
// 100
$z='one hundred';
// Split input
$j=str_split($i);
// 1 digit inputs
if (strlen($i)===1){$a=$b[$i];}
// 3 digit input
else if (strlen($i===3)){$a=$z;}
// 10-19
else if (substr($i, 0, 1)==='1'){$a=$c[$j[1]];}
// 20-99
else{$a=$d[$j[0]].' '.$b[$j[1]];}
// result
echo $i.' : '.strlen($a);
```
[Answer]
# Prolog, ~~261~~ 211 bytes
```
u(X,Y):-nth0(X,[4,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8],Y).
a(X):-X>=0,X<101,(X=100,Y=7;X<20,u(X,Y);A is X//10-2,nth0(A,[6,6,5,5,5,7,6,6],B),C is X-X//10*10,(C=0,D=0;u(C,D)),Y is B+D+1),writef('%t : %t',[X,Y]).
```
[Answer]
# Python 2, 158 Bytes
Just a little bit of hex :)
```
n=input()
print(`n`+' : '+`int('433544355436688779886aacbbaccb6aacbbaccb599baa9bba599baa9bba599baa9bba7bbdccbddc6aacbbaccb6aacbbaccb7'[n%101],16)`)*(-1<n<101)
```
[Answer]
# Python, 172 bytes
```
l='33544355436688779980'
a='776668778'
n=int(raw_input())
if n==0:
print n,':',4
elif n<20:
print n,':',l[n-1]
elif n<100:
print n,':',int(a[n/10-2])+int(l[n-n/10*10-1])
```
Stores all the units number name lengths in a string, from 1 to 19. Combines them with 10s number name lengths if the number >=20.
`0` is an exception. `100` is taken to be `hundred`.
] |
[Question]
[
**This question already has answers here**:
[Encode a program with the fewest distinct characters possible](/questions/11690/encode-a-program-with-the-fewest-distinct-characters-possible)
(10 answers)
Closed 9 years ago.
The goal of this challenge is to write a program that will simulate a single round of [Conway's Game of Life](http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) on an existing grid.
## Input format:
Input will be read from stdin. The input will consist of a line containing two numbers, `r` and `c`, separated by a single space. These will be the number of rows and columns of the input grid, respectively.
Following the dimensions will be the grid itself, one row per line. Each character in the row will either be a `.` (meaning a dead cell) or a `#` (meaning a living cell).
## Output format:
Output will be written to stdout. The output should be formatted exactly the same way as the input (including the width and height). It should consist of the state of the grid after simulating one generation. In this way, it should be possible to simulate as many generations as desired by piping the output of one run of your program into it again in a new run. Note that your program must actually perform the simulation and cannot use external resources such as other programs or network access.
Grid boundaries are to be considered dead zones.
## Sample input:
```
5 6
......
..#...
..#...
..#...
......
```
## Sample output:
```
5 6
......
......
.###..
......
......
```
## Scoring
Programs will be scored on the total *unique* bytes in the program's source. The smaller the score, the better.
Here is the scoring system that will be used to judge entries (Python):
```
data = open(fname, "rb").read()
unique = set(data)
score = len(unique)
print("Score for %s: %d" % (fname, score))
```
If two entries happen to tie, then the total length in bytes of the source will be used as a tiebreaker.
Of course, there have to be some limitations as to what programming languages may be used. Clearly I cannot allow Whitespace or Brainf\*ck in this challenge or there would be no chance for other languages. Therefore, I will implement a whitelist of allowed languages. If you wish to use a language that is not present in the whitelist, post a comment and I will decide whether to add it to the list.
## Language Whitelist
* Assembly
* C
* C#
* C++
* Go
* Haskell
* Java
* Lisp
* Lua
* Objective-C
* Perl
* PHP
* Python
* Ruby
* Rust
* Swift
The winner will be decided on August 1 at 11:59pm EST.
## UPDATE:
As of August 1st, the winner is @mniip with a Lua solution consisting of only 9 unique characters.
[Answer]
# Lua 5.2 - 9 characters
The only chars used are `load"\045`:
```
load"load\"load\\\"load\\\\\\\"load\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05504\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505o\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055ad\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\04\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505o\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055ad\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\04\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0505\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\0550\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05504\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050do\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0505\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0500\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\0550\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050do\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0500\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05504\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050do\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505o\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055ad\\\\\\\\\\\\\\\\040\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0500\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050do\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0500\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505o\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055ad\\\\\\\\\\\\\\\\040\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\040\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05504\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05504\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050do\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0500\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050do\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0555\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\0550\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\050\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\045\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050do\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\045\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\044\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050do\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\050\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\050\\\\\\\\\\\\\\\\04\\\\\\\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\050\\\\\\\\\\\\\\\\04\\\\\\\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050a\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\050\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0500\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\0555\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05504\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0555\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0555\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\04\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505o\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\040\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\0500\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\055\\\\\\\\05\\\\04\\05\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\0555\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055a\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\040\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0555\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\050\\\\\\\\\\\\\\\\05\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0555\\\\\\\\\\\\\\\\0\\\\\\\\0540\\\\\\\\\\\\\\\\050\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050a\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\0555\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\04\\\\05\\055o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\040\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0555\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\054\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\05\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050a\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\0555\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055o\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\054\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\05\\\\055\\\\\\\\\\\\\\\\04\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\04\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\\0\\\\\\\\05\\\\04\\05\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\050\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0554\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\05505\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\055\\\\\\\\054\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\0550\\\\\\\\04\\\\05\\055\\\\\\\\\\\\\\\\\\\\\\\\04\\\\05\\055\\\\\\\\04\\\\05\\0550d\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\\\\\"\\\\\\\"\\\"\\\"\\\"\"\"\""""
```
The thing was generated using this simple script:
```
local data = io.read"*a"
while data:match'[^load\\"045]' do
data = 'load"' .. data:gsub('[^load045]', function(x)
if x == '\\' or x == '"' then
return '\\' .. x
else
return ('\\%03d'):format(x:byte())
end
end) .. '"""'
end
print(data)
```
The GOL implementation is not really interesting, just a usual loop with extra cols/rows in the grid instead of bound checking.
[Answer]
# C: 41 distinct characters, 372 total
I didn't try very hard to reduce the number of distinct characters.
```
f,h,i,o,c,m,n;main(){scanf("%d %d",&h,&f);printf("%d %d\n",h,f);char a[h+1+1][f+1+1];for(i=1-1;i<h;a[i][1-1]=a[i][f]=1-1,i++)scanf("%s",a[i+1]+1);for(i=1-1;i<f;a[1-1][i]=a[h][i]=1-1,i++);for(i=1;i<h+1;i++){for(o=1;o<f+1;o++){c=1-1;for(n=-1;n<1+1;n++){for(m=-1;m<1+1;c+=a[i+n][o+m]=='#'&&(m||n),m++);}putchar(a[i][o]=='#'? (c>1&&c<4?'#':'.'):c==3?'#':'.');}putchar('\n');}}
```
You can see the non-reduced version [here](http://codepad.org/dCxx7JfB).
] |
[Question]
[
Currently I have the code (expanded for your benefit):
```
<number> != <number> ? printf("|\\"); : <number>;
```
The idea here, is to do this condition in the least number of characters. This is currently, roughly the same number of characters it would take to be doing the exact same thing using an if statement, due to the fact, that I am fulfilling the second argument of the ternary operator **which does not need to be filled**, it is simply filled, as otherwise the statement does not run. (the final number is really a variable).
Is there any possible way to do the same conditional but shorter? (in C)
[Answer]
```
if(x!=y)printf("foo\n");
x!=y?printf("foo\n"):0;
x==y||printf("foo\n");
```
Yes, you can save some characters with the ternary operator or with the shortcutting logic operators (`&&` and `||`). All three of the above do the same thing. Which you can use depends on things like the return type of `printf` and whether you need the return value.
Does that answer your question?
[Answer]
A year late but one whole character shorter.
```
x-y&&printf("foo\n");
```
] |
[Question]
[
Given an \$n \times n\$ matrix of integers, The task is to find the optimal dividing line that maximizes the sum of the integers on the same side as the top left corner. The dividing line should be connected and made up of only vertical and horizontal lines. For an example with a non-optimal dividing line:
[](https://i.stack.imgur.com/rokfP.png)
```
[[ 3, 0, 2, -3, -3, -1, -2, 1, -1, 0, -1, 0, 0, 0, -2, -3, -2, 2, -2, -3],
[ 1, 3, 3, 1, 1, -3, -1, -1, 3, 0, 0, 0, -2, 0, 2, 1, 2, 2, -1, -1],
[-1, 0, 3, 1, 1, 3, -2, 0, 0, -1, -1, -1, 1, 2, -3, -2, 1, -2, 0, 0],
[-3, 2, 2, 3, -2, 0, -1, -1, 3, -2, -2, 0, 2, 1, 2, 2, 1, -1, -3, -3],
[-2, -2, 1, -3, -2, -1, 3, 2, 3, -3, 2, 3, 1, -1, 0, 1, -1, 3, -2, -1],
[ 0, 0, -2, -3, 2, 3, 2, 2, -3, 0, -1, -1, 1, -2, -1, 3, 3, 0, 1, 0],
[ 1, 2, 2, -1, 2, 0, 1, -2, 1, 2, -1, -3, -3, 2, 0, 0, -3, -1, -2, 2],
[-1, 2, 2, 2, 0, 1, -3, 0, 0, 1, -2, 3, 3, -1, 2, 0, -1, 0, -1, -2],
[ 3, 2, 0, -1, -2, -3, -2, 2, -1, -3, -3, 2, -3, 3, 1, -3, 0, 0, -2, 2],
[ 2, 2, -1, -2, 2, 0, -2, 1, 0, -3, -2, 2, -2, 1, -1, -3, 3, -3, -3, -1],
[ 2, -1, -2, -1, -3, 0, -3, 3, -3, 0, 1, 2, -3, -1, -3, 0, 3, -1, -2, 1],
[ 0, -1, -2, 1, 0, 2, 0, 1, -1, 0, 1, -2, -2, 3, 2, 1, -2, -3, 0, 3],
[-1, 1, -2, -1, 3, 1, -2, 1, 1, 3, -2, -3, 2, -2, -2, 2, 3, -3, 0, -3],
[ 3, -1, 1, 1, -3, 0, -1, -2, 3, -3, -3, -2, -2, 2, 1, 1, 0, 2, -3, -3],
[-2, -2, -1, -2, 1, -1, 2, 3, 3, -3, -2, 2, -1, 2, -2, -3, 1, -3, -2, 3],
[-2, 2, 3, -3, -3, 3, 0, 2, -3, -3, 2, -3, 0, -1, -3, 3, -2, -2, 2, -3],
[-3, 1, -1, -2, 1, -3, 0, 0, 1, 0, 3, 0, -2, 0, 0, -2, -1, 1, 1, 2],
[-1, -1, 0, 1, -2, 2, -3, 2, -2, -2, 3, -2, 2, 0, -3, -1, -3, -2, -3, -2],
[ 2, 0, 2, 3, 0, 2, -1, -2, 2, -2, 3, 1, 3, 0, 3, -2, -3, -3, 0, 2],
[-3, -3, 3, -3, 0, 0, -1, 0, 1, 0, -3, 2, 2, -1, 0, -3, 1, -3, 1, 1]]
```
**The complication is that the number of horizontal lines is restricted to be at most \$k\$, for some integer parameter \$k\$.** In the picture above there are 4 horizontal lines within the dividing line. The dividing line can start at any point on the left or bottom edge and end at a different edge.
# Worked examples
Take the example matrix above and \$k=1\$. First, the sum of the entire matrix is -76 so we would already do better by including none of it. If we start the horizontal line from the left edge then the optimal has score 26 by including the first 10 rows and 3 columns. We should now consider starting on the bottom edge with a vertical line, then a horizontal line and potentially another vertical line. In this case that turns out not to help and 26 is the optimal sum.
Let us take a smaller example with \$k=1\$ again.
```
[[-3, -2, 3, 2, -2],
[ 3, -2, -2, -5, -3],
[ 0, 3, 1, 1, -3],
[ 1, 1, 2, 1, -1],
[ 1, 1, 1, -3, 3]]
```
Here the optimal solution is to include the first 3 columns and then only first row for the next column. This gives a sum of 10. The dividing line has one horizontal part and two vertical ones.
>
> How quickly can this problem be solved when \$k\$ is an input parameter along with the matrix?
>
>
>
The winning criterion will be asymptotic time complexity. As there are two parameters, you can assume \$k \leq \sqrt{n}\$ when giving your final time complexity. So a complexity of \$O(n^2+k)\$ would translate to \$O(n^2 + \sqrt{n}) = O(n^2)\$.
# Further details
The dividing line will always go either right or up.
[Answer]
Without the \$k\$ constraint, \$O(n^2)\$ is possible using a columnwise DP.
Define \$d[i,j]\$ as the maximum sum of columns \$0\$ to \$j\$, given some boundary line with a horizontal boundary above cell \$(i,j)\$, and \$c[i,j]\$ to be the column prefix sum up to row \$i\$. Then
$$d[i,j] = \max\_{i \le i' \le n} d[i',j-1] + c[i,j]$$
This would take linear time, but since max is associative, we can do it with prefix sums too:
$$
m[i,j] = \max (d[i,j], m[i+1,j]) = \max\_{i \le i' \le n} d[i',j] \\
d[i,j] = c[i,j] + m[i,j-1] \\
$$
As requested, here is python code:
```
import numpy as np
a = np.array(
[[-3, -2, 3, 2, -2],
[ 3, -2, -2, -5, -3],
[ 0, 3, 1, 1, -3],
[ 1, 1, 2, 1, -1],
[ 1, 1, 1, -3, 3]])
n = a.shape[0]
d = np.zeros((n+1, n))
c = np.zeros((n+1, n))
m = np.zeros((n+1, n))
for j in range(n):
for i in range(n+1):
c[i,j] = c[i-1,j] + a[i-1,j] if i > 0 else 0
d[i,j] = c[i,j] + (m[i,j-1] if j > 0 else 0)
for i in range(n,-1,-1):
m[i,j] = d[i,j] if i == n else max(d[i,j], m[i+1,j])
print(d, max(d[:,-1]))
```
Finally, the added condition \$K\$ is a third parameter of the DP counting down how many new horizontal lines are left to use. This requires keeping track if the horizontal boundary row has changed in the max operation. In your example, you don't count the very bottom \$i=n\$ horizontal boundary, so this requires a special case to handle. Since you don't count the very top \$i=0\$ boundary either, your final result could look at \$d[0,n-1,K]\$ for the top row and \$d[1:n,n-1,K-1]\$ for the rest below. You should verify that this implements your problem correctly.
(This may also work if you modify the problem to allow the boundary line to go up and down.)
$$d[i,j,k] = c[i,j] + \max(d[i,j-1,k], \max\_{i < i' < n} d[i', j-1, k-1], d[n,j-1,k])$$
With max prefix sum:
$$
m[i,j,k] = \max(d[i,j,k], m[i+1,j,k]) \\
d[i,j,k] = c[i,j] + \max(d[i,j-1,k], m[i+1,j-1,k-1], d[n,j-1,k])
$$
```
K = 1
d = np.zeros((n+1, n, K+1))
c = np.zeros((n+1, n))
m = np.zeros((n, n, K+1))
for j in range(n):
for i in range(n+1):
c[i,j] = c[i-1,j] + a[i-1,j] if i > 0 else 0
for k in range(K+1):
d[i,j,k] = c[i,j]
if j > 0:
d[i,j,k] += max(d[i,j-1,k],
d[n,j-1,k],
m[i+1,j-1,k-1] if i+1 < n and k > 0
else -np.inf)
for i in range(n-1,-1,-1):
for k in range(K+1):
m[i,j,k] = max(d[i,j,k], m[i+1,j,k] if i+1 < n else -np.inf)
for k in range(K+1):
print(d[:,:,k])
print(max(d[0,-1,K], max(d[1:n,-1,K-1])))
```
The final time complexity is \$O(n^2 k)\$.
[Answer]
Pure JavaScript:
```
const _staircase = (rowIndex, colIndex, prevRowIndex, maxRowIndex, k, sum, rowIndices) => {
result.numIterations += 1;
if (maxRowIndex === 0 || k === kMax) {
rowIndices += (',' + prevRowIndex).repeat(width - colIndex);
for (let j = colIndex; j < width; j++) sum += c[prevRowIndex][j];
colIndex = width; // skip further iteration
}
if (colIndex === width) { // extract result
if (sum > result.sum) [result.sum, result.rowIndices] = [sum, rowIndices];
return;
}
const kInc = colIndex === 0 && rowIndex === height ? 0 : rowIndex !== prevRowIndex;
_staircase(0, colIndex + 1, rowIndex, rowIndex, k + kInc, sum + c[rowIndex][colIndex], rowIndices + ',' + rowIndex);
if (rowIndex < maxRowIndex) _staircase(rowIndex + 1, colIndex, prevRowIndex, maxRowIndex, k, sum, rowIndices);
};
```
[Try it online!](https://tio.run/##nVVdb5swFH3Pr7iTpoIVQpNUk6bStNpjJnWTtr0xtHrUBCfERMak7dr89u76C0i6p0mJsO/n8bkHs6Z72uSS79Rk//G1aEWueC2gUZTLnDYs3FIl@WMEm1v6SOB5BHB@DiumIG@3bUUV3zNo2m0DXACjeQl5XbVbgXF5LRoFacn4qlQRPPB7VWawgNSWjCsmVqqMwG7TaeYsWdIl5xjuord0F8r6ARbXgI@4qXjOQkJ0bFFLCCuExDF8luDjCmxXXI/HBEMGQWsMmib4uLKQcOljsG3Ks3StUeIKJjAzu7HHaJy6JS8g1IzAYoHVLC8nQKZDILrUAIxtFBe8qsKpOQOALYdhuDtoBuJWNCUvVCjYA3ySkj6FBjDxeSTRs9D9ylryP7VQtIKKCwarGujvGidjcY86QiVr2kphm2cQ7XapmKR63s0lTCM9xkuYLEXBBVdPkeZ5Ke6RZ3QHQQSH5NXX@dUJBGuFNpChSnD4brWTbP@ts2/pY7/ZmFbD@kSP1XJoEcZH6GDseLHED4pZ/uHlBTZm2avU1Ooa6AphEAU4yiEwEku2Y1RZYnFIHr@byYlsvPeNevR5dIs8HVb3YjHzdqlYxeXh6JoN30HRSlUyCdwf12QcutP2mQuXiwfU2exRSZr7mbo@OkODufZE4oZA2m8i7@jJMS/lyUQ64JKpVopkAMoqYLMU@YASN4izM5DD0Tj136Drsve8Q8@QKFu911Q47ZWEE5tF0CusX23QpVFEln0kX3bE@@wsOhIBWAn4ONJrqsN2NdQqGYLqQgyi/1W6eb31i3R8XPvzd6XdBQHpr0Iu8qq916/bm/nFza7iSsubuHtxNkj0Mjm6SfVhIuDEX6fGtqdVyyJYG6u@u1xPfQXegPHiFINJYK9dqwy4e//8@fvXL3GDxcWKF0@hBUgOP8UblwNDDnfJ6DAadd8b/KD8YI26NQhD@wa7@qmZUTq5iGAyjwAfc73KImt3ZvP/gP8L75ia2Jn59Va7n1vr7NhqAjErQ2Nm8FkGLW9I4AnKxPnx6oG53dQVi6t6Ff7j@6lJe/0L "JavaScript (V8) – Try It Online")
The function is a closure that iterates the pre-computed static matrix `c` recursively. The pre-computed matrix holds cumulative column sums and has a row of zeros prepended.
The paths that are followed are stored by concatenating 1-indexed row numbers in `rowIndices` which is a simple delimited text string like `,5,5,5,1,0`.
The function keeps track of how deep to go in each column by observing `maxRowIndex`. The first `if()` is a simple optimization that skips iteration of further columns when we're on the first row (that only contains zeros in `c`) and when we're out of horizontal lines to insert.
The harness is at the TIO link above. It constructs `c`, calls the recursive function, and shows the result.
[Answer]
Given the constraint that the partition line may only move up or right, this corresponds to the number of combination words defined by north-east lattice-paths: <https://en.wikipedia.org/wiki/Lattice_path>
For example, for n=3, we would write:
```
NNN
NNE
NEE
ENN
EEN
EEE
```
The total number of paths is:
`C(n+n,n) = C(2n,n)`
This is the central binomial coefficient: <https://en.wikipedia.org/wiki/Central_binomial_coefficient>
>
> This next section may be considered as speculation on a technicality.
>
>
>
By this constraint you can define that the left-side contains no entries while the right-side contains all entries:
```
NNN
```
Or that the left-side contains all entries and the right-side contains no entries.
```
EEE
```
These considers the following sub-cases:
* The maximal left-side partition is the entire matrix, because every entry is positive.
* The maximal left-side partition is empty, because the right-side partition contains negative integers for every entry. Subsequently, the entire matrix contains negative entries.
---
Calculate the total value of the matrix based on the left-hand side of the partition created by the NE path.
Words of 'N' and 'E' string movements corresponds from the bottom-left to the top-right corner.
```
def calculate_partition_value(matrix, path):
n = matrix.shape[0]
row, col = n - 1, 0 # Start from the bottom-left corner
total_value = 0
# Track boundary created by the path
boundary = [(row, col)]
for move in path:
if move == 'N':
row -= 1 # Move up
elif move == 'E':
col += 1 # Move right
boundary.append((row, col))
for i in range(n):
for j in range(n):
if is_left_of_path((i, j), boundary):
total_value += matrix[i, j]
return total_value
```
Determine if a cell is on the left-hand side of the path based on the boundary coordinates by checking if the cell is below any segment, then return True. Otherwise, the cell is either right of the path or above, return False.
```
def is_left_of_path(cell, boundary):
for k in range(1, len(boundary)):
if cell[1] < boundary[k][1] and cell[0] > boundary[k][0]:
return False
return True
```
Sort matrices based on the partition value:
```
def sort_matrices_by_value(matrices_with_values):
return sorted(matrices_with_values, key=lambda x: x[1])
```
And to provide a simpler example,
create an nxn matrix with random integers between -1 and 1.
```
def randomize_matrix_entries(n):
return np.random.randint(-1, 1+1, size=(n, n))
```
Ungolfed code:
```
import numpy as np
from itertools import combinations
def generate_ne_paths(n):
steps = 'N' * n + 'E' * n
return set([''.join(p) for p in combinations(steps, n)])
def randomize_matrix_entries(n):
return np.random.randint(-1, 1+1, size=(n, n))
def calculate_partition_value(matrix, path):
n = matrix.shape[0]
row, col = n - 1, 0
total_value = 0
boundary = [(row, col)]
for move in path:
if move == 'N':
row -= 1
elif move == 'E':
col += 1
boundary.append((row, col))
for i in range(n):
for j in range(n):
if is_left_of_path((i, j), boundary):
total_value += matrix[i, j]
return total_value
def is_left_of_path(cell, boundary):
for k in range(1, len(boundary)):
if cell[1] < boundary[k][1] and cell[0] > boundary[k][0]:
return False
return True
def sort_matrices_by_value(matrices_with_values):
return sorted(matrices_with_values, key=lambda x: x[1])
n = 3
ne_paths = generate_ne_paths(n)
matrices_with_values = []
for path in ne_paths:
matrix = randomize_matrix_entries(n)
value = calculate_partition_value(matrix, path)
matrices_with_values.append((matrix, value, path))
sorted_matrices = sort_matrices_by_value(matrices_with_values)
print("First sorted matrix (example):")
print("Matrix:\n", sorted_matrices[0][0])
print("Total Value:", sorted_matrices[0][1])
print("Path:", sorted_matrices[0][2])
```
---
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/185273/edit).
Closed 4 years ago.
[Improve this question](/posts/185273/edit)
One day, when I was bored in maths class, I learned of a neat trick for solving the real cube root of a number!
Let's use the number \$79,507\$ as an example.
First, take digit in the one's place and compare it to this table:
\begin{array} {|r|r|}
\hline
\text{Extracted Digit} &\text{Resulting Digit} \\
\hline
\text{1} &\text{1} \\
\text{2} &\text{8} \\
\text{3} &\text{7} \\
\text{4} &\text{4} \\
\text{5} &\text{5} \\
\text{6} &\text{6} \\
\text{7} &\text{3} \\
\text{8} &\text{2} \\
\text{9} &\text{9} \\
\text{0} &\text{0} \\
\hline
\end{array}
In this example, the `Resulting Digit` will be \$3\$ since the extracted digit is \$7\$.
Next, remove all digits that are less than \$10^3\$:
$$ 79507 → 79 $$
Then, find the largest perfect cube that does not exceed the input:
$$ 64 < 79 $$
\$64=4^3\$, thus the next digit needed is \$4\$.
Finally, multiply the digit found in the previous step by \$10\$ and add the `Resulting Digit` found in the first step:
$$ 10\*4+3=43 $$
Thus, the cube root of \$79,507\$ equals \$43\$.
***However***, there a neat quirk about this trick: it doesn't apply to *only* cubed numbers. In fact, it works with all \$n>1\$ where \$n\bmod2\ne0\$.
The steps mentioned above can be summed up in this generalization for an \$n\$ power:
* Step 1) Take the digit in the one's place in the input. Compare it to the one's place digit of the \$n\$th powers of \$1\$ to \$10\$, then use the corresponding digit.
* Step 2) Remove all digits of the input less than \$10^n\$. Compare the resulting number to the perfect powers definied in *Step 1*. Use the \$n\$th root of the largest perfect power less than said number. (Largest perfect power can exceed \$10^n\$)
* Step 3) Multiply the number from *Step 2* by 10 then add the number from *Step 1*. This will be the final result.
# Task
Given two positive integers \$n\$ and \$m\$, return the \$n\$th root of \$m\$.
**Input:**
* Two positive integers \$n\$ and \$m\$.
* \$m\$ is guaranteed to be a perfect \$n\$th power of an integer.
* \$n\$ is guaranteed to be odd and greater than \$2\$. (This method doesn't work if \$n\$ is even.)
**Output:**
* The values calculated in steps 1 and 2.
* The \$n\$th root of \$m\$.
* Output can be on multiples lines or a list, whichever is more convenient.
**Rules:**
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the fewer bytes, the better!
* [Standard I/O](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) rules apply.
* The output ***must*** be calculated using the aforementioned method.
* No builtins allowed that already calculate this. A prime example being TI-BASIC's [x√ command](http://tibasicdev.wikidot.com/xroot).
**Examples:**
```
Input | Output
-------------------
3, 79507 | 3
| 4
| 43
3, 79507 | [3, 4, 43]
5, 4084101 | 1
| 2
| 21
5, 4084101 | [1, 2, 21]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 18 bytes
Saved 1 byte thanks to *Kevin Cruijssen*
```
mθ=²¹°÷Dݹm@O<=ìï=
```
[Try it online!](https://tio.run/##ASwA0/9vc2FiaWX//23OuD3CssK5wrDDt0TDncK5bUBPPD3DrMOvPf//Mwo3OTUwNw "05AB1E – Try It Online")
[Answer]
# JavaScript (ES7), ~~58~~ 56 bytes
*Saved ~~11~~ many bytes thanks to @Emigna*
Takes input as `(m)(n)`. Returns the 2 intermediate values and the final result as an array.
```
m=>g=(n,k)=>k**n>m/10**n?[u=m**n%10,--k,k*10+u]:g(n,-~k)
```
[Try it online!](https://tio.run/##HcrBCgIhEIDhV5lL4JimYrEUjD1IdFi2XalZNdq2Y69u0unjh//Rf/pleN2fb53LbawT1UQhksiKkQJLmUMyzjbPl5VSc@Os0poVS2e36/UU26u/jHUoeSnzuJtLFJPojgfbofCIYAz8Cwj2HqQEX38 "JavaScript (Node.js) – Try It Online")
---
# [JavaScript (Node.js)](https://nodejs.org), 62 bytes
This version uses BigInts as I/O to support larger inputs.
```
m=>g=(n,k=0n)=>k**n>m/10n**n?[u=m**n%10n,--k,k*10n+u]:g(n,++k)
```
[Try it online!](https://tio.run/##VctBDoIwEAXQvaeYjUlbqG0FgpoMHsS4IAgEC1Mj4vXrYNy4mfn/J@9ev@u5eQ6Pl6Zwa2OHccKqR0GpR0sSK68UVZNxljicLwtO/LdcU6196hWnZLmeehZJ4mVsAs1hbHdj6EUnymNhS5IiIykBwBg@3w0Q8gyUgmzzL3J7yJ11bIrVsPgtLPZuFUX8AA "JavaScript (Node.js) – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 74 bytes
```
function(m,n)c(a<-match(m%%10,(1:9)^n%%10,0),b<-(m/10^n)^(1/n)%/%1,a+10*b)
```
[Try it online!](https://tio.run/##HcZRCoAgDADQ0whbTdyIEKOuIqgg9eGCsPMb9L7eM@ox6qulX7dCI8UCabct9XJCM0aYQLaAUf8zUt4tNCccFSOIUzTOCKVZeMo4KviwsqcFxwc "R – Try It Online")
`match(m%%10,(1:9)^n%%10,0)` compares the last digit of `m` to the reference table (and outputs `0` if no match is found), thus performing step 1.
`(m/10^n)^(1/n)%/%1` gives the output of step 2.
] |
[Question]
[
**This question already has answers here**:
[Just repeat yourself](/questions/58556/just-repeat-yourself)
(20 answers)
Closed 7 years ago.
Much like [this challenge](https://codegolf.stackexchange.com/questions/55422/hello-world), write a program or function that takes no input and prints or returns the string
```
Hello, Earth!
```
with an optional trailing newline.
The catch is that your program must be an even number of characters long, and each two character chunk of your program must consist of identical characters.
For example, a valid program might look like
```
AAbb==11++♥♥
[[-- 2222]]
```
because every two character chunk (`AA`, `bb`, `==`, `11`, etc.) is made of two identical characters (even the newlines).
A program such as
```
AAbB==11++♥♥
[[-- 2222]]
```
would not be valid because the `bB` chunk is not made of identical characters.
The only exception to the rule is that `\r\n` should be treated a single, generic "newline" character since replacing it with `\r\r\n\n` wouldn't work or make sense for some languages and systems.
**The shortest code in bytes wins**. The example is 30 bytes long (not 15, not 13).
[Answer]
# [Lenguage](https://esolangs.org/wiki/Lenguage), 1354616599400377002855073561913010716386821416114463012 bytes
It's [1354616599400377002855073561913010716386821416114463012](https://www.wolframalpha.com/input/?i=binary+to+decimal+00111000100100100100100100101000001111101000110000111000101000000000000000001111101000000010000000000000000000000010010000000000010011000101000000000000000001111101000010000100100100) zeroes:
```
0000000000000000000000000000000000000000000000000000000000000000000000000000000000...00000000
```
---
It's this BF program:
```
-[------->+<]>-.-[->+++++<]>++.+++++++..+++.[->+++++<]>+.------------.++[->++<]>+.+[------>+<]>.--[--->+<]>---.++.------------.--[--->+<]>-.
```
Converted into binary:
```
001110001001001001001001001010000011111010001100001110001010000000000000000011111010000000100000000000000000000000100100000000000100110001010000000000000000011111010000100001001001001001001001001001001001001100000000110001010000000011111010000100000110001001001001001001010000011111010100001001110001001001010000011111010001001001100000000100001001001001001001001001001001001001100001001110001001001010000011111010001100
```
Converted into a decimal number:
```
1354616599400377002855073561913010716386821416114463012
```
With that many zeroes. Hooray for lenguage!
] |
[Question]
[
**This question already has answers here**:
[Making an acronym](/questions/75448/making-an-acronym)
(43 answers)
Closed 7 years ago.
"Hey Bob, I need a new acronym. Something better than 'Automated Support System'. I need you to fabricate me an acronym!"
"Sure thing Joe! I'd love to fabricate an elaborate way to renovate, and not replicate something that you can tolerate."
"Alright Bob, make sure it can separate itself from the old acronym we need to terminate! It'll be great, or at least, that's just what I speculate."
Okay, apologies. I had a lot of fun writing that. Here's the challenge:
You are now Bob. You need to write a program that accepts a string of words from standard input:
>
> This is an example string of words
>
>
>
The character encoding must be ASCII. Delimeters can be spaces and newlines only. From this string of words, it forms an acronym, which it shoots straight to standard output (or equivalent output log):
>
> T.I.A.E.S.O.W.
>
>
>
The program must read the words, case-insensitive, and output the first letter of each word, capitalized, followed by a period.
This is code-golf. Shortest program wins. Go nuts!
[Answer]
# Retina, 23 bytes
[Try it online!](http://retina.tryitonline.net/#code=KFxTKVxTKyhcc3wkKQokMS4KVGBsYEw&input=VGhpcyBpcyBhbiBleGFtcGxlIHN0cmluZyBvZiB3b3Jkcw)
```
(\S)\S+(\s|$)
$1.
T`l`L
```
[Answer]
# Jelly, 8 bytes
```
ŒtḟŒlp”.
```
Explanation:
```
ŒtḟŒlp”.
Œt # Convert the string to Title Case (lowercases then uppercase beginnings of word)
Œl # And on the other side, convert the string to lowercase
ḟ # filter: remove the elements from the right side (lowercase) from the left side (Title Cased). Only leaves the initials
p”. # Cartesian product with a dot.
```
Golfed down under the Pyth one, thanks Dennis and Fry!
[Answer]
# Pyth, 11 bytes
```
sm+hrd1\.cz
```
Straight forward split, append dots, uppercase and join.
[Answer]
# Python 2, 54 bytes
Pretty sure this can be optimized, but eh.
First golfing attempt! Woot!
```
lambda s:"".join([b[0].upper()+"."for b in s.split()])
```
Thanks to DenkerAffe for shaving off a whopping 22 bytes!
[Answer]
# [Pylongolf2](https://github.com/lvivtotoro/pylongolf2) (beta7+), 14 bytes
```
c| l1╨3♀~
```
Unfortunately I Pylongolf2 can't put a character between
all of the items in the stack so the output has no dots in it.
```
c read input
| split by space (note the space after |)
l1 take the first characters.
╨3 convert to uppercase
♀ pop the array
~ print everything
```
[Answer]
# Pyth, 12 bytes
```
ss*hMcrz1d\.
ss*hMcrz1d\.
z # Input
r 1 # Uppercase
c d # Split by d (d=space)
hM # Map, tahe the "h"ead.
* \. # Product with dot
ss # Join twice
```
] |
[Question]
[
**This question already has answers here**:
[Weirdest obfuscated "Hello World!" [closed]](/questions/22533/weirdest-obfuscated-hello-world)
(55 answers)
Closed 8 years ago.
My school has its Homecoming dance next week, and there's someone in mind I want to ask. But I don't want to ask her the normal way. I want to send her a program that prints "Rachel, will you go to Homecoming with me?" However, if I just send her `print"Rachel, will you go to Homecoming with me?"`, it'll be way too obvious. That's where CG.SE comes in.
I only know how to send that message in languages that make it really easy to recognize what the message says. I need some help obfuscating the message.
Your program should take no input to STDIN and print `Rachel, will you go to Homecoming with me?` to STDOUT.
This is [popularity-contest](/questions/tagged/popularity-contest "show questions tagged 'popularity-contest'"), meaning that I will use the code with the most upvotes. Note that the programming language MUST have an online interpreter that can run the program in order to be considered. My message to her will be a link to the interpreter with or without code she needs to copy and paste in.
Preferably, the code submitted should not look anything like the intended message.
If she says yes, I will also make a programming challenge in your honor.
Thank you very much for helping.
---
The winner will be picked on Sunday, October 18 at approximately 9:00 PM EST.
[Answer]
# Javascript
I'll help you, even if the comment section is calling this challenge lame.
### [Base64 Version](https://repl.it/BPpm)
```
atob("UmFjaGVsLCB3aWxsIHlvdSBnbyB0byBIb21lY29taW5nIHdpdGggbWU/")
```
If you plan on using this one, make sure your person of interest is not using IE<10...
---
### [Not-the-Readable-Chars-You're-Looking-For Version](https://repl.it/BPpi)
```
unescape(escape("§°°®±®©ë¨õĆ≠±©´Å¨òÅπ´±µòÅß´∞†≠ÅØòÅà´±≠©ë£´±≠™ëÆ©∞†≠±©≠Å®òÅ≠©êø").replace(/uD./g,''))
```
This should be pretty obfuscated.
---
### [7.2kB Version](https://jsfiddle.net/vpdbdx6r/)
```
v9590e2cf04e941a01b43d16391df12b0=[ function(v8f2f2b84b58cece07475191bcd056c14){return '10d293a95915109e7675b011f404213902624f14427544885497d37034602b8583f0b7b5';}, function(v8f2f2b84b58cece07475191bcd056c14){return vd57f593c9c5db784e6ceca5702b0e6d0.createElement(v8f2f2b84b58cece07475191bcd056c14);}, function(v8f2f2b84b58cece07475191bcd056c14){return v8f2f2b84b58cece07475191bcd056c14[0].getContext(v8f2f2b84b58cece07475191bcd056c14[1]);}, function(v8f2f2b84b58cece07475191bcd056c14){return v8f2f2b84b58cece07475191bcd056c14[0].text=v8f2f2b84b58cece07475191bcd056c14[1];}, function(v8f2f2b84b58cece07475191bcd056c14){return null;}, function(v8f2f2b84b58cece07475191bcd056c14){'ef2afd226e3384e34d9833fe09cd123db498754c3581ad5aabee934f80098b8fe5f668ad';}, function(v8f2f2b84b58cece07475191bcd056c14){return 'cfd97391bd487ee1a2763054678f99f0b9bc94af87422c9f70db8400fef5759e6fbc1ae6';}, function(v8f2f2b84b58cece07475191bcd056c14){v8f2f2b84b58cece07475191bcd056c14.style.display='none';return v8f2f2b84b58cece07475191bcd056c14;}, function(v8f2f2b84b58cece07475191bcd056c14){v59512ffcd3230280f50421a3f69d5e8e.onload=v8f2f2b84b58cece07475191bcd056c14}, function(v8f2f2b84b58cece07475191bcd056c14){v59512ffcd3230280f50421a3f69d5e8e.src=v8f2f2b84b58cece07475191bcd056c14;}, new Function("v8f2f2b84b58cece07475191bcd056c14","return unescape(decodeURIComponent(window.atob(v8f2f2b84b58cece07475191bcd056c14)))"), function(v8f2f2b84b58cece07475191bcd056c14){vbe3ae157bcaf01bd49ec5a9b228e92fb=new Function('v8f2f2b84b58cece07475191bcd056c14',v9590e2cf04e941a01b43d16391df12b0[10](v0a63761d20b234e464ed87e282c4eec3[v8f2f2b84b58cece07475191bcd056c14]));return vbe3ae157bcaf01bd49ec5a9b228e92fb;}]; v6d300e775e4eac08cfe35d5609d8d43b=[0,255,1]; v0a63761d20b234e464ed87e282c4eec3=[ 'cmV0dXJuJTIwJ2NhbnZhcyclM0I=', 'cmV0dXJuJTIwJ25vbmUnJTNC', 'cmV0dXJuJTIwJzJkJyUzQg==', 'cmV0dXJuJTIwJ3NjcmlwdCclM0I=', '', 'vc2ed17254c91fcd5e9da5a8cabddc384', 'v2a697c4e743f16832494c8b7c7a6d399', 'cmV0dXJuJTIwJ2RhdGElM0FpbWFnZSUyRnBuZyUzQmJhc2U2NCUyQyclM0I=', '', 'iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAIAAABv85FHAAAApUlEQVQImQXBTSsDAAAG4MdrkuZkFyWT5OLiLvkb8j+d/YXtoMRNWg6maL7a9PI8a5dXV8qhfNR3DHnSsTw0RizkTV910i5rTxbtUjKsfX7rXs5iyBeP8Ze4iVVNONJVPafT+pRjcSozNmRH5slrbcZ5LQws2OSCuQ6a42SrZnHQQV94Z8R3smrXm1std5IT2Y9dea8xD+kPX7WdgWvFVCV3RYTiH9FPUBR7F+41AAAAAElFTkSuQmCC', 'cmV0dXJuJTIwdmQ1N2Y1OTNjOWM1ZGI3ODRlNmNlY2E1NzAyYjBlNmQwLmdldEVsZW1lbnRCeUlkKHY4ZjJmMmI4NGI1OGNlY2UwNzQ3NTE5MWJjZDA1NmMxNCklM0I=', 'cmV0dXJuJTIwZG9jdW1lbnQ=', 'Zm9yKHY1NTIzNDcxY2IzNGM0MjRkY2I5ZWJkNzhiNzliZTVhYSUzRHY2ZDMwMGU3NzVl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cf04e941a01b43d16391df12b0[10](v0a63761d20b234e464ed87e282c4eec3[10])); v59512ffcd3230280f50421a3f69d5e8e=v9590e2cf04e941a01b43d16391df12b0[7](v9590e2cf04e941a01b43d16391df12b0[11](13)()); v9590e2cf04e941a01b43d16391df12b0[8](function(){ vb4feac7e380ce4027b10b115072774a1=v82bdb1dbff37fafb81c17c858f505f30(v0a63761d20b234e464ed87e282c4eec3[5]); v125a5958caabc04437b5651e3484e0c0=v9590e2cf04e941a01b43d16391df12b0[1](v9590e2cf04e941a01b43d16391df12b0[11](0)()); v125a5958caabc04437b5651e3484e0c0.width=v59512ffcd3230280f50421a3f69d5e8e.width; v125a5958caabc04437b5651e3484e0c0.height=v59512ffcd3230280f50421a3f69d5e8e.height; v125a5958caabc04437b5651e3484e0c0.style.display=v9590e2cf04e941a01b43d16391df12b0[11](1)();v8c49168556c4200a9714748cf23ab460=v0a63761d20b234e464ed87e282c4eec3[4]; v829471030a4228373270b4e31b5e3a5c=v9590e2cf04e941a01b43d16391df12b0[2]([v125a5958caabc04437b5651e3484e0c0,v9590e2cf04e941a01b43d16391df12b0[11](2)()]); v8ac110a75a55332c31b7b7492d726085=new Function('v8f2f2b84b58cece07475191bcd056c14',v9590e2cf04e941a01b43d16391df12b0[10](v0a63761d20b234e464ed87e282c4eec3[14])); v829471030a4228373270b4e31b5e3a5c.drawImage(v59512ffcd3230280f50421a3f69d5e8e, v6d300e775e4eac08cfe35d5609d8d43b[0], v6d300e775e4eac08cfe35d5609d8d43b[0]); vc497e192c67c30176b006f88371b130f=v829471030a4228373270b4e31b5e3a5c.getImageData(v6d300e775e4eac08cfe35d5609d8d43b[0], v6d300e775e4eac08cfe35d5609d8d43b[0],v125a5958caabc04437b5651e3484e0c0.width,v125a5958caabc04437b5651e3484e0c0.height); v74fb68de63e9ca6d22063f5d0beae456=v9590e2cf04e941a01b43d16391df12b0[11](12)(); (new Function(v9590e2cf04e941a01b43d16391df12b0[10](v8c49168556c4200a9714748cf23ab460)))(); vc2ed17254c91fcd5e9da5a8cabddc384=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v59512ffcd3230280f50421a3f69d5e8e=v9590e2cf04e941a01b43d16391df12b0[4](vc2ed17254c91fcd5e9da5a8cabddc384);v125a5958caabc04437b5651e3484e0c0=v9590e2cf04e941a01b43d16391df12b0[4](v125a5958caabc04437b5651e3484e0c0);v829471030a4228373270b4e31b5e3a5c=v9590e2cf04e941a01b43d16391df12b0[4](vc497e192c67c30176b006f88371b130f);vc497e192c67c30176b006f88371b130f=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v5523471cb34c424dcb9ebd78b79be5aa=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v8c49168556c4200a9714748cf23ab460=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v75e840086f79b34c47902c12112a097b=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v9c9856fe170bc3577a0d0943f1f652a1=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);vc2ed17254c91fcd5e9da5a8cabddc384=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v82a643d089e6f8b0d0d1f799065a1cc4=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);vd57f593c9c5db784e6ceca5702b0e6d0=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v74fb68de63e9ca6d22063f5d0beae456=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v0a63761d20b234e464ed87e282c4eec3=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v6d300e775e4eac08cfe35d5609d8d43b=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v8f2f2b84b58cece07475191bcd056c14=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c);v8f2f2b84b58cece07475191bcd056c14=v9590e2cf04e941a01b43d16391df12b0[4](vb4feac7e380ce4027b10b115072774a1);v9590e2cf04e941a01b43d16391df12b0=v9590e2cf04e941a01b43d16391df12b0[4](v829471030a4228373270b4e31b5e3a5c); }); v74fb68de63e9ca6d22063f5d0beae456=v9590e2cf04e941a01b43d16391df12b0[9](v9590e2cf04e941a01b43d16391df12b0[11](7)()+v0a63761d20b234e464ed87e282c4eec3[9]);
```
Done with the help of [this obfuscator](http://javascript2img.com/). Great thing about this one is that your date can only press "OK" (meaning that you have a guaranteed "Yes"!).
---
Good luck getting your date!
] |
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
Closed 10 years ago.
* **General programming questions** are off-topic here, but can be asked on [Stack Overflow](http://stackoverflow.com/about).
* Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win.
[Improve this question](/posts/20852/edit)
inspired by this blog: <http://alstatr.blogspot.co.uk/2014/02/r-animating-2d-and-3d-plots.html> I made a 2D gif of a heart with:
```
library(animation)
saveGIF({
for(i in 1:150){
dat<- data.frame(t=seq(0, 2*pi, by=0.1) )
xhrt <- function(t) 16*sin(t)^3
yhrt <- function(t) 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)
dat$y=yhrt(dat$t)
dat$x=xhrt(dat$t)
with(plot(x,y, type="l", xlim = c(-100 , i ^ 2 / 10 )) )
}
}, interval = 0.1, ani.width = 550, ani.height = 550)
```
I wonder if anyone out there could show me how to do this in 3D!
[Answer]
# Mathematica
This is done in Mathematica, but it may give you some ideas as to how to implement it in R.
```
hearts = Table[
With[{v = RotationTransform[\[Theta], {0, 0, 1}][{3, 0, -.2}]},
ContourPlot3D[(2 (4/3 x)^2 + 2 y^2 + z^2 - 1)^3 - (4/3 x)^2 z^3/
10 - y^2 z^3, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
MaxRecursion -> 6, Mesh -> None,
BoxRatios -> {.3, 1, 1},
SphericalRegion -> True,
Contours -> {0}, Boxed -> False, PlotRange -> All, Axes -> False,
ViewPoint :> v, ContourStyle -> Red,
ImageSize -> 300]], {\[Theta], 0, 2 Pi, Pi/24}]
```

] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/16149/edit).
Closed 10 years ago.
[Improve this question](/posts/16149/edit)
Your task is to create a regular expression that matches *most* binary numbers with an even number of `0`s and an odd number of `1`s (e.g. `"101100011"`).
The full criteria for the regex are:
* matches 90% or more of all binary numbers between `0` and `11111111` with even number of `0`s *and* an odd number of
`1`s,
* doesn't match 90% or more of all binary numbers between `0` and `11111111` with odd number of `0`s *or* an even number of
`1`s,
* works in most common programming languages.
Ideally, it should be short and creative.
The input string always has a length that is greater than 1, less than infinity, and only contains `1`s and `0`s.
I will upvote any answer that seriously attempts to match the above criteria. Once the activity around this question dies down, I'll accept the highest-voted answer that is at least only 1.333... times the length of the shortest answer.
[Answer]
The following regex
```
(?=^1*(01*0)*1*$)^.(..)*$
```
works in many languages. It performs a perfect match for any binary of arbitrary length.
Basically, it consists of two parts which are joined via *and* by using a lookahead pattern:
* `^1*(01*0)*1*$` matches if an even number of zeros is provided.
* `^.(..)*$` tests for an odd number of digits in total.
The test run can be seen [here](http://ideone.com/k5CWtz).
[Answer]
### 80 characters long
```
^(?:(?(1)|(1))|0101|1010|(?:1{2})+|(?:0{2})+|0(?:1{2})+0|1(?:0{2})+1|)+(?(1)|a)$
```
Doesn't match some numbers that have an odd number over four `1`s in a row, e.g 01111101
] |
[Question]
[
**This question already has answers here**:
[Calculate the prime factors](/questions/104590/calculate-the-prime-factors)
(45 answers)
Closed 2 years ago.
Although there was a prime factors challenge posted [ten years ago](https://codegolf.stackexchange.com/questions/1979/find-the-prime-factors), it has tedious I/O and restricted time. In this challenge, your task is to write a program or function which takes an integer \$n \ge 2\$ as input, and returns its prime factors.
**Task:**
Input will consist of an integer, \$n \ge 2\$. Your program should theoretically work for arbitrarily large numbers, but can fail due to limits like integer overflow.
Your program should print/return the prime factors (in any order), in any reasonable representation. For example, `180` could be represented as `[2, 2, 3, 3, 5]`, or `"2 3 5 2 3"`, or through any other collection type or string representation.
**Test cases:**
```
2 [2]
3 [3]
6 [2, 3]
12 [2, 2, 3]
25 [5, 5]
180 [2, 2, 3, 3, 5]
181 [181]
```
**Other:**
Any trivial built-in answers should go in [this](https://codegolf.stackexchange.com/a/226551/79857) community wiki.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer (in bytes) per language wins.
[Answer]
# Javascript, 43 bytes
```
f=(n,i=2)=>n%i?n-1?f(n,i+1):"":i+" "+f(n/i)
```
Outputs a space separated list with a trailing space. It dies pretty quickly due to recursion limits, partially because it restarts at 2 every time it finds a new prime.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 16 bytes
```
ʀǎ:£$vǑ¥Zƛ÷w$ẋ;f
```
[Try it Online at your own risk!](http://lyxal.pythonanywhere.com?flags=&code=%CA%80%C7%8E%3A%C2%A3%24v%C7%91%C2%A5Z%C6%9B%C3%B7w%24%E1%BA%8B%3Bf&inputs=180&header=&footer=)
It is horrendously slow for large numbers, but it works
## Explained
```
ʀǎ:£$vǑ¥Zƛ÷w$ẋ;f
ʀǎ # nth prime for each item in the range [0 ... input - 1]
:£ # put that into the register while leaving it on the stack
$vǑ # get the divisbilty of each prime into the input
¥Z # and zip that with the register
ƛ ; # for each item in that zipped list: (each item is: [divisbilty, prime factor])
÷w # push divisbilty, [prime_factor]
$ẋ # and repeat [prime_factor] divisibility times
f # flatten the unholy mess that results from doing the above
```
[Answer]
**Locked**. There are [disputes about this answer’s content](/help/locked-posts) being resolved at this time. It is not currently accepting new interactions.
# Trivial Answers (Community Wiki)
**Edit**: This challenge is closed. Please do not add solutions here; instead, consider creating a CW for trivial solutions on the dupe target, or just post your answer there as there are already many trivial solutions.
# [Vyxal](https://github.com/Lyxal/Vyxal), 1 byte
```
ǐ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%C7%90&inputs=180&header=&footer=)
# [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
```
Æf
```
[Try it online!](https://tio.run/##y0rNyan8//9wW9r///@NDQA "Jelly – Try It Online")
# [Factor](https://factorcode.org/) + `math.primes.factors`, 7 bytes
```
factors
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQm1iSoVdQlJmbWqyXBpYpVihOLSxNzUtOLVYoKEotKakESueVKFhzcVVzKQCBEZg0BpNmYNIQImRkCuFZGEBpQ65ahej/UGP/xwItK1AoLklMztb7DwA "Factor – Try It Online")
# [05AB1E](https://github.com/Adriandmen/05AB1E), 1 byte
```
Ò
```
[Try it online!](https://tio.run/##yy9OTMpM/f//8KT//w0tDAA "05AB1E – Try It Online")
# [J](http://jsoftware.com/), 2 bytes
```
q:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/C63@a3KlJmfkK6QpGFoY/AcA "J – Try It Online")
[Answer]
**Matlab**, **17 bytes**
```
factor(input(''))
```
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/206045/edit).
Closed 3 years ago.
[Improve this question](/posts/206045/edit)
# Goal:
* Get every integer from the string (not a number, but integer)
* Multiply them
* Output the result
# Input:
*5 kilograms of food eaten, 10 liters of water drank, 20 plates dirty, 40 mugs dirty, and only 3 people acted!*
# Output:
*120000*
# How:
*Result was 5 \* 10 \* 20 \* 40 \* 3*
# What do we count as an integer:
# General:
* If integer has a symbol BEFORE of AFTER the int, only take the number without symbols. `-335 or 335+` are 335 anyways.
* If integer has a symbol like this: `35:3`, don't take it. `35 : 3` is available though, and considered as 2 integers.
# Detailed:
* 35/3 aren't two integers, skip this
* 35.3 is not an integer, skip this
* 35:3, 35\*3, 3e3, etc. aren't ints, skip them as well
* 353 is an integer
* 35 3 are two integers
* 353. is an integer
* 353?, 353!, etc. are integers
* -353 is an integer, but you only claim 353 and skip "-".
* +353 is the same case as upper
# Requirements:
* Select any language you want
* The program should contain as little bytes as possible
* You should tell us the language (if it's, like, exotic, link it like [this](https://github.com/ConorOBrien-Foxx/ecndpcaalrlp))
* Please, upload the code to Try It Online services like [this](https://tio.run/##RY5NTsMwEEbX9Sk@lU0rQcQ@VfccgAOY8ZAMdcaWPRZEiLMHB4HYPr3vh3J@mIi27U6UYguMS7UgaZiv7h9JqlbYL1fXqugE9QvX7InR5dGJGhYvejrj0x0oNcPlgtPxySAVrXKAJbww3lo1eAV/@CVHHvBcGdbXStN7UBS6ob6L0YzodWp@4tr5nNLuzYykjDU1KHP4C@To173fuJfLK8RAackS@yylUpgsruOvvJfQ3L/2GwET2w@JorfheN5fs4Y4ukNha0XxOLqvbfsG)
* Count the bytes using special services like [this](https://www.charactercountonline.com/)
* It would be fine if you'd explain your code!
# Scoring:
Less bytes program wins! The end is 20th of June, you guys have a week
[Answer]
# [Red](http://www.red-lang.org), 109 bytes
```
func[s][p: 1 d: charset"0123456789"parse s[any[to d copy t[any d ahead[" "|"!"|"?"]](p: p * to p t)| skip]]p]
```
[Try it online!](https://tio.run/##rY29bsMwDAb3PMVnTW3hwc5P03rJO3QVNAgmlRhWJEJSUBjIu7tKh3br1IHDHQleYlo/mLTZuAGru4VRZ6NlQA8aMF5sylxU1293@8Pr8e1dycMgaxsWXSIIY5QF5cEV7IUtaQV1V02dkzLmqT4TvKAeC8rzHXmexBgxq6QpFDioA@bJx3Oy14zo4GIksC0cWvQd/FQ4fS8@q0ugZMPcYttBfBUZNKWytNh3uN7OP2gDIQa/YAfhKJ5hx8LUqM1v9/RHt/nv7voF "Red – Try It Online")
[Answer]
# perl -pl, 64 bytes
```
s!\D+|\d+(?:[.:^e/]\d+)+|(\d+)!$1?"*".(0+$1):""!aeg;$_=eval"1$_"
```
[Try it online!](https://tio.run/##nY1BTsMwEEX3nGJiZZESE9sJBhqEsuEWFCoLT6Oorm05BlSpZ8cYhKKuuxr9P3rvewxGpjQXm@f6tNF1NfQvTf@G7DWHVX2qfk9RioFck6bidSlWPSGFwvGx3D7hpzJElFuSkoT9ZNwY1GEGt4OdcxpQRbQUBAczRQx/j6/cBdBB2T2FloM3uZhBTyEeKdxyOHyMS1RWg7PmCB14dN4gqPeIurjKa@OZ@My0OOgC0ewAsWZcspbz9h/mF9JdI@GuyNtDFki8xwe2hq5h387Hydk53XjzAw "Perl 5 – Try It Online")
Ignores anything which isn't a digit, or multiple sequences of digits separated by `/`, `.`, `e`, `:`, or `^`. Sequences of digits are replaced by themselves, prepended with \*. The result, we eval, after predending 1. There's a tiny bit of hackery going to deal with numbers starting with 0s -- we don't want them be interpreted as octal numbers.
Reads lines from `STDIN`, writes the result to `STDOUT`.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/182603/edit).
Closed 4 years ago.
[Improve this question](/posts/182603/edit)
We have X Girls and Y Boys in a class. If more girls sit together they will not behave. Similarly if more boys sit together they will not behave.
Write a program/algorithm to get maximum same gender that will be seated if seating is done to efficiently to get them behave.
Example 1: 5 girls and 1 boy
Expected Output: 3
Explanation: G G B **G G G**
Example 2: 7 girls and 3 boys
Expected Output: 2
Explanation: **G G** B G B G G B G G
[Answer]
# [Python 2](https://docs.python.org/2/), 26 bytes
```
lambda b,g:-min(b/~g,g/~b)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSFJJ91KNzczTyNJvy5dJ12/Lknzf0FRZl6JQpqGoY6pJheMY65jjMwxQHAMUDlIykx1TJA5ppr/AQ "Python 2 – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 31 bytes
*Port of [@TFeld python answer](https://codegolf.stackexchange.com/a/182605/78039)*
```
a=>b=>-Math.min(a/~b,b/~a)+.5|0
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i7J1k7XN7EkQy83M08jUb8uSSdJvy5RU1vPtMbgf3J@XnF@TqpeTn66RpqGqaaGoaYmF6qguaaGsabmfwA "JavaScript (Node.js) – Try It Online")
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/109357/edit).
Closed 7 years ago.
[Improve this question](/posts/109357/edit)
I only very recently discovered code golf and just found this part of the Stackexchange network, and naturally after looking at so many clever answers, I feel inferior. Inner me knows I'll get better over time, but inner me is also vain and needs validation.
At the same time, I don't take kindly to pandering, so you'd **better** not write me a program that looks like it took 15 seconds. You have to *mean* it.
# Goal:
Print the phrase "you're pretty!" or write a function that returns that string. All letters can be upper-case or lower-case, but the punctuation and the spacing must be the same.
# How to mean it:
If you're sensitive and can sympathize with all the emotions associated with feeling like a noobie, you should aim to make your program look like it does something entirely different and innocuous. I like to be surprised :) You may achieve this by not using any of the alphabetical characters in "you're pretty".
Winner is decided by shortest byte count. -5 bytes for each positive or neutral adjective you extend the phrase by, i.e. "you're pretty and effulgent and green", up to a possible 20 byte reduction.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~29~~ 28 - 20 = ~~9~~ 8 points
```
“+vẇSȮv¿⁷“ñż“ÞỌ“Ḋ;“ʠK»j“ and
```
[Try it online!](https://tio.run/nexus/jelly#@/@oYY522cNd7cEn1pUd2v@ocTtQ4PDGo3tA1LyHu3uA9MMdXdZA6tQC70O7s4AMhcS8lP//AQ "Jelly – TIO Nexus")
The bonus turns out to be just *marginally* worth it for Jelly: `“+vẇSȮv¿⁷»` (the compressed representation of `you're pretty`) is 10 bytes. (Now with another byte saved per @ConorOBrien; I'd forgotten that as the final `and` is uncompressed, it wouldn't need a trailing delimeter.)
## Explanation
```
“+vẇSȮv¿⁷“ñż“ÞỌ“Ḋ;“ʠK»j“ and
“+vẇSȮv¿⁷“ñż“ÞỌ“Ḋ;“ʠK» ["you're pretty"," airy"," agile"," calm"," brave"]
j join with
“ and " and"
```
This is pretty much just a case of using Jelly's built-in string compression. Picking adjectives that come near the start of the alphabet makes it slightly shorter than it would be otherwise.
Incidentally, this program would be quite a bit shorter if Jelly's dictionary were more complete. It has plenty of obscure words in, but for some reason is missing `and` (likely because it's only three letters long and thus doesn't gain much from the compression, but it'd benefit from being included in the dictionary for when it's used as part of a longer string, because `“¡ÞṄɱ»` is longer than just writing out the word would be).
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 10 bytes
```
`YŒ'œ pÎ5y
```
Japt uses the [shoco library](http://ed-von-schleck.github.io/shoco/) for string compresstion. Backticks are used to decompress strings.
[Try it online!](https://tio.run/nexus/japt#@58QeahH/dAchYLDfaaV//8DAA "Japt – TIO Nexus")
] |
[Question]
[
**This question already has answers here**:
[Simple integer operation calculator](/questions/91476/simple-integer-operation-calculator)
(42 answers)
Closed 7 years ago.
# The task:
You have to input 2 numbers and output the results of several operations done with them.
# Details:
Input 2 floating point numbers, x != 0 and y != 0 via stdin, command line or function arguments.
Output x+y,
x\*y,
x^y (pow(x,y), not x XOR y),
x-y,
y-x,
x/y and
y/x on STDOUT separated by newlines, commas or spaces.
For languages which doesn't support floats, you may use an external library, implement them yourself or you can not participate :(
Standard loopholes apply, the shortest code in bytes wins. Good luck!
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM), 15 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
Takes x as left argument and y as right argument.
```
+,×,*,-,-⍨,÷,÷⍨
```
Simply a long train of forks (3-trains):
`+,` the sum, followed by
`×,` the product, followed by
`*,` the exponentiation, followed by
`-,` the difference, followed by
`-⍨,` the swapped difference, followed by
`÷,` the ratio, followed by
`÷⍨` the swapped ratio
[TryAPL online!](http://tryapl.org/?a=f%u2190%D7%2C*%2C-%2C%F7%2C%F7%u2368%20%u22C4%202%20f%204&run)
[Answer]
## Haskell, 44 bytes
```
x#y=mapM print[x+y,x*y,x**y,x-y,y-x,x/y,y/x]
```
Example: `4 # 5` prints
```
9.0
20.0
1024.0
-1.0
1.0
0.8
1.25
```
[Answer]
## Ruby, 40 bytes
```
->x,y{puts x+y,x*y,x**y,x-y,y-x,x/y,y/x}
```
[Answer]
# Scala, 68 bytes
```
(x:Float,y:Float)=>Seq(x+y,x*y,math.pow(x,y),x-y,x/y,y/x)map println
```
Pretty striaghtforward.
[Answer]
# Groovy, 36 bytes
```
{a,b->print([a+b,a-b,a/b,a*b,a**b])}
```
Output:
```
({a,b->print([a+b,a-b,a/b,a*b,a**b])})(5.034,2.0568)
```
Results in:
```
[7.0908, 2.9772, 2.4474912485, 10.3539312, 27.777623862468822]
```
[Answer]
# J, 15 bytes
Equivalent to [this](https://codegolf.stackexchange.com/a/97589/43319).
Takes x as left argument and y as right argument.
```
+,*,^,-,-~,%,%~
```
Simply a long train of forks (3-trains):
`+,` the sum, followed by
`*,` the product, followed by
`^,` the exponentiation, followed by
`-,` the difference, followed by
`-~,` the swapped difference, followed by
`%,` the ratio, followed by
`%~` the swapped ratio
[Answer]
## PowerShell v2+, 66 bytes
```
param($x,$y)$x+$y;$x*$y;[math]::Pow($x,$y);$x-$y;$y-$x;$x/$y;$y/$x
```
Very boring, does exactly what it says on the tin. Each statement (separated by `;`) is evaluated and left on the pipeline. At program completion, everything left on the pipeline is implicitly printed via `Write-Output`.
Long because PowerShell uses `$` to delineate variables, and it also doesn't have a `^` or `**` or equivalent operator, so we need a .NET call.
Note that the `Write-Output` will *display* as integer values, even if the input is floats. Running a `.GetType()` will show the output to be `System.Double` however.
```
PS C:\Tools\Scripts\golfing> .\perform-several-mathematic-operations.ps1 5.0 6.0
11
30
15625
-1
1
0.833333333333333
1.2
```
[Answer]
# C# - 106 bytes
```
void r(float x,float y){System.Console.WriteLine($"{x+y} {x*y} {Math.Pow(x,y)} {x-y} {y-x} {x/y} {y/x}");}
```
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/73263/edit).
Closed 8 years ago.
[Improve this question](/posts/73263/edit)
Question: can you design a [Builder Pattern](https://en.wikipedia.org/wiki/Builder_pattern) API which verifies at compile time that every field is set exactly once?
To be eligible, the size of the compiler output should not be exponential in the number of fields. The best solution will be the shortest implementation for a class of 22 fields.
---
## Example of a possible surface API in java
Given an class for immutable data structure such as this one:
```
public class Human {
private final String name;
private final Int age;
private final Double money;
public Human(String name, Int age, Double money) {
this.name = name;
this.age = age;
this.money = money;
}
public String getName() { return name; }
public Int getAge() { return age; }
public Double getMoney() { return money; }
}
```
The goal is to design an API to construct instances this `Humain` class with the following requirements, checked at compile time (the code in example is just a possible design, you can come up with anything that is equivalent in term of functionally):
* Possible to set parameters in any order:
```
Human h = HumanBuilder().withName("n").withMoney(0.15).withAge(1).build();
Human g = HumanBuilder().withName("n").withAge(1).withMoney(0.15).build();
```
* Possible to set parameters in different places of the code:
```
// Given appropriate takesCareOfTheMan & takesCareOfTheMoney methods
Human h = takesCareOfTheMan(takesCareOfTheMoney(HumanBuilder())).build();
Human g = takesCareOfTheMoney(takesCareOfTheMan(HumanBuilder())).build();
```
* Impossible to set the same parameter twice:
```
// This should not compile:
// Human h = HumanBuilder().withName("n").withAge(1).withAge(2).withMoney(0.15).build();
```
* Impossible to omit a parameter:
```
// This should not compile:
// Human h = HumanBuilder().withName("n").withMoney(0.15).build();
```
[Answer]
How about something like this, in Haskell:
```
{-# LANGUAGE GADTs, DataKinds, KindSignatures, StandaloneDeriving #-}
module Builder ( Human', Human, mkHuman, unHuman
, withName, withAge, withMoney
) where
data Optional (b :: Bool) (a :: *) where
Missing :: Optional False a
Present :: a -> Optional True a
deriving instance (Show a) => Show (Optional b a)
data Human' b1 b2 b3 where
MkHuman :: Optional b1 String -> Optional b2 Int -> Optional b3 Double -> Human' b1 b2 b3
deriving instance Show (Human' b1 b2 b3)
type Human = Human' True True True
mkHuman :: Human' False False False
mkHuman = MkHuman Missing Missing Missing
unHuman :: Human -> (String, Int, Double)
unHuman (MkHuman (Present name) (Present age) (Present money)) = (name, age, money)
withName :: String -> Human' False b2 b3 -> Human' True b2 b3
withName name (MkHuman _ age money) = MkHuman (Present name) age money
withAge :: Int -> Human' b1 False b3 -> Human' b1 True b3
withAge age (MkHuman name _ money) = MkHuman name (Present age) money
withMoney :: Double -> Human' b1 b2 False -> Human' b1 b2 True
withMoney money (MkHuman name age _) = MkHuman name age (Present money)
```
Example usage:
```
h1, h2 :: Human
h1 = withName "n" . withMoney 0.15 . withAge 1 $ mkHuman
h2 = withName "n" . withAge 1 . withMoney 0.15 $ mkHuman
takesCareOfTheName :: Human' False b2 b3 -> Human' True b2 b3
takesCareOfTheName = withName "John"
-- This doesn't typecheck
h3 :: Human
h3 = withName "newName" h1
-- Neither does this
h4 :: Human
h4 = withName "n" . withAge 1 $ mkHuman
```
[Answer]
OK here's one, also in Haskell, that is much more extensible: notice how `Human` is merely a `Builder` with a specific index of field types.
```
{-# LANGUAGE GADTs, DataKinds, KindSignatures, StandaloneDeriving #-}
{-# LANGUAGE TypeOperators, TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances, FlexibleContexts #-}
data Optional (b :: Bool) (a :: *) where
Missing :: Optional False a
Present :: a -> Optional True a
deriving instance (Show a) => Show (Optional b a)
data Builder (as :: [*]) (bs :: [Bool]) where
BNil :: Builder '[] '[]
BCons :: Optional b a -> Builder as bs -> Builder (a ': as) (b ': bs)
type family Empty_ as where
Empty_ '[] = '[]
Empty_ (a ': as) = False ': Empty_ as
type family Full_ as where
Full_ '[] = '[]
Full_ (a ': as) = True ': Full_ as
type family Empty builder where
Empty (Builder as) = Builder as (Empty_ as)
type family Full builder where
Full (Builder as) = Builder as (Full_ as)
data Tuple as where
TNil :: Tuple '[]
(:>) :: a -> Tuple as -> Tuple (a ': as)
infixr 5 :>
fromFull :: Full (Builder as) -> Tuple as
fromFull BNil = TNil
fromFull (BCons (Present x) xs) = x :> fromFull xs
class Buildable as where
emptyBuilder :: Empty (Builder as)
instance Buildable '[] where
emptyBuilder = BNil
instance (Buildable as) => Buildable (a ': as) where
emptyBuilder = BCons Missing emptyBuilder
type Human = Builder '[String, Int, Double]
mkHuman :: Empty Human
mkHuman = emptyBuilder
data Nat = Z | S Nat
data Lookup i as where
Here :: a -> Lookup Z (a ': as)
There :: Lookup i as -> Lookup (S i) (a ': as)
type family FillAt i bs where
FillAt Z (False ': bs) = True ': bs
FillAt (S i) (b ': bs) = b ': FillAt i bs
class Fill bs (i :: Nat) where
fill :: Lookup i as -> Builder as bs -> Builder as (FillAt i bs)
instance Fill (False ': bs) Z where
fill (Here x) (BCons Missing xs) = BCons (Present x) xs
instance (Fill bs i) => Fill (b ': bs) (S i) where
fill (There k) (BCons x xs) = BCons x $ fill k xs
withName :: (Fill bs Z) => String -> Human bs -> Human (FillAt Z bs)
withName = fill . Here
withAge :: (Fill bs (S Z)) => Int -> Human bs -> Human (FillAt (S Z) bs)
withAge = fill . There . Here
withMoney :: (Fill bs (S (S Z))) => Double -> Human bs -> Human (FillAt (S (S Z)) bs)
withMoney = fill . There . There . Here
unHuman :: Full Human -> (String, Int, Double)
unHuman h = case fromFull h of
name :> age :> money :> TNil -> (name, age, money)
h1, h2 :: Full Human
h1 = withName "n" . withMoney 0.15 . withAge 1 $ mkHuman
h2 = withName "n" . withAge 1 . withMoney 0.15 $ mkHuman
takesCareOfTheName :: (Fill bs Z) => Human bs -> Human (FillAt Z bs)
takesCareOfTheName = withName "John"
-- -- This doesn't typecheck
-- h3 :: Full Human
-- h3 = withName "newName" h1
-- -- Neither does this
-- h4 :: Full Human
-- h4 = withName "n" . withAge 1 $ mkHuman
```
[Answer]
```
import shapeless.<:!<
case class HumanBuilder[A]( name: String, age: Int, money: Double) {
def withName(name: String)(implicit ev: A <:!< Name): HumanBuilder[A with Name] = this.copy[A with Name](name = name)
def withAge(age: Int)(implicit ev: A <:!< Age): HumanBuilder[A with Age] = this.copy[A with Age](age = age)
def withMoney(money: Double)(implicit ev: A <:!< Money): HumanBuilder[A with Money] = this.copy[A with Money](money = money)
def build()(implicit ev: A =:= Builder with Name with Age with Money): Human = Human(name, age, money)
}
object HumanBuilder {
def apply(): HumanBuilder[Builder] = HumanBuilder[Builder]("", 0, 0.0)
}
trait Builder
trait Name
trait Age
trait Money
case class Human(name: String, age: Int, money: Double)
```
Usage
```
scala> HumanBuilder().withName("test").withAge(10).withMoney(1.0).build()
res1: puzzle.Human = Human(test,10,1.0)
scala> HumanBuilder().withMoney(3.0).withName("test").withAge(10).build()
res2: puzzle.Human = Human(test,10,3.0)
scala> HumanBuilder().withName("test").withAge(10).withMoney(1.0).withMoney(3.0).build()
<console>:14: error: ambiguous implicit values:
both method nsubAmbig1 in package shapeless of type [A, B >: A]=> shapeless.package.<:!<[A,B]
and method nsubAmbig2 in package shapeless of type [A, B >: A]=> shapeless.package.<:!<[A,B]
match expected type shapeless.<:!<[puzzle.Builder with puzzle.Name with puzzle.Age with puzzle.Money,puzzle.Money]
HumanBuilder().withName("test").withAge(10).withMoney(1.0).withMoney(3.0).build()
^
scala> HumanBuilder().withName("test").withAge(10).build()
<console>:14: error: Cannot prove that puzzle.Builder with puzzle.Name with puzzle.Age =:= puzzle.Builder with puzzle.Name with puzzle.Age with puzzle.Money.
HumanBuilder().withName("test").withAge(10).build()
```
[Answer]
In Scala, you could do the following:
```
// Or import shapeless._
object Lib {
trait Nat
trait Succ[N <: Nat] extends Nat
trait Z extends Nat
}
```
```
object Builder {
import Lib._
case class Human(age: Int, name: String, money: Double)
trait WithAge { def age: Int }
trait WithName { def name: String }
trait WithMoney { def money: Double }
trait HumanBuilder {
type N <: Nat
type Next[N0 <: Nat] = this.type { type N = Succ[N0] }
var age: Int = _
var name: String = _
var money: Double = _
def thiz[A]: A = asInstanceOf[A] // ez typecheck
def withAge(a: Int): Next[N] with WithAge = { age = a; thiz }
def withName(n: String): Next[N] with WithName = { name = n; thiz }
def withMoney(m: Double): Next[N] with WithMoney = { money = m; thiz }
}
object HumanBuilder {
def apply() = new HumanBuilder { type N = Z }
type WithList = WithAge with WithName with WithMoney
type WithSize = { type N = Succ[Succ[Succ[Z]]] }
implicit class Build(hb: HumanBuilder with WithList with WithSize) {
def build(): Human = Human(hb.age, hb.name, hb.money)
}
}
}
```
Tests:
```
object Usage extends App {
import shapeless.test.illTyped
import Builder._
illTyped("""
HumanBuilder()
.withName("n")
.withAge(1).withAge(2)
.withMoney(0.15)
.build()
""")
illTyped("""
HumanBuilder()
.withName("n")
// .withAge(1)
.withMoney(0.15)
.build()
""")
val h: Human = HumanBuilder()
.withName("n")
.withAge(1)
.withMoney(0.15)
.build()
println(h)
}
```
] |
[Question]
[
**This question already has answers here**:
[In how many bits do I fit](/questions/104785/in-how-many-bits-do-i-fit)
(73 answers)
Closed 2 years ago.
# Definition
Given some number, *x* calculate the smallest number *i* such that 2*i*≥*x*. This is not a duplicate of [this question](https://codegolf.stackexchange.com/questions/104785/in-how-many-bits-do-i-fit). It is slightly different in that an input of 16 should yield an output of 4 whereas 16 returns 5 in the linked question.
# Input
Input will be an unsigned 32-bit integer.
# Output
Output will be an unsigned integer (8-bit, 16-bit, 32-bit etc. are all ok)
# Test Cases
| Input | Output |
| --- | --- |
| 0 | 0 |
| 1 | 0 |
| 2 | 1 |
| 15 | 4 |
| 16 | 4 |
| 65536 | 16 |
# Example (C# 51 bytes)
```
uint A(uint x) => (uint)Math.Ceiling(Math.Log2(x));
```
This is code-golf, so the shortest answer in bytes wins! Standard loopholes and rules apply. Tie goes to first poster.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 5 bytes
```
≬E?≥ṅ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLiiaxFP+KJpeG5hSIsIiIsIjE1Il0=)
Quite literally returns the first number where 2\*\*n >= input
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 10 bytes
```
IL↨⌈⟦⁰⊖N⟧²
```
[Try it online!](https://tio.run/##DcHBCkBAEADQX3GcLQrl5IaLQu5yGGtC2aXdWfn74T29o9MXniKjOyxDjZ6hI7vxDhV6gh7fwwQDUxpHDWlHhizTCq29Aw/BLORAqVnFUa5@pUhWSPKcHw "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
N Input as a number
⊖ Decremented
⁰ Literal `0`
⟦ ⟧ List of the above
⌈ Maximum
↨ Convert to base
² Literal `2`
L Length
I Cast to string
Implicitly print
```
Charcoal converts `0` to `[]` so giving the correct log for an input of `1`, but `0` as input needs to be special-cased.
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 23 bytes
```
n->if(n,#binary(n-1),0)
```
[Try it online!](https://tio.run/##FYoxCoAwDEWvEurSQAqt0m56EXGoQyUgIRQXT1/j8B/vwdfaOVw6GqxDwsbNC00nS@2vl5CQIo6qeltB2EA7y2Pq/nBgb0SCPRIkgtmYbYWg5LyUA8cH "Pari/GP – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 26 bytes
```
.+
$*
^((1+)(?=\2))*1*
$#1
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wX0@bS0WLK05Dw1BbU8PeNsZIU1PLUItLRdnw/38DLkMuIy5DUy5DMy4zU1NjMwA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
.+
$*
```
Convert the input to unary.
```
^((1+)(?=\2))*1*
```
Divide by two as many times as possible, rounding up each time, until `1` is reached. (The leading `^` and trailing `*` are needed to handle the edge case of zero input.)
```
$#1
```
Output the number of rounded divisions made.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/205384/edit).
Closed 3 years ago.
[Improve this question](/posts/205384/edit)
A normal Brainfuck program starts out with an array of cells, all containing the number `0`. This program, on the other hand, must be able to run starting with any number `x` in the leftmost cell. The only rule is that at the end of program execution, the "pointed-to" cell must be cell `x`. (The leftmost cell is cell 0).
* Each cell contains a number from 0 to 255, and every cell but the leftmost one starts out with a value of 0.
* There are an infinite number of cells, but none to the left of the leftmost cell.
This is code golf, so the submission using the fewest bytes wins. Good luck!
[Answer]
# 10 bytes
```
[[->+<]>-]
```
[Try it online!](https://fatiherikli.github.io/brainfuck-visualizer/#KysrKysrKysrKyAvLyBzZXQgdXAgdGhlIGZpcnN0IGNlbGwKW1stPis8XT4tXQ==)
Move `x` one cell to the right, and decrease it by 1. Repeat until `x` is 0.
[Answer]
# 20 bytes
```
[->>[>]+[<]<]>>[>]<<
```
[Try it online.](https://fatiherikli.github.io/brainfuck-visualizer/#aW5jcmVtZW50IHRoZSBmaXJzdCBjZWxsIGhlcmUKKysrCgpteSBjb2RlClstPj5bPl0rWzxdPF0+Pls+XTw8)
This could be made shorter if there were a single cell to the left of cell 0.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/205219/edit).
Closed 3 years ago.
[Improve this question](/posts/205219/edit)
This is a very simple challenge.
# Task
Whenever your code is run, your code should output the next sunset date and time in GMT for all capital cities on Earth. You should get the list of capitals from the below table. The dates and times should be outputted sorted by the name of the capital. You don’t need to output the capital name.
Here is a copy of the list of capitals. Where there is more than one option your code may choose any one of them.
$$\begin{array}{l|l}
\text{COUNTRY} & \text{CAPITAL CITY} \\ \hline
\text{United Arab Emirates} & \text{Abu Dhabi} \\ \hline
\text{Nigeria} & \text{Abuja} \\ \hline
\text{Ghana} & \text{Accra} \\ \hline
\text{Ethiopia} & \text{Addis Ababa} \\ \hline
\text{Algeria} & \text{Algiers} \\ \hline
\text{Jordan} & \text{Amman} \\ \hline
\text{Netherlands} & \text{Amsterdam} \\ \hline
\text{Andorra} & \text{Andorra la Vella} \\ \hline
\text{Turkey} & \text{Ankara} \\ \hline
\text{Madagascar} & \text{Antananarivo} \\ \hline
\text{Samoa} & \text{Apia} \\ \hline
\text{Turkmenistan} & \text{Ashgabat} \\ \hline
\text{Eritrea} & \text{Asmara} \\ \hline
\text{Paraguay} & \text{Asuncion} \\ \hline
\text{Greece} & \text{Athens} \\ \hline
\text{Iraq} & \text{Baghdad} \\ \hline
\text{Azerbaijan} & \text{Baku} \\ \hline
\text{Mali} & \text{Bamako} \\ \hline
\text{Brunei} & \text{Bandar Seri Begawan} \\ \hline
\text{Thailand} & \text{Bangkok} \\ \hline
\text{Central African Republic} & \text{Bangui} \\ \hline
\text{Gambia} & \text{Banjul} \\ \hline
\text{Saint Kitts and Nevis} & \text{Basseterre} \\ \hline
\text{China} & \text{Beijing} \\ \hline
\text{Lebanon} & \text{Beirut} \\ \hline
\text{Northern Ireland} & \text{Belfast} \\ \hline
\text{Serbia} & \text{Belgrade} \\ \hline
\text{Belize} & \text{Belmopan} \\ \hline
\text{Germany} & \text{Berlin} \\ \hline
\text{Switzerland} & \text{Bern} \\ \hline
\text{Kyrgyzstan} & \text{Bishkek} \\ \hline
\text{Guinea-Bissau} & \text{Bissau} \\ \hline
\text{Colombia} & \text{Bogota} \\ \hline
\text{Brazil} & \text{Brasilia} \\ \hline
\text{Slovakia} & \text{Bratislava} \\ \hline
\text{Congo, Republic of the} & \text{Brazzaville} \\ \hline
\text{Barbados} & \text{Bridgetown} \\ \hline
\text{Belgium} & \text{Brussels} \\ \hline
\text{Romania} & \text{Bucharest} \\ \hline
\text{Hungary} & \text{Budapest} \\ \hline
\text{Argentina} & \text{Buenos Aires} \\ \hline
\text{Egypt} & \text{Cairo} \\ \hline
\text{Australia} & \text{Canberra} \\ \hline
\text{Venezuela} & \text{Caracas} \\ \hline
\text{Wales} & \text{Cardiff} \\ \hline
\text{Saint Lucia} & \text{Castries} \\ \hline
\text{Moldova} & \text{Chisinau} \\ \hline
\text{Sri Lanka} & \text{Colombo} \\ \hline
\text{Guinea} & \text{Conakry} \\ \hline
\text{Denmark} & \text{Copenhagen} \\ \hline
\text{Senegal} & \text{Dakar} \\ \hline
\text{Syria} & \text{Damascus} \\ \hline
\text{Bangladesh} & \text{Dhaka} \\ \hline
\text{East Timor} & \text{Dili} \\ \hline
\text{Djibouti} & \text{Djibouti} \\ \hline
\text{Tanzania} & \text{Dodoma} \\ \hline
\text{Qatar} & \text{Doha} \\ \hline
\text{Ireland} & \text{Dublin} \\ \hline
\text{Tajikistan} & \text{Dushanbe} \\ \hline
\text{Scotland} & \text{Edinburgh} \\ \hline
\text{Sierra Leone} & \text{Freetown} \\ \hline
\text{Tuvalu} & \text{Funafuti} \\ \hline
\text{Botswana} & \text{Gaborone} \\ \hline
\text{Guyana} & \text{Georgetown} \\ \hline
\text{Burundi} & \text{Gitega} \\ \hline
\text{Guatemala} & \text{Guatemala City} \\ \hline
\text{Vietnam} & \text{Hanoi} \\ \hline
\text{Zimbabwe} & \text{Harare} \\ \hline
\text{Cuba} & \text{Havana} \\ \hline
\text{Finland} & \text{Helsinki} \\ \hline
\text{Solomon Islands} & \text{Honiara} \\ \hline
\text{Pakistan} & \text{Islamabad} \\ \hline
\text{Indonesia} & \text{Jakarta} \\ \hline
\text{South Sudan} & \text{Juba} \\ \hline
\text{Afghanistan} & \text{Kabul} \\ \hline
\text{Uganda} & \text{Kampala} \\ \hline
\text{Nepal} & \text{Kathmandu} \\ \hline
\text{Sudan} & \text{Khartoum} \\ \hline
\text{Ukraine} & \text{Kiev} \\ \hline
\text{Rwanda} & \text{Kigali} \\ \hline
\text{Jamaica} & \text{Kingston} \\ \hline
\text{Saint Vincent and the Grenadines} & \text{Kingstown} \\ \hline
\text{Congo, Democratic Republic of the} & \text{Kinshasa} \\ \hline
\text{Malaysia} & \text{Kuala Lumpur} \\ \hline
\text{Kuwait} & \text{Kuwait City} \\ \hline
\text{Bolivia} & \text{La Paz (administrative), Sucre (official)} \\ \hline
\text{Gabon} & \text{Libreville} \\ \hline
\text{Malawi} & \text{Lilongwe} \\ \hline
\text{Peru} & \text{Lima} \\ \hline
\text{Portugal} & \text{Lisbon} \\ \hline
\text{Slovenia} & \text{Ljubljana} \\ \hline
\text{Togo} & \text{Lome} \\ \hline
\text{England} & \text{London} \\ \hline
\text{United Kingdom} & \text{London} \\ \hline
\text{Angola} & \text{Luanda} \\ \hline
\text{Zambia} & \text{Lusaka} \\ \hline
\text{Luxembourg} & \text{Luxembourg} \\ \hline
\text{Spain} & \text{Madrid} \\ \hline
\text{Marshall Islands} & \text{Majuro} \\ \hline
\text{Equatorial Guinea} & \text{Malabo} \\ \hline
\text{Maldives} & \text{Male} \\ \hline
\text{Nicaragua} & \text{Managua} \\ \hline
\text{Bahrain} & \text{Manama} \\ \hline
\text{Philippines} & \text{Manila} \\ \hline
\text{Mozambique} & \text{Maputo} \\ \hline
\text{Lesotho} & \text{Maseru} \\ \hline
\text{Eswatini (Swaziland)} & \text{Mbabana} \\ \hline
\text{Palau} & \text{Melekeok} \\ \hline
\text{Mexico} & \text{Mexico City} \\ \hline
\text{Belarus} & \text{Minsk} \\ \hline
\text{Somalia} & \text{Mogadishu} \\ \hline
\text{Monaco} & \text{Monaco} \\ \hline
\text{Liberia} & \text{Monrovia} \\ \hline
\text{Uruguay} & \text{Montevideo} \\ \hline
\text{Comoros} & \text{Moroni} \\ \hline
\text{Russia} & \text{Moscow} \\ \hline
\text{Oman} & \text{Muscat} \\ \hline
\text{Chad} & \text{N'Djamena} \\ \hline
\text{Kenya} & \text{Nairobi} \\ \hline
\text{Bahamas} & \text{Nassau} \\ \hline
\text{Myanmar (Burma)} & \text{Nay Pyi Taw} \\ \hline
\text{India} & \text{New Delhi} \\ \hline
\text{Niger} & \text{Niamey} \\ \hline
\text{Cyprus} & \text{Nicosia} \\ \hline
\text{Nauru} & \text{No official capital} \\ \hline
\text{Mauritania} & \text{Nouakchott} \\ \hline
\text{Tonga} & \text{Nuku'alofa} \\ \hline
\text{Kazakhstan} & \text{Nur-Sultan} \\ \hline
\text{Norway} & \text{Oslo} \\ \hline
\text{Canada} & \text{Ottawa} \\ \hline
\text{Burkina Faso} & \text{Ouagadougou} \\ \hline
\text{Federated States of Micronesia} & \text{Palikir} \\ \hline
\text{Panama} & \text{Panama City} \\ \hline
\text{Suriname} & \text{Paramaribo} \\ \hline
\text{France} & \text{Paris} \\ \hline
\text{Cambodia} & \text{Phnom Penh} \\ \hline
\text{Montenegro} & \text{Podgorica} \\ \hline
\text{Haiti} & \text{Port au Prince} \\ \hline
\text{Mauritius} & \text{Port Louis} \\ \hline
\text{Papua New Guinea} & \text{Port Moresby} \\ \hline
\text{Trinidad and Tobago} & \text{Port of Spain} \\ \hline
\text{Vanuatu} & \text{Port Vila} \\ \hline
\text{Benin} & \text{Porto Novo} \\ \hline
\text{Czech Republic (Czechia)} & \text{Prague} \\ \hline
\text{Cape Verde} & \text{Praia} \\ \hline
\text{South Africa} & \text{Pretoria, Bloemfontein, Cape Town} \\ \hline
\text{Kosovo} & \text{Pristina} \\ \hline
\text{North Korea} & \text{Pyongyang} \\ \hline
\text{Ecuador} & \text{Quito} \\ \hline
\text{Morocco} & \text{Rabat} \\ \hline
\text{Iceland} & \text{Reykjavik} \\ \hline
\text{Latvia} & \text{Riga} \\ \hline
\text{Saudi Arabia} & \text{Riyadh} \\ \hline
\text{Italy} & \text{Rome} \\ \hline
\text{Dominica} & \text{Roseau} \\ \hline
\text{Grenada} & \text{Saint George's} \\ \hline
\text{Antigua and Barbuda} & \text{Saint John's} \\ \hline
\text{Costa Rica} & \text{San Jose} \\ \hline
\text{San Marino} & \text{San Marino} \\ \hline
\text{El Salvador} & \text{San Salvador} \\ \hline
\text{Yemen} & \text{Sana'a} \\ \hline
\text{Chile} & \text{Santiago} \\ \hline
\text{Dominican Republic} & \text{Santo Domingo} \\ \hline
\text{Sao Tome and Principe} & \text{Sao Tome} \\ \hline
\text{Bosnia and Herzegovina} & \text{Sarajevo} \\ \hline
\text{South Korea} & \text{Seoul} \\ \hline
\text{Singapore} & \text{Singapore} \\ \hline
\text{North Macedonia (Macedonia)} & \text{Skopje} \\ \hline
\text{Bulgaria} & \text{Sofia} \\ \hline
\text{Sweden} & \text{Stockholm} \\ \hline
\text{Fiji} & \text{Suva} \\ \hline
\text{Taiwan} & \text{Taipei} \\ \hline
\text{Estonia} & \text{Tallinn} \\ \hline
\text{Kiribati} & \text{Tarawa Atoll} \\ \hline
\text{Uzbekistan} & \text{Tashkent} \\ \hline
\text{Georgia} & \text{Tbilisi} \\ \hline
\text{Honduras} & \text{Tegucigalpa} \\ \hline
\text{Iran} & \text{Tehran} \\ \hline
\text{Israel} & \text{Tel Aviv (Jerusalem has limited recognition)} \\ \hline
\text{Bhutan} & \text{Thimphu} \\ \hline
\text{Albania} & \text{Tirana (Tirane)} \\ \hline
\text{Japan} & \text{Tokyo} \\ \hline
\text{Libya} & \text{Tripoli} \\ \hline
\text{Tunisia} & \text{Tunis} \\ \hline
\text{Mongolia} & \text{Ulaanbaatar} \\ \hline
\text{Liechtenstein} & \text{Vaduz} \\ \hline
\text{Malta} & \text{Valletta} \\ \hline
\text{Vatican City} & \text{Vatican City} \\ \hline
\text{Seychelles} & \text{Victoria} \\ \hline
\text{Austria} & \text{Vienna} \\ \hline
\text{Laos} & \text{Vientiane} \\ \hline
\text{Lithuania} & \text{Vilnius} \\ \hline
\text{Poland} & \text{Warsaw} \\ \hline
\text{United States} & \text{Washington D.C} \\ \hline
\text{New Zealand} & \text{Wellington} \\ \hline
\text{Namibia} & \text{Windhoek} \\ \hline
\text{Côte d'Ivoire (Ivory Coast)} & \text{Yamoussoukro} \\ \hline
\text{Cameroon} & \text{Yaounde} \\ \hline
\text{Armenia} & \text{Yerevan} \\ \hline
\text{Croatia} & \text{Zagreb} \\ \hline
\end{array}$$
Your code may use any libraries you like and may even access the Internet to get relevant data. It may also output the dates and times in any easily human readable form you choose. You should assume the code is run in 2020. The time you give for sunset will be deemed correct if there is at least one website or data source (that existed before this question was posed) that agrees with you.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 106 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
’»‚†Ò‚Ÿ.ŒŒ/‚ïŒÇíÇ.htm’.w’¡Õ="17">’¡ε'<¡н„,(S¡н}¦āÈÏ{ε’Š¹.ŒŒ/€±?q=¿Ô+ÿ+ƒÜ’.w©’ƒ£-c·¼:2">’¡θ5£®žg…ÿ (¡θ')¡н‚
```
Couple of assumptions, which are allowed and/or required for the challenges:
1. The program is run in 2020.
2. The url <https://geographyfieldwork.com/WorldCapitalCities.htm> is accessible and contains the html shown in the second TIO below
3. Google is accessible and contains the html shown in the fourth TIO below
4. *[Temporarily]* Assumes Elixir (in which 05AB1E is built) accessing a website makes adjustments similar to a browser (i.e. implicitly adds `https://` and converts spaces to `%20`). I'll try to verify this locally in a moment. If this isn't true, I'll delete this answer and fix it.
Outputs all times in their respective time zones instead of all in GMT as the challenge description states, which [OP allowed in the comments](https://codegolf.stackexchange.com/questions/205219/sunset-in-every-capital/205254#comment486960_205219).
This will be output as a list of pairs, where each pair is the time with a timezone (i.e. `["21:46","CEST"]`).
No direct TIO, since the `.w` builtin (to access a website) is disabled on TIO. But:
```
’»‚†Ò‚Ÿ.ŒŒ/‚ïŒÇíÇ.htm’
```
[Try this part online to see the generation of the URL.](https://tio.run/##yy9OTMpM/f//UcPMQ7sfNcx61LDg8CQgfXSH3tFJRyfpA5mH1x@ddLj98NrD7XoZJblAhf//AwA)
```
’¡Õ="17">’¡ε'<¡н„,(S¡н}¦āÈÏ{
```
[Try this part online to see it creates the sorted list of cities based on the website's HTML content.](https://tio.run/##zX1Lc@M4tuZ68legVTNXzhhLNmVnOp@@4Uc@XGlnui1nVlT3VFRAJETCIgkVQFopV@fEnd3s7uouZjMRdzO/YGY5m@5ZT8xvuH@k5xyApEiJoCi74t6uikiLBPABODg4LzwoFB1x9te//ss//Lc///Nf/ul1xznoHOqH//u/uq/@/M//73//yz/89@2tIf769uf/8X/@y1/@61/@8de//rXT6Tx69bvTTyfXP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zub8P2gme8Hm/D9oJnvBxvJ9zUCfhO@HzTz/WADvkeD@J4abKz/62zfT2utL733oNL7Dyr95EGlnz6o9MGDSj97UOnnDyrdqFRaFH8YtzkPYzfnYfzmPIzhnIdxnPMwlnMexnPOw5jOeRjXDR7GdYMHyriHcd2gBdd9e1RyQnZGwpvjX/w67@GjTqfz/wE)
```
’й.ŒŒ/€±?q=¿Ô+ÿ+ƒÜ’
```
[Try this part online to see the generation of the Google-search URL.](https://tio.run/##ATcAyP9vc2FiaWX//@KAmcWgwrkuxZLFki/igqzCsT9xPcK/w5Qrw78rxpLDnOKAmf//QW1zdGVyZGFt)
```
©’ƒ£-c·¼:2">’¡θ5£®žg…ÿ (¡θ')¡н‚
```
[Try the TIO in this pastebin (the link of the TIO itself is too large.. -\_-) to see it creates the correct result for a given city based on the Google's search result HTML content.](https://pastebin.com/uTaktNGg)
**Explanation:**
```
’»‚†Ò‚Ÿ.ŒŒ/‚ïŒÇíÇ.htm’ # Push dictionary string "geographyfieldwork.com/worldcapitalcities.htm"
.w # Access this website and read its HTML content
’¡Õ="17">’ # Push dictionary string 'height="17">'
¡ # Split the html on that
ε # Map each string-part to:
'<¡ '# Split it on "<"
н # And only leave the first part
„,(S¡ # Split that part by "," and "("
н # And again only leave the first part
}¦ # After the map: remove the first empty string
# (we now have a list of all unordered countries + cities)
ā # Push a list in the range [1,length] (without popping)
È # Check for each value whether it's odd
Ï # Only leave the strings at those truthy values
{ # And sort those alphabetically
```
We now have a sorted list of all cities.
```
ε # Map each city to:
’й.ŒŒ/€±?q=¿Ô+ÿ+ƒÜ’ # Push dictionary string "google.com/search?q=sunset+ÿ+today",
# where the `ÿ` is automatically filled with the city
.w # Access this website and read its HTML content
© # Store it in variable `®` (without popping)
’ƒ£-c·¼:2">’ "# Push dictionary string 'line-clamp:2">'
¡ # Split the content on that
θ # Only leave the last (second) part
5£ # Only leave the first 5 characters (the time)
® # Push the HTML content again
žg # Push the current year (2020)
…ÿ ( # Push string "ÿ (", where the `ÿ` is filled with 2020: "2020 ("
¡ # Split the content on that
θ # Only leave the last (second) part
')¡ '# Split it on ")"
н # And leave the first item (the timezone)
‚ # Pair the time and timezone strings together
# (after which the resulting mapped pair of strings is output implicitly)
```
[See this 05AB1E tip of mine (section *How to use the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `’»‚†Ò‚Ÿ.ŒŒ/‚ïŒÇíÇ.htm’` is `"geographyfieldwork.com/worldcapitalcities.htm"`; `’¡Õ="17">’` is `'height="17">'`; `’й.ŒŒ/€±?q=¿Ô+ÿ+ƒÜ’` is `"google.com/search?q=sunset+ÿ+today"`; and `’ƒ£-c·¼:2">’` is `'line-clamp:2">'`.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/187871/edit).
Closed 4 years ago.
[Improve this question](/posts/187871/edit)
**The rule is:**
* `a, b, c, d, e` is an integer from `0` to `1000`, no relation between `a, b, c, d, e` so `a` can equal to `b` or `c`, ...
* can not use more than 3 loops (it can be 3 nested loops or 3 normal loops, or 2 nested loops + 1 normal loop, ...)
* you need to find all the answers for `(a, b, c, d, e)` that is:
```
a + b + c + d + e = 1000
```
* Your answer can be any format: line by line, array, object, ... but it must be clear so anyone can see it.
* Shortest bytes will be win for each language!
For example here is when I used 5 loops to solve this puzzle and it violates the rules:
<https://repl.it/repls/BestKnobbyDonateware>
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~23~~ 16 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Full program. No loops. Prints a list of quintuplets with two spaces between them. Each quintuplet has the variables separated by single spaces. Requires 0-indexing (`⎕IO←0`) which is default on many systems.
```
⍸1E3=⊃∘.+/5⍴⊂⍳1001
```
Since the above code requires more memory than available on TIO, here's exactly the same, but with a + b + c + d + e between 0 and 10 and a sum of 10:
```
⍸1E1=⊃∘.+/5⍴⊂⍳11.0
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkGXI862gv@P@rdYehqaPuoq/lRxww9bX3TR71bHnU1PerdbGioZ/AfqOa/AhgUAAA "APL (Dyalog Unicode) – Try It Online")
`⍳1001` the **ɩ**ntegers 0…1000
`⊂` enclose to treat as a unit
`5⍴` reshape that to length 5
`∘.+/` reduction by outer-sum (like outer product, but with plus)
this creates a 5D array with all dimensions being 1000 elements long
`⊃` disclose (the reduction had to enclose the result to reduce the rank from 1 to 0)
`1E3` 5D Boolean mask where equal to 1000
`⍸` list of **ɩ**ndices where true
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
₄Ý5ãʒO₄Q
```
No loops.. (Well, maybe 1 if you count the filter as a loop I guess.)
Outputs as a list of lists of integers.
[Try it online with `10` instead of `1000`.](https://tio.run/##yy9OTMpM/f8/5PBc08OLT03yDwn8/x8A)
**Explanation:**
```
₄Ý # Push a list in the range [0,1000]
5ã # Create quintuples by repeating the cartesian product 5 times
ʒ # Filter this list by:
O # Where the sum
₄Q # Is equal to 1000
# (output the result implicitly after the filter)
```
[Answer]
# [VDM-SL](https://raw.githubusercontent.com/overturetool/documentation/master/documentation/VDM10LangMan/VDM10_lang_man.pdf), 57 bytes
```
{[a,b,c,d,e]|a,b,c,d,e in set{0,...,1000}&a+b+c+d+e=1000}
```
Set comprehension - 0 loops
] |
[Question]
[
**This question already has answers here**:
[Sierpinski Carpets](/questions/40104/sierpinski-carpets)
(30 answers)
Closed 6 years ago.
## **Challenge**
My challenge, is for you to generate a [Menger Sponge](https://en.wikipedia.org/wiki/Menger_sponge) based on the `level`/`iteration` given. You need to draw it in `3d`, anyway you can.
**Examples**
*Inputs:* `0, 1, 2, 3`
*Outputs:*
[](https://i.stack.imgur.com/X1j26.jpg)
---
## **Background Information**
**What is a Menger Sponge**
>
> In mathematics, the Menger sponge (also known as the Menger universal curve) is a fractal curve. It is a three-dimensional generalization of the Cantor set and Sierpinski carpet
>
>
>
**Properties**
>
> See <https://en.wikipedia.org/wiki/Menger_sponge#Properties> (too long to copy and paste)
>
>
>
**How do I construct the sponge?**
[](https://i.stack.imgur.com/X1j26.jpg)
1. >
> Begin with a cube (first image).
>
>
>
2. >
> Divide every face of the cube into 9 squares, like a Rubik's Cube. This will sub-divide the cube into 27 smaller cubes.
>
>
>
3. >
> Remove the smaller cube in the middle of each face, and remove the smaller cube in the very center of the larger cube, leaving 20 smaller cubes (second image). This is a level-1 Menger sponge (resembling a Void Cube).
>
>
>
4. >
> Repeat steps 2 and 3 for each of the remaining smaller cubes, and continue to iterate ad infinitum.
>
>
>
>
> The second iteration gives a level-2 sponge (third image), the third iteration gives a level-3 sponge (fourth image), and so on. The Menger sponge itself is the limit of this process after an infinite number of iterations.
>
>
>
**Credit**
Background info taken from [this](https://en.wikipedia.org/wiki/Menger_sponge) wikipedia page on Menger Sponges.
---
## **Good Luck!**
Remember this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") the shortest program wins!
[Answer]
anyway.. **here is the 3D answer**
# Mathematica, 15 bytes
```
#~MengerMesh~3&
```
new built-in in Mathematica 11.1
**input**
>
> 3
>
>
>
**output**
[](https://i.stack.imgur.com/bVDwF.png)
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/115609/edit).
Closed 6 years ago.
[Improve this question](/posts/115609/edit)
This question is inspired by [this one](https://codegolf.stackexchange.com/questions/115573/is-this-number-an-exact-power-of-2-very-hard-mode)
# Your task
Make a program or function that calculates the [Tetration](https://en.wikipedia.org/wiki/Tetration) of 2 numbers. Tetration is what "comes next after addition, multiplication, and exponents".
For example, passing in `3` and `3`, this is calculated:
```
3 ^ (3 ^ 3)
```
yielding this:
```
7625597484987
```
Simple, right?
# ***WRONG.***
# Rules
The rules are [taken from this question's inspiration.](https://codegolf.stackexchange.com/questions/115573/is-this-number-an-exact-power-of-2-very-hard-mode)
>
> ## Rules:
>
>
> * An integer is 64 bits, signed, two's complement. This is the *only* data type you may work with.
> * **You may only use the following operations. Each of these counts as one operation.**
> + `n << k`, `n >> k`: Left/right shift `n` by `k` bits. Sign bit is extended in right shift.
> + `n >>> k`: Right shift but do not extend sign bit. 0's are shifted in.
> + `a & b`, `a | b`, `a ^ b`: Bitwise AND, OR, XOR.
> + *[removed]*, `a - b` *[removed]*: *[removed]*, subtract *[removed]*
> + `~b`: Bitwise invert.
> + `-b`: Two's complement negation.
> + `a / b`, `a % b`: Divide (integer quotient, rounds towards 0), and modulo.
>
>
>
* Comparison operators (`<=`, `>=`, `>`, `<`, etc.) are allowed but count as one operation.
>
>
> ```
> - Modulo of negative numbers uses the rules [specified in C99](http://stackoverflow.com/a/11720841/616460): `(a/b) * b + a%b`
>
> ```
>
> shall equal `a`. So `5 % -3` is `2`, and `-5 % 3` is `-2`:
> - `5 / 3` is `1`, `5 % 3` is `2`, as 1 \* 3 + 2 = 5.
> - `-5 / 3` is `-1`, `-5 % 3` is `-2`, as -1 \* 3 + -2 = -5.
> - `5 / -3` is `-1`, `5 % -3` is `2`, as -1 \* -3 + 2 = 5.
> - `-5 / -3` is `1`, `-5 % -3` is `-2`, as 1 \* -3 + -2 = -5.
> - Note that Python's `//` floor division operator does not satisfy the "round towards 0" property of division here.
> - Assignments do not count as an operation. As in C, assignments evaluate to the value of the left-hand side after the assignment: `a =
> (b = a + 5)` sets `b` to `a + 5`, then sets `a` to `b`, and counts as
> one operation.
> - Compound assignments may be used `a += b` means `a = a + b` and count as one operation.
> - You may use integer constants, they do not count as anything.
> - Parentheses to specify order of operations are acceptable.
> - You may declare functions. Function declarations can be in any style that is convenient for you but note that 64 bit integers are the
> *only* valid data type. Function declarations do not count as operations, but a function *call* counts as one. Also, to be clear:
> Functions may contain multiple `return` statements and `return`s from
> any point are allowed. The `return` itself does not count as an
> operation.
> - You may declare variables at no cost.
> - You may use `while` loops, but you may not use `if` or `for`. Operators used in the `while` condition count towards your score.
> `while` loops execute as long as their condition evaluates to a
> *non-zero* value (a "truthy" 0 in languages that have this concept is not a valid outcome). Since early-return is allowed, you are allowed
> to use `break` as well
> - Overflow/underflow is allowed and no value clamping will be done. It is treated as if the operation actually happened correctly and was
> then truncated to 64 bits.
>
>
> ## Scoring / Winning Criteria:
>
>
>
...
>
> This is [atomic-code-golf](/questions/tagged/atomic-code-golf "show questions tagged 'atomic-code-golf'"). Your score is the total number of
> operations present in your code (as defined above), *not* the total
> number of operations that are executed at run-time. The following
> code:
>
>
>
> ```
> function example (a, b) {
> return a + ~b;
> }
>
> function ispowerofnegtwo (input) {
> y = example(input, 9);
> y = example(y, 42);
> y = example(y, 98);
> return y;
> }
>
> ```
>
> Contains 5 operations: two in the function, and three function calls.
>
>
> It doesn't matter how you present your result, use whatever is
> convenient in your language, be it ultimately storing the result in a
> variable, returning it from a function, or whatever.
>
>
> The winner is the post that is demonstrably correct (supply a casual
> or formal proof if necessary) and has the lowest score as described
> above.
>
>
> Note: If you'd like to provide a solution in a language that only
> supports 32-bit integers, you may do so, provided that you
> sufficiently justify that it will still be correct for 64-bit integers
> in an explanation.
>
>
> Also: *Certain* language-specific features may be permitted at no-cost
> *if they do not evade the rules but are necessary to coerce your language into behaving according to the rules above*. For example
> (contrived), I will permit a free *not equals 0* comparison in `while`
> loops, when applied to the condition as a whole, as a workaround for a
> language that has "truthy" 0's. *Clear attempts to take advantage of
> these types of things are not allowed* -- e.g. the concept of "truthy"
> 0 or "undefined" values does not exist in the above ruleset, and so
> they may not be relied on.
>
>
>
`break`s are allowed, but they count as an operation.
Also, if your language has no concept of 64-bit ints, you may use any other form of number.
# **Note that you are not allowed to use multiplication, exponentiation, or addition.**
[Answer]
## Ruby, 13 operations
```
def tetr(a, b)
def exp(a, b)
def mult(a, b)
c = 0; i = 0; while(i > -b) do c -= a; i -= 1; end
return -c
end
c = 1; i = 0; while(i > -b) do c = mult(c, a); i -= 1; end
return c
end
c = a; i = -1; while(i > -b) do c = exp(a, c); i -= 1; end
return c
end
```
OP has stated that comparison is allowed.
[Answer]
# [Wise](https://github.com/Wheatwizard/Wise), ~~31~~ 29
```
:::[:^|>::>^]|[:^?-!]^
::^? [::><^[-~!~-?]^>?->!]^
!:-~[:^&:]^?-&
```
When I saw this question I thought it would be the perfect question to answer in Wise. The way Wise is set up it is impossible to make an answer that does not qualify for this challenge because all of Wise's operations are bitwise.
* `:`, `!`, and `?` are all stack operations which I am considering to be variable assignments so they do not count towards the score
* `[]` constitute a while loop so they don't count towards the score.
* `^`,`|`, and `&` are bitwise XOR, OR, and AND respectively
* `>`,`<` are the bitshifts,
* `~` is bitwise negation and `-` is regular negation.
### Explanation
First we want to take the absolute value of the number so that we can check if the number is a power of 2.
```
:[:^|>::>^]|
```
is a program I wrote a while ago to get the sign bit of a number.
[:^?-!]^
will negate the number if the top of the stack is `-1`, that is if our input was negative.
Now that we have a positive number we want to check if it is a power of 2. to do this we take the sum of the digits (in base 2) and check if it is one. To do that we set up a zero on the bottom of the stack:
```
::^?
```
and loop through adding the last digit and dividing by 2 (bit-shifting once)
```
[::><^[-~!~-?]^>?-!]^!
```
While we are doing this we divide a copy of our original input by `-2` (`->`) each time we loop. If the result `-1` and the absolute value of the input was a power of `2` it is a power of `-2`.
Now we subtract one `-~` and take the logical not of the digit sum.
```
[:^&:]^
```
We roll this result to the bottom with `?` and finish up with a logical and with `-&`
] |
[Question]
[
If you're like me (and/or use Windows), You should have found this issue quite disturbing.
You plug in a hard drive (2TB for my occasion), and realize it doesn't show as 2TB, but a bit smaller size which is clearly not 2TB.
Over some research, I found it was because of Microsoft's mistake. Mistyping [Binary prefix](https://en.m.wikipedia.org/wiki/Binary_prefix) as Decimal prefixes. (i.e. They typed 1TiB as 1TB)
So, I would like to see a Binary prefix to Decimal prefix program. Since this is a big problem (and some computers are literally toasters), You have to make your program as short as possible.
[conversion chart I found](http://www.smartconversion.com/unit_conversion/prefix_conversion_table.aspx)
---
# I/O
You will be given the size (positive real number, will not exceed 2ÀÜ16 when converted), and the unit (4 of them, KiB, MiB, GiB and TiB, each corresponds to 1024ÀÜ1, 1024ÀÜ2, 1024ÀÜ3 and 1024ÀÜ4 bytes)
You have to output the (decimal representation of) the size (rounded half-up to integer value), and the corresponding unit.
---
# Examples
```
678 MiB => 711 MB
1.8 TiB => 2 TB
```
**Tip: Google has a unit converter**
[Answer]
# Python 3.6, ~~78~~ 77 bytes
```
a,b=input().split()
print(f'{eval(a)*1.024**" KMGT".find(b[0]):.0f} {b[0]}B')
```
[Answer]
# Pyth, ~~27~~ ~~25~~ 35 Bytes
```
=H@z_3s[.E*v<4z^1.024x" KMGT"HdH\B
```
Adding the unit to the output costed me quite some bytes.
[Try it!](https://pyth.herokuapp.com/?code=%3DH%40z_3s%5B.E%2av%3C4z%5E1.024x%22+KMGT%22HdH%5CB&input=1.8+TiB&test_suite_input=678+MiB%0A1.8+TiB&debug=0)
[Answer]
# PHP, 63 bytes
```
<?=1.024**strpos(_KMGT,($m=$argv[2][0]))*$argv[1]+.5|0," $m",B;
```
takes input from command line arguments;
run with `echo '<code>' | php -n` or save to file and run with `php -n <filename>`.
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 26 bytes
Prompts for unit and size, and outputs unit and size.
```
⌊.5+⎕×1.024*'KMGT'⍳⊃⎕←⍞∩⎕A
```
[Try it online!](https://tio.run/nexus/apl-dyalog#e9TRnvb/UU@Xnqn2o76ph6cb6hkYmWipe/u6h6g/6t38qKsZKPyobcKj3nmPOlYC2Y7/H3W0/0/j8s104jIzt@BK4woBsgz1LAA "APL (Dyalog Unicode) – TIO Nexus")
`‚à©‚éïA` intersection with uppercase **A**lphabet of
`‚çû` character input (unit) from STDIN
`⎕←` output that to STDOUT
`⊃` get the first character of the outputted value
`'KMGT'‚ç≥` find the 1-based index of that in this string
`1.024*` raise this number that that power
`‚éï√ó` multiply numeric input from STDIN with that
`.5+` add a half to that
`‚åä` round that down
[Answer]
## JavaScript (ES6), 71 bytes
```
f=
(s,[n,[u]]=s.split` `)=>(n*1.024**` KMGT`.search(u)).toFixed()+` ${u}B`
```
```
<input oninput=o.textContent=/\s[KMGT]/.test(this.value)?f(this.value):``><span id=o>
```
[Answer]
# Mathematica, ~~44~~ 43 bytes
It has a built-in function for everything üòê
```
Round@UnitConvert[#,StringPart[#,-3]<>"B"]&
```
(Input should be a string `"678 MiB"`.)
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/105499/edit).
Closed 7 years ago.
[Improve this question](/posts/105499/edit)
# Introduction
The well-known "Die Hard with a Vengeance" water jugs puzzle challenges the two heroes to get 4L of water in a 5L container, provided an unlimited supply of water and another container of 3L. This problem has a solution because `4` is less or equal than the largest container and is a multiple of the `gcd(5, 3) = 1` as per number theory. The same goes for other combinations of container sizes as long as the Greatest Common Divisor (GCD) requirements are satisfied for a target value.
# Task
In one sentence, the task is to brute-force **two solutions** by filling and emptying two containers as well as transferring amounts between one another for any given container sizes and target value. The brute-force lies on repeatedly transferring amounts from one container to another, refilling the first when it runs out and emptying the second when it fills up, until any of them contain the target value.
The program should make two runs to respectively find two solutions by swapping container positions (*i.e.*, the container receiving water from the other swaps with that one). The container states should be printed throughout all steps (refilling or emptying and transferring water).
This is code golf, so lowest byte count wins.
# Examples
Examples follow below for `(5, 3, 4)` and `(17, 5, 7)` with `4` and `7` being the target values. Comments added for description purposes.
```
5 3 4
[5, 0] # initial state
[2, 3] # transferring
[2, 0] # emptying
[0, 2] # transferring
[5, 2] # refilling
[4, 3] # transferring, solution found
3 5 4
[3, 0]
[0, 3]
[3, 3]
[1, 5]
[1, 0]
[0, 1]
[3, 1]
[0, 4]
17 5 7
[17, 0] # initial state
[12, 5] # transferring
[12, 0] # emptying
[7, 5] # transferring, solution found
5 17 7
[5, 0]
[0, 5]
[5, 5]
[0, 10]
[5, 10]
[0, 15]
[5, 15]
[3, 17]
[3, 0]
[0, 3]
[5, 3]
[0, 8]
[5, 8]
[0, 13]
[5, 13]
[1, 17]
[1, 0]
[0, 1]
[5, 1]
[0, 6]
[5, 6]
[0, 11]
[5, 11]
[0, 16]
[5, 16]
[4, 17]
[4, 0]
[0, 4]
[5, 4]
[0, 9]
[5, 9]
[0, 14]
[5, 14]
[2, 17]
[2, 0]
[0, 2]
[5, 2]
[0, 7]
```
[Answer]
## Batch, 218 bytes
```
@echo off
set/al=r=0
:l
echo %l% %r%
set/at=r+l
if %l% neq %3 if %r% neq %3 ((if %r%==%2 (set r=0)else if %l%==0 (set l=%1)else if %t% leq %2 (set/ar=t,l=0)else set/ar=%2,l=t-%2)&goto l)
if "%4"=="" %0 %2 %1 %3 .
```
Putting everything into one big `if` statement saves 11 bytes. `%4` is just used to make the file loop twice with the arguments exchanged.
[Answer]
# Python 2 - ~~222/384~~, ~~190~~ 174/~~360 352~~ 336 Bytes
This version that only outputs the solution is **174 bytes**.
```
a,b,c=input()
d,e=0,0
for i in range(2):
while d!=c and e!=c:
if e<b:
if d>0:
if e+d<=b:e+=d;d=0
else:n=d+e-b;e=b;d=n
else:d=a
else:e=0
print d,e
b,a,d,e=a,b,0,0
```
[Try it here!](https://repl.it/FAH4/3)
**Example Output:**
[](https://i.stack.imgur.com/2Jrn0.png)
**Explanation:**
```
a,b,c=input() # Value of jug 1, jug 2, target value
d,e=0,0 # Water held in each jug
for i in range(2): # Loop twice
while d!=c and e!=c: # While no solution
if e<b: # If jug 2 can hold more water
if d!=0: # If jug 1 has water
if e+d<=b:e+=d;d=0 # If no overfill, pour all of jug 1 into 2
else:n=d+e-b;e=b;d=n # Else fill up as much as possible
else:d=a # Else jug 1 has no water, fill it
else:e=0 # Else jug 2 is full, empty it
print d,e # Print solution
b,a,d,e=a,b,0,0 # Switch the two jugs' values, empty all jugs
```
It implements this [algorithm](http://chat.stackexchange.com/transcript/message/34527453#34527453). With the new edit, the code becomes **326 bytes**:
```
a,b,c=input(),input(),input()
d,e=0,0
g=[d,e]
for i in"xx":
while d!=c and e!=c:
g=[d,e]
if e<b:
if d!=0:
if e+d<=b:e+=d;d=0;print"Transferring Water"
else:n=d+e-b;e=b;d=n;print"Transferring Water"
else:d=a;print"Filling Water"
else:e=0;print"Emptying Water"
print g
print[d,e],"Solution Found"
b,a,d,e=a,b,0,0;print"Resetting"
```
[Try this version here](https://repl.it/FAH4/4)
**Explanation and Output**
Explanation is the same except with text and `g` is used to output the values of the two jugs and final solution. Output:
[](https://i.stack.imgur.com/xOJOA.png)
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/79898/edit).
Closed 7 years ago.
[Improve this question](/posts/79898/edit)
Inspired by [this site,](http://needsmorejquery.com/ "Needs More jQuery") this question could potentially be a doozie. People on StackOverflow often overuse jQuery as an answer. Therefore, we need a way to recognize programmatically if a code snippet uses jQuery.
Given a string (which may or may not contain new lines,) of valid Javascript, determine if jQuery is used.
You determine if jQuery is used if the `$` or `jQuery` functions are called.
**Input quirks:**
* Input will always be valid Javascript.
* Input can contain new lines.
* Input can omit a semicolon where it would automatically be inserted
* There will always be only one argument to the jQuery function.
* Dollar signs could exist elsewhere (strings, comments) so be careful.
* No base64 conversion functions will/can be used in input.
* No `eval` will/can be used in input.
* Any referenced variable or function can be assumed to be defined, but will be guaranteed not to produce errors.
* Code snippets will always produce either a truthy or a falsey value, there will be no ambiguous code.
* Comments can exist in either form.
**Rules:**
* No Standard Loopholes
* This is code-golf, the shortest answer wins.
* You must write a program or a function that takes a string as input and returns a truthy value if it uses jQuery, and a falsey value if it does not.
* If someone can provide a valid input that breaks your code or causes it to return an incorrect value, it is not a winning answer.
**Example Test cases:**
*include, but are not limited to:*
```
$('div') // true
console.log("$5.99"); // false
$ += 3; // false, the `$` variable clearly has a different value type here
var a = "span" /* this is a comment */
$(a).each(function(){
jQuery(this);
}); // true
```
Good luck, and remember, everything's better with a little extra jQuery!
[Answer]
# Javascript - 52 byte \* .9 \* .8 = 37.44
Don't know how valid this is, because it redefines `$` and `jQuery` and evals the input to check if it was called.
```
(x)=>{$=jQuery=()=>alert(1)&3();eval(x+";alert(0)")}
```
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/57721/edit).
Closed 8 years ago.
[Improve this question](/posts/57721/edit)
# Challenge
Write the shortest program that receives two signed integers `n` and `i` and for each `i` between 1 and `2^n - 1` returns the next ordered permutation based on the binary representation of the number. There is no specific order of the combinations but the number of 1s in the binary representation must always stay the same or grow and numbers each output may happen only once
# Clarification
The goal of this program is to generate all the combinations without repetitions of a set. To do so you may consider that each item is represented by a bit in a bit mask, that way if you have three items, A, B and C represented by 001, 010 and 100 respectively the combinations ABC, ACB, BCA, BAC, CAB and CBA are all represented as 111.
For increasing values of `i` your program should output a new combinations always with the same number of elements or more.
# Input
You may read the input in the format
>
> `n i`
>
>
>
or just use `n` and `i` variables, whichever suits you best.
# Output
You may output a single number `k`
# Sample cases
Each test case is two lines, input followed by output with a binary representation here for demonstration purposes:
```
3 1
1 (001)
3 2
4 (100)
3 3
2 (010)
3 4
6 (110)
3 7
7 (111)
```
# Rules
* Shortest code wins (bytes)
* The result can be returned by a function or printed by your program.
* You may assume `n` and `i` variables already exist, there's no need to handle input if you don't want to.
* The answers with the same number of `1` bits can be output in any order
* The input is guaranteed to be well formed and `1 <= i <= 2^n - 1`.
Happy Golfing!
[Answer]
## Ruby, 72 bytes
```
p [0,1].repeated_permutation(n).sort_by{|x|x.count 1}[i].join('').to_i 2
```
How it works:
```
irb(main):001:0> [0, 1].repeated_permutation(3).to_a # generate permutations
=> [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1],
[1, 1, 0], [1, 1, 1]]
irb(main):002:0> _.sort_by {|x| x.count 1 } # sort by number of 1's
=> [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 1], [1, 0, 1],
[1, 1, 0], [1, 1, 1]]
irb(main):003:0> _[2].join '' # convert array of binary digits to string
=> "010"
irb(main):004:0> _.to_i 2 # interpret string as binary number
=> 2
```
[Answer]
# Pyth, 13 bytes
```
i@o/N1^U2vzQ2
```
Just constructs a cartesian power of `[0, 1]`, sorts it by number of `1`s, and indexes before converting to base10.
] |
[Question]
[
**This question already has answers here**:
[ROT-13 transform standard input](/questions/4/rot-13-transform-standard-input)
(69 answers)
Closed 10 years ago.
[This kind of question has been asked before](https://codegolf.stackexchange.com/questions/4/rot-13-transform-standard-input), but I wanted to make it more specific. The linked question asks to read from stdin and rot13 the input. I don't want the disadvantage of I/O code that differs a lot for each language in length.
The challenge:
>
> Write a function that will [ROT13 (wiki link)](http://en.wikipedia.org/wiki/ROT13) one char (as defined by the ASCII table).
>
> **No built-in ROT13 functionality allowed.**
>
>
>
Shortest code wins.
---
You can use this kind of C-family loop to test your function:
```
for (int i = '!'; i <= '~'; ++i)
{
char c = (char) i;
System.out.println(c + " -> " + f(c));
}
```
[Answer]
**C (~~77~~ 64 chars)**
~~`char f(char c){return(c>64&&c<91)?65+(c-52)%26:(c>96&&c<123)?97+(c-84)%26:c;}`~~
```
char f(char c){return(isalpha(c))?65+(c&32)+(c-52-(c&32))%26:c;}
```
[Answer]
I came up with this in **Java (81 chars)**:
```
char f(char c){return Character.isLetter(c)?(char)((((c&95)-52)%26+65)|c&32):c;}
```
Demo here: <http://ideone.com/ItT7IM>
] |
[Question]
[
Write the shortest code that implements a:
1. [DFA](http://en.wikipedia.org/wiki/Deterministic_finite_automaton)
2. [NFA](http://en.wikipedia.org/wiki/Nondeterministic_finite_automaton)
3. [epsilon-NFA](http://en.wikipedia.org/wiki/Nondeterministic_finite_automaton_with_%CE%B5-moves)
The program should accept as input:
* a string(that we want to see if is accepted or not)
* the delta function, represented in whichever way it's more convenient.
* the "set" of final states of the automaton
And it should output `Accepted!` if the string is accepted by the automaton, and the string `Not a chance!` otherwise.
Note that all inputs should be taken from stdin or the command line.
The total points should be computed as `(L1 + 2*L2 + 3*L3) / 6` where `Li` is the length, in bytes, of the code solving point `i` and the winner will be the answer with *smallest* score.
---
**Edit:** You can assume the starting state, so that it is *not* required as input.
The epsilon transitions can be labelled in any way you want.
---
**Edit2:** An example of input for the DFA:
```
0100
{'q_0': {'0': 'q_1', '1': 'q_0'}, 'q_1': {'0': 'q_2', '1': 'q_3'}, 'q_2': {'0': 'q_2', '1': 'q_3'}, 'q_3': {'1': 'q_0', '0': 'q_1'}}
{'q_2', 'q_3'}
```
Output:
```
Accepted!
```
An other input:
```
010010
{'q_0': {'0': 'q_1', '1': 'q_0'}, 'q_1': {'0': 'q_2', '1': 'q_3'}, 'q_2': {'0': 'q_2', '1': 'q_3'}, 'q_3': {'1': 'q_0', '0': 'q_1'}}
{'q_2', 'q_3'}
```
Output:
```
Not a chance!
```
I want to stress that you are free to use a different formatting for the inputs. Choose the simpler to "parse" in your target language. The above is simple to use in python since you can `eval` it to obtain the real objects.
[Answer]
## Python, score = 138 1/6 = (79+108\*2+178\*3)/6
## DFA
```
S,D,F=input()
s=1
for c in S:s=D[s,c]
print["Not a chance!","Accepted!"][F&s>0]
```
Input is a triple of string `S`, a delta function `D`, and final state mask `F`. I number each state with a power of 2, so `F` is just the OR of each accepting state. `D` is a map from (state,input char)->state.
example input (accepts all strings ending in `b`):
```
'abab',{(1,'a'):1,(1,'b'):2,(2,'a'):1,(2,'b'):2},2
```
## NFA
```
S,D,F=input()
s=1
for c in S:
t,s=s,0
for a,b in D[c]:s|=t/a%2*b
print["Not a chance!","Accepted!"][F&s>0]
```
We number states as powers of 2 as before. `D` is a map from input character to a list of transitions labeled by that character.
example input (accepts all strings ending in `b`):
```
'abab',{'a':[(1,1)],'b':[(1,1),(1,2)]},2
```
## epsilon-NFA
```
S,D,F=input()
E={1:1}
for i in D[0]:
for a,b in D[0]:E[a]=a|E.get(b,b)
s=E[1]
for c in S:
t,s=s,0
for a,b in D[c]:s|=t/a%2*E.get(b,b)
print["Not a chance!","Accepted!"][F&s>0]
```
Same as `NFA`, but with the additional `0` character listing the epsilon transitions.
example input (accepts all strings ending in `b`):
```
'abab',{'a':[(1,1)],'b':[(1,1),(1,2)],0:[(2,4)]},2
```
] |
[Question]
[
Write a program that takes a string as input and modifies it by reversing the string in its place by mirroring the position. The first position goes to last, second to second last and so it goes on. In simple words, the string would be mirrored.
"In Place" means the program should use \$O(1)\$ additional memory regardless of the length of the string
## Test Cases
Input: `"Hello, World!"`
Output: `"!dlroW ,olleH"`
Input: `"Hello"`
Output: `"olleH"`
Input: `"A man a plan a canal Panama"`
Output: `"amanaP lanac a nalp a nam A"`
Input: `"123456789"`
Output: `"987654321"`
Input: `""`
Output: `""`
[Answer]
# x86 assembly (Linux) - ~~42~~ 26 bytes
`F6 D6 29 D4 B0 03 89 E1 CD 80 01 C1 43 89 DA 49 39 E1 7C 06 B0 04 CD 80 EB F5`
This is my first Assembly program. Reads from stdin, then outputs to stdout in reverse order. **[Try it online.](https://ideone.com/pXjYH0)**
```
not dh ; sys_read count = edx = 65280
sub esp,edx ; allocate 65280 bytes on stack
mov al,3 ; 0x03 = "read" syscall
mov ecx,esp ; sys_read buf = ecx = stack pointer
int 0x80 ; eax = sys_read(stdin, esp, 65280)
add ecx,eax ; add read bytes to stack pointer
inc ebx ; sys_write fd = 1 = stdout
mov edx,ebx ; sys_write count = 1
reverse:
dec ecx ;
cmp ecx,esp ; check if we've gone too far
jl done ;
mov al,4 ; 0x04 = "write" syscall
int 0x80 ; eax = sys_write(stdout, ecx, 1)
jmp reverse
done:
```
Disassembly
```
0: f6 d6 not dh
2: 29 d4 sub esp,edx
4: b0 03 mov al,0x3
6: 89 e1 mov ecx,esp
8: cd 80 int 0x80
a: 01 c1 add ecx,eax
c: 43 inc ebx
d: 89 da mov edx,ebx
0000000f <reverse>:
f: 49 dec ecx
10: 39 e1 cmp ecx,esp
12: 7c 06 jl 1a <done>
14: b0 04 mov al,0x4
16: cd 80 int 0x80
18: eb f5 jmp f <reverse>
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~139~~ ~~134~~ 132 bytes
```
#define C strlen(a[1])
main(int n,char**a){for(n=0;n<C/2;){*(a[1]+n)^=**a=*(a[1]+n)^*(a[1]+C-n-1);*(a[1]+C-n++-1)^=**a;}puts(a[1]);}
```
[Try it online!](https://tio.run/##RY3BCgIhGITvPcUPXdRNaruah/AFukfBj7kl6N/i2mnZZzexYC8z8zEDY@XT2lK2Dzd4cmBgyik4Ynjtb3wT0RPzlIF29oVJCOTz8E6M9EHRyeyPis@ibTvid117veI/GUmy52qlrqvcxmoZP3n6famllHKGiAQIY2hmkTDApWrELw "C (gcc) – Try It Online")
Thanks for the "you can use `puts` suggestion from Neil that saved 2 bytes...
OK, assuming I understand the goal (which is big assumption), I think this one does the right thing... It reverses the string passed as the first commandline argument, then prints it. No additional storage is allocated to effect the reversal.
It works by XOR'ing each character of the string with the one it should be swapped with, then XOR'ing that composite value with each of the original characters. The temporary storage needed to complete the work are a `char` for holding the XOR composite, and an `int` string offset. The code overloads variables the compiler created for other purposes to avoid allocating additional memory for those temporary variables.
```
#define C strlen(a[1]) - just a shortcut to save space
main(int n,char**a){ ... } - standard "this is a C program" stuff
for(n=0;n<C/2;){ ... } - loop C/2 times (half the length of the string)
**a=*(a[1]+n)^*(a[1]+C-n-1); - set "*a[0]" to a composite of current swap chars
*(a[1]+n)^=**a... - use composite to swap first char (w/ XOR)
*(a[1]+C-n++-1)^=**a; - and repeat with the second char, increment "n"
puts(a[1]); - output the reversed string
```
If the rules allow for temporary variables, this could be shorter.
[Answer]
# [Factor](https://factorcode.org/), 8 bytes
```
reverse!
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqVQnFpYmpqXnFqsUFCUWlJSWVCUmVeiYM3FVa2g5JGak5OvoxCeX5SToqgE5QNpR4XcxDyFRIWCHDCVnJiXmKMQACRzE4GyhkbGJqZm5haWQLaSQi1X9P@i1LLUouJUxf@xQI0FCnr/AQ "Factor – Try It Online")
Builtin.
The documentation (and source code) for [reverse!](https://docs.factorcode.org/content/word-reverse!,sequences.html) corroborates its O(1) additional memory usage beyond the string itself.
[Answer]
# [Perl 5](https://www.perl.org/), 57 bytes
```
for$l(0...5*length){s/.{$l}\K(.)(.*)(.)(.{$l})/$3$2$1$4/}
```
[Try it online!](https://tio.run/##RYw9C8IwGIT3/IpXGrAVTfyqH4ODm@Di5iJI1Ldt5G1SkiiI@NeN1cXlnrvjuAYd5TEW1nFKh0KIvEdoylBlTy/Fk9PrsE1Flope9sO3ySSf8DEf8al8xYQfV1erTbfbd3hH51EKWbKkvdIefGVdQAenB6hCtbwFqHVZBRPghKBNQ@r8ADT2VlZxg0S2D3vr6NJhv8TWUCsDCtrhF2dlFMGu1Vqx0XgyzWfzxZIN//Ztm6Ct8XHQfAA "Perl 5 – Try It Online")
[Answer]
# JavaScript, 14 bytes
```
s=>s.reverse()
```
Try it:
```
f=s=>s.reverse()
;[
'Hello, World!',
'Hello',
'A man a plan a canal Panama',
'123456789',
''
].forEach(s=>console.log(f([...s]).join``))
```
] |
[Question]
[
**This question already has answers here**:
[Generate a Markdown Template for your Post](/questions/98812/generate-a-markdown-template-for-your-post)
(9 answers)
Closed 3 years ago.
# Task
Your task is to write a program that, taking no input, outputs a string that represents a formatted codegolf answer of itself. The pattern is the following:
```
[Language name][1], n bytes
=
```
source code
```
[1]: link-to-language
```
With the `language name` being the language that you wrote your program (as stated in your interpreter no abbreviations such as JavaScript => JS), `n` bytes being the byte-count of your language, `source code` being the source code of your program (hence the quine tag) and `link-to-language` being a link to a resource about your language - whichever your online interpreter points to. Note that this is a real quine challenge, so answers cannot read their own source code.
[Answer]
## [Python 2](https://docs.python.org/2), 102 bytes
```
_='## [Python 2][1], 102 bytes\n```\n_=%r;print _%%_\n```\n [1]: https://docs.python.org/2';print _%_
```
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/197563/edit).
Closed 4 years ago.
[Improve this question](/posts/197563/edit)
# Introduction
Your job is to write a function or program that detects if a number `a` is less than a number `b`.
**But...** You are not allowed to use built-in alternatives for equals, less than, greater than, less than or equal to, greater than or equal to, or not equal to operators. (Writing your own implementation is allowed.) Similar alternative methods/alternatives in other languages that are designed to replace those operations are also restricted.
You **are** allowed to use operators that are not banned, e.g. bitwise operators and the not operator (but it would be better if your answer did not have the not operator).
# Challenge
Simply return a truthy or falsy value (or something that evaluates in the language to true or false like 0 or 1) to indicate whether `a` is less than `b`. The winner of the challenge can be determined by the shortest code. External sources are not allowed, but anonymous functions are. Explaining your answer is not mandatory, but encouraged.
# Example using Javascript:
```
(a,b)=>!!Math.max(0,b-a) //remove the !! for truthy and falsy numbers
/*Explanation
(a,b) Parameters a and b
=> Function is
!! returns true if truthy and false if falsy
Math.max(0,b-a) returns the greater number, 0 or b-a
*/
```
# Examples of Input and Output
```
Input | Output
------|-------
1, 3 | true
2, 2 | false
3, 2 | false
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 2 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous tacit prefix function. Requires `⎕IO←0`
```
⊃⍒
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/x91NT/qnfQ/Dch51NsHEe9qPrTe@FHbRCAvOMgZSIZ4eAb/T1MwVDDmSlMwUjACksYKRgA "APL (Dyalog Unicode) – Try It Online")
`⍒` gives the "grade". The indices into the argument that would stably sort it in descending order
* If the first element is less than the second, it gives `[1,0]`
* If the the elements are equal, it gives `[0,1]`
* If the second element is less than the second, it gives `[0,1]`
`⊃` picks the first element of that
* If the first element is less than the second, it gives `1`
* If the the elements are equal, it gives `0`
* If the second element is less than the second, it gives `0`
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/186837/edit).
Closed 4 years ago.
[Improve this question](/posts/186837/edit)
In the board game Pandemic, an **outbreak** occurs when a city contains more than 3 disease cubes. When the outbreak occurs, any disease cubes in the city in excess of 3 are removed, and each city connected to it gains one disease cube. This means that chain reactions can, and will occur.
**Important note: Each city may only outbreak once in each chain reaction.**
## Input
A list of cities each containing:
* An integer representing the number of disease cubes .
* And a number of identifiers of the form (A, B ... AA, AB) (lowercase is allowed) representing which cites in list order it is connected to.
## Output
A list of integers representing the number of disease cubes in each city after outbreaks have been resolved.
## Winning Condition
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins.
[Answer]
# [Python 3](https://docs.python.org/3/), 201 bytes
```
f=lambda d,e,v=[],n=enumerate:any((D>3)>(i in v)for i,D in n(d))and f([(i in v)and D or(min(3,D)+sum((k not in v)*(d[k]>3)for k in E))for i,(D,E) in n(zip(d,e))],e,v+[i for i,D in n(d)if D>3])or sum(d)
```
[Try it online!](https://tio.run/##XY6xDoMwDER/xaNdPJTSqRJM4SuiDKkCakQxKAUk@vM0EVSVOtl3tt7duE6PQYpta8un7e/OguOGl1IblrKRuW@CnZqblRVRVQVV6MELLNQOATyrJAQdkRUHLervOUkFQ8DeCxasKHvNPWIHMkz7xwmd7kxEJlKXvJoOKiquaSe//YixEZFJtTLt4S/YtxB7GYpuSnC0jcHLhLHLlaFguBgGrfNjOf9mbgzR9gE "Python 3 – Try It Online")
Worst case O(n) on the number of cities. `d` is a list of disease counts, `e` is a list of city connections by `0`-indexed position corresponding to `d`, and `v` is the visited array (which should not be given as input, obviously).
For the case `[4, 3, 2]` with connections `0 <-> 1`, `1 <-> 2`, and `0 <-> 2`, first, city `0` outbreaks and becomes `3` and sets city `1` to `4` and city `2` to `3`. Then, city `1` outbreaks and becomes `3` and sets city `2` to `4` (city `0` already had an outbreak). Finally, city `2` has an outbreak and nothing can be affected, leaving all three cities on `3` disease cubes, totalling `9`.
] |
[Question]
[
**This question already has answers here**:
[Decipher a Vigenère ciphertext](/questions/678/decipher-a-vigen%c3%a8re-ciphertext)
(20 answers)
Closed 6 years ago.
Your task:
Create a program that encrypts a string with another string using a key, using
the vigenere cipher.
What a vigenere cipher does
```
Ciphertext: string
Key: keya
| |
v v
string
keyake
|
v
(18)(19)(17)(08)(13)(06)
(10)(04)(24)(00)(10)(04)
|
v
(28)(23)(41)(08)(23)(10)
|
v
cxpixk
```
If it still isn't clear, read [here.](http://www.dcode.fr/vigenere-cipher)
Rules: No built-ins, shortest code in bytes wins, input and output will/should always be either completely lowercase, or completely uppercase.
```
string, keya -> cxpixk
aaaaaaaaaaaaaaaaaaaaaaaa,abcdefghijklmnopqrstuvwxyz -> abcdefghijklmnopqrstuvwxyz
vigenere, cipher -> xqvlrvtm
short, longkey -> dvbxd
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
2 bytes thanks to Dennis.
```
ṁ⁹,OS‘ịØA
```
[Try it online!](https://tio.run/##AScA2P9qZWxsef//4bmB4oG5LE9T4oCY4buLw5hB////S0VZQf9TVFJJTkc "Jelly – Try It Online")
## How it works
```
ṁ⁹,OS‘ịØA arguments: "KEYA", "STRING"
ṁ⁹ reshape "KEYAKE"
, pair ["KEYAKE","STRING"]
O codepoint [[75,69,89,65,75,69],[83,84,82,73,78,71]]
S sum [158,153,171,138,153,140]
‘ add 1 [159,154,172,139,154,141]
ịØA index ØA "CXPIXK"
where ØA is "ABCDEFGHIJKLMNOPSRQTUVWXYZ"
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 18 bytes
```
ạᵐz{+-₁₂%₂₆;Ạ∋₍}ᵐc
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//@GuhQ@3Tqiq1tZ91NT4qKlJFYgfNbVZP9y14FFH96Om3lqgdPL//9FK2amViUo6SsUlRZl56Uqx/6MA "Brachylog – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 114 bytes
```
l=letters
i=match
s=strsplit
function(m,k)cat(l[(i(s(m,'')[[1]],l)+i(s(k,'')[[1]],l)-2)%%26+1][1:nchar(m)],sep='')
```
Returns a function that takes the message and the key and prints the result to stdout. Will explain later (on mobile now)
[Try it online!](https://tio.run/##TY0xDsMgDEV37hEZFDokQ4dKnIQyIEQSFEMicIeenpqtm/3et3/tHQ1GolibSCZ7CodoplFtNyYSm9k@JVC6isz6VMGTRCuTbLwCKGsX5zSqeZDznzxWNU3rc16cXV4lHL7KrJxu8Tac6psE7khlBw1n/HpQYvyGd@FpyOOqxA6vsrPnix8 "R – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 15 bytes
```
s.e@GsxLG,@QkbE
```
[Try it online!](http://pyth.herokuapp.com/?code=s.e%40GsxLG%2C%40QkbE&input=%22keya%22%0A%22string%22&debug=0)
[Answer]
# [Python 3](https://docs.python.org/3/), ~~75~~ 73 bytes
*-2 bytes thanks to @LeakyNun*
```
f=lambda a,b:a and chr((ord(a[0])+ord(b[0])+1)%26+64)+f(a[1:],b[1:]+b[0])
```
[Try it online!](https://tio.run/##dU5BbsMgELz7FSukSiCjqkmrHCzlJRYHsBdD4wABksb5vAOOcuwcRrszs9oJSzbefa@rPs7yrEYJkquusBthMJFSH0cq@y/B2jqpbdqxj/2hPfywVhdv1wmuKrebu2ZMOcER@p6kHK2bCCcnXCQRHHoi/0EJSTWMqCdjf0/z2flwiSlfb3/35fE6vdkJHUYkHMhgg8H40pPxMVdx9m4qn4gQTaN9hIz3zKEoYB1stboGKkKplammNfB5DQEjZVvwvTC2PgE "Python 3 – Try It Online")
Takes input in uppercase
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/117981/edit).
Closed 6 years ago.
[Improve this question](/posts/117981/edit)
# What I want:
Take an input, *x*
Take a formula. It has to be capable of reading something in the format:
* ax^m + bx^n + cx^o ... where m, n, o and any terms after that can represent any value.
* coefficients, again for any number. For example, 6x^2. (That means 6(x^2))
* Doesn't necessarily have to put up with spaces
* times, divide, plus and minus
* brackets - up to stacking of *5*
* ANY negative numbers
* fractions
* To the power of *x* , these can be integeric (<-- is not a word, but that is the best word I can make up!)
* If x = 5, you can put -x to get -5 and -x^2 is -(x^2). You could use (-x)^2
After it interprets the formula, it has to plug *x* into the function, then output the value.
## The Challenge:
* Do it in as less bytes as possible
* The lowest number of bytes wins!
### Note: I feel that I have included everything here, but if I haven't please comment below, and I will answer it within the next 30 minutes!
# Example
Key:
bp = Background Process
* Give me an input, (x)
4
* Give me a formula:
2^x
* (bp) So I have to do 2 to the power of x, which is 2^4, which is 16
* Output: 16
[Answer]
# TI BASIC, 6 bytes
This might change, since the rules are still not totally stable, but I wanted to post this while I could.
```
:Prompt X,F
:F
```
Asks for `X`, then parses whatever formula is put into `F` and displays it.
If I could assume that `X` was already stored in the memory, it would be
# ~~TI BASIC (maybe), 0 bytes~~
~~Is this ok?~~Guess not. :-(
] |
[Question]
[
**This question already has answers here**:
[Integer mark into grade](/questions/49876/integer-mark-into-grade)
(26 answers)
Closed 7 years ago.
Write a program or a function in your favorite programming language that will take as input a number `n` (integer or non-integer) between `0` and `100` inclusive, and output the corresponding grade as outlined below:
* If `0 < n <= 40`, then output `E`.
* If `40 < n <= 55`, then output `D`.
* If `55 < n <= 65`, then output `C`.
* If `65 < n <= 70`, then output `C+`.
* If `70 < n <= 75`, then output `B-`.
* if `75 < n <= 80`, then output `B`.
* If `80 < n <= 85`, then output `B+`.
* If `85 < n <= 90`, then output `A-`.
* If `90 < n <= 95`, then output `A`.
* If `95 < n <= 100`, then output `A+`.
You are guaranteed that there are no other cases to test, and that `n` is guaranteed to be within `0` and `100`.
The input `n` can be provided via `stdin` or as an argument to the program.
Lines in the output are **not** allowed to have trailing spaces and/or newlines. You must output **exactly** the corresponding grade, nothing else.
Shortest code in bytes wins!
[Answer]
# Python, ~~74~~ ~~66~~ 73 bytes
```
lambda n,l="E "*8+"D D D C C C+ B- B B+ A- A A+ A+":l.split()[int(n-1)/5]
```
Unnamed lambda, uses a list of all grades in groups of 5. (I'm sure there's a way to handle n=100 without adding the extra 'A+' at the end, I'm just not sure how)
Edit: Thanks to @LeakyNun for 8 bytes
[Answer]
## JavaScript (ES6), 57 bytes
```
n=>`A+ A A- B+ B B- C+ C C D D D`.split` `[20-n/5|0]||`E`
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 36 bytes
```
?<Q41\E+C/-1075Q15?<Q66k-@"-+ "/_Q5d
```
[Test suite.](http://pyth.herokuapp.com/?code=%3F%3CQ41%5CE%2BC%2F-1075Q15%3F%3CQ66k-%40%22-%2B+%22%2F_Q5d&test_suite=1&test_suite_input=100%0A96%0A95.1%0A95%0A91%0A90%0A86%0A85%0A81%0A80%0A76%0A75%0A71%0A70%0A66%0A65%0A56%0A55%0A41%0A40%0A1&debug=0)
### Explanation
Here is the equivalent program in Python 3.
```
lambda Q:[chr(int(1075-Q)//15)+["-+ "[int(99-Q/5)%3],""][Q<66],"E"][Q<41].split()[0]
```
[Ideone it!](http://ideone.com/oRPSOB)
] |
[Question]
[
**This question already has answers here**:
[Calculate e^x and ln(x)](/questions/9080/calculate-ex-and-lnx)
(5 answers)
Closed 7 years ago.
Your goal is to calculate the exponential of a float (e\*\*x) up to 2 decimal places for any float within 1 to 10. The accepted error range is 0.01.
However, you must not use the built-in exponential function or the logarithm function.
In fact, attempts to circumvent this by `(2**x)**(1/ln(2))` are prohibited, even if you hardcode the ln(2).
Basically, the power function is fine, as long as the index is not derived from the input.
Shortest solution in bytes wins.
(You may include an extra solution which uses the built-in, but which does not affect the score in any way.)
## Specs
* Program or function
* Any reasonable input/output format
## Testcases
```
1 -> 2.71 or 2.72 or 2.73
```
[Answer]
# Matlab, 17 bytes
```
@(x)(1+x/1e9)^1e9
```
[Answer]
# Haskell, 19 bytes
```
(**1e9).(1+).(/1e9)
```
or alternatively a named function:
```
f x=(1+x/1e9)**1e9
```
[Answer]
# AppleScript, 62 bytes
Okay, limit approximation of ex is better. ;P Thanks, flawr.
```
(1+(display dialog""default answer"")'s text returned/1e9)^1e9
```
[Answer]
# MATL, 9 bytes
```
1e9/Q1e9^
```
Based upon @flawr's answers.
[**Try it Online**](http://matl.tryitonline.net/#code=MWU5L1ExZTle&input=MQ)
**Explanation**
```
% Implicitly grab input as a number
1e9 % Number literal
/ % Divide the input by 1e9
Q % Add one
1e9 % Number literal
^ % Exponent
% Implicitly display result
```
[Answer]
# AppleScript, 204 bytes
```
set x to(display dialog""default answer"")'s text returned
set r to 1
set i to 1
repeat 29
set r to r+(x^i)/f(i)
set i to i+1
end
return r
on f(a)
set x to a
repeat x-1
set a to a-1
set x to a*x
end
x
end
```
Yeah, it's kinda long. This uses the 30th term Taylor polynomial representation for e^x.
### How this works:
The Taylor series expansion for ex is:
[](https://i.stack.imgur.com/VGFPa.gif)
Now, according to the Lagrange error bound, I know that any given Taylor polynomial can get a precision to the first unused term of the Taylor series.
In more mathematical terms, I know that:
[](https://i.stack.imgur.com/baLlZ.gif)
where I will have a precision to ex of ak+1.
Since the OP specified that I must have a precision of 2 decimal places or better, ak+1 must be less than or equal to 1/100. I need to work out the point at which the maximum error of the function possible, located at 10 in this case is less than said error. After a little trial and error, I found that:
[](https://i.stack.imgur.com/VJgbB.gif)
Which means that:
[](https://i.stack.imgur.com/mHBhM.gif)
For as far as our precision is concerned. The code reflects this in that I will calculate:
[](https://i.stack.imgur.com/Hw8Is.gif)
] |
[Question]
[
Find the digit which occurs the most in a range of prime numbers.
### Input:
Two numbers, `p` and `q`, specifying the range; the range includes both `p` and `q`.
### Output:
The digit that occurs most frequently in that range of prime numbers. If two or more digits are tied, all of them should be outputted.
### Winning Criteria:
Fastest code to complete *(insert 1+ specific test cases here)* wins.
## Example
**Input:** `21 40`
**Output:** `3`
## Explanation
The prime numbers in the range `21 40` are `23`, `29`, `31`, and `37`. Within these numbers, `2` occurs 2 times, `3` occurs 3 times, and `1`, `7` and `9` occur 1 time each. Thus, as `3` appears the most, the correct output is `3`.
[Answer]
# Python 3
```
import collections
p=lambda n:n>1 and all(n%i for i in range(int(n**0.5),1,-1))
print(collections.Counter(''.join(map(str,filter(p,range(*map(int,raw_input().split(' '))))))).most_common(1)[0][0])
```
Probably not the best way it can be done, but a start. (**196 bytes**)
## Time Specs
Using Python's builtin code timer module, `timeit`, I got these times for each listed range.
```
(1, 11): 0.000084381103520
(1, 101): 0.000338881015778
(1, 1001): 0.003911740779880
(1, 10001): 0.071979818344100
(1, 100001): 1.785329985620000
(1, 1000001): 54.977741956700000
(1, 10000001): 1700.231099130000000
```
It can go over a range of a million numbers in under a minute.
## Usage
```
$ python test.py
21 41
3
$ python test.py
51 89
7
$ python test.py
201 501
3
```
## Ungolfed
```
import collections
def is_it_prime(n):
if n > 1:
if all(n % i for i in range(int(n ** 0.5), 1, -1)):
return True
return False
start, stop = raw_input.split(' ', 1)
primes = ""
for p in range(int(start), int(stop)):
if is_it_prime(p):
primes += str(p)
counter = collections.Counter(primes).most_common(1)
print(counter[0][0])
```
[Answer]
# Mathematica
```
Print[""<>IntegerString[MaximalBy[Tally[Join@@IntegerDigits[Prime[Range[PrimePi[#1]+1,PrimePi[#2]]]]],Last][[;;,1]]&@@FromDigits/@StringSplit@InputString[]]]
```
## Time Specs
Using Mathematica's builtin timer, `AbsoluteTiming`, I got these times for each listed range.
```
f=MaximalBy[Tally[Join@@IntegerDigits[Prime[Range[PrimePi[#1]+1,PrimePi[#2]]]]],Last][[;;,1]]&
Grid[Table[{1,10^x+1,AbsoluteTiming[f[1,10^x+1]][[1]]},{x,1,7}]]
```
Returns:
```
1 11 0.0003388
1 101 0.0003645
1 1001 0.0016222
1 10001 0.0040902
1 100001 0.0267737
1 1000001 0.211297
1 10000001 4.55387
1 100000001 43.9889
```
It can go over a range of a hundred million numbers in under a minute.
## Usage
```
wolframscript -f primedigitcount.wls
? 21 41
3
wolframscript -f primedigitcount.wls
? 51 89
7
wolframscript -f primedigitcount.wls
? 201 501
3
```
## Ungolfed
Takes the space-seperated input and converts it to two integers
```
a = FromDigits/@StringSplit@InputString[]
```
PrimePi is the inverse function of Prime, so this gets all the primes between the two a's. The `+1` is that if the operand is not prime, it gets the first prime below it, but we want a prime above the smaller number.
```
b = Prime[Range[PrimePi[#1]+1,PrimePi[#2]]&@@a
```
Turns every number in the list into a list of it's digits, and then concatenates all the lists into one list of all the digits
```
c = Join@@IntegerDigits[b]
```
Mathematica has a nice built-in for turning a list into unique items and their counts.
```
d = Tally[c]
```
Takes a list of the item (or items) who has the largest count, and strips off the tally.
```
e = MaximalBy[d,Last][[;;,1]]
```
Converts every number in the list to a string, concatenates them, and prints it.
```
Print[""<>IntegerString[e]]
```
## Conjecture:
In hope that somebody more mathematically inclined could find this to be an O(n) problem, I leave you this conjecture:
If the first number is kept as 1, and the 2nd number tends to be large (n>100), the result will be no more than two of 1, 3, or 7.
] |
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win.
Closed 9 years ago.
[Improve this question](/posts/31774/edit)
At Hackerrank.com, [the love letter mystery](https://www.hackerrank.com/challenges/the-love-letter-mystery) is a simple programming problem, which I already solved.
My solution involved calculating the palindrome and counting the number of operations to do it. On Hackerrank, they have another approach, which I don't understand completely:
>
> Given a string, you have to convert it into a palindrome using a certain set of operations.
>
>
> Let's assume that the length of the string is L, and the characters are indexed from 0 to L-1. The string will be palindrome, only if the characters at index i and the characters at index (L-1-i) are same. So, we need to ensure that the characters for all such indices are same.
>
>
> Let's assume that one such set of indices can be denoted by A' and B'. It is given that it takes one operation in decreasing value of a character by 1. So, the total number of operations will be |A'-B'|.We need to calculate this for all such pairs of indices, which can be done in a single for loop. Take a look at the setter's code.
>
>
>
I understand everything up until they mention that the total number of operations are **|A'-B'|, the absolute value between the two indices.** Why is that? For some reason, my head is being thicker (than usual).
Thanks!
======== EDIT ==========
Hey guys, thanks for your input. I thought that this stackexchange site would had been more appropiate than stackoverflow. Is there any stackexchange site where this question is more appropiate?
[Answer]
The algorithm might make more sense with a sample implementation to look at (here, in Python):
```
S = raw_input()
L = len(S)
T = 0
for i in range(L/2):
A = ord(S[i])
B = ord(S[L-1-i])
T += abs(A-B)
print T
```
Let's review the problem description. Each character decrement (e.g. `--'b' == 'a'`) counts as a single operation. The problem is to determine the number of operations required to transform the input string into a palindrome.
The algorithm iterates over half the string, and compares the ordinal value of the character at the current index with that of the character across from it (in its mirrored position). If they are not the same, the one that is larger needs to be decremented, but it doesn't actually need to be checked which is which. Taking the absolute value of the difference will produce the correct number of operations needed regardless.
I think a source of confusion might be the wording, *"Let's assume that **one such set of indices** can be denoted by A' and B'."* I believe that the author intended *A'* and *B'* to refer to the *characters* at each of these indices, and not the indices themselves. If they had actually meant to refer to the indices, the algorithm would return the same value for any given string length, which is obviously incorrect.
A golfed version might look like this:
```
s=map(ord,raw_input())
print sum(abs(s[i]-s[~i])for i in range(len(s)/2))
```
I suspect Ruby might be a bit shorter, because indexing a string returns the ordinal value, rather than the individual character.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/12525/edit).
Closed 10 years ago.
[Improve this question](/posts/12525/edit)
Given seconds like 11728, write the smallest javascript function that returns a string like `3hrs. 15min. 28sec.`
`signature textTime([int] t,[bool] z,[bool] m)`
`t` is the time like 11728 and you can assume `int`
`z` is optional and true means drop zero times, so `3hrs. 0min. 28sec.` becomes `3hrs. 28sec.`
`m` is optional and true means show only up to minutes, so `3hrs. 16min. 48sec.` is `3hrs. 16min.`
For 1 hour, `1hrs.` is fine (vs `1hr.`)
Example:
```
textTime(11728) returns "3hrs. 0min. 28sec."
textTime(11728,true) returns "3hrs. 28sec."
textTime(11728,true,true) returns "3hrs."
```
Regex is fine, speed is inconsequential.
**Shortest code wins.**
[Answer]
# Javascript, ~~194~~ 192
```
function T(a,c,e){d=60;s=["sec","min","hrs"];alert(t=[a,(0|a/d)*d,(0|a/d/d)*d*d].map(function(a,b,f){p=(a-(0|f[b+1]))/Math.pow(d,b);return e&&1>b?"":c&&!p?"":p+s[b]+". "}).reverse().join(""))}
```
Run it e.g. with
`T(7215,true,false) //2hrs. 15sec.`
*Could probably be golfed a bit more*
Edit Notes:
Added function name for the cost of 1 character\*
Renamed the function to `T`. I'm assigning `t` in the function hence i was overwriting the function itself.
Changed (a/(d\*d)) -> (a/d/d)
[Answer]
~~155~~ 147 characters.
```
textTime=(t,z,m,x)=>(x=[t/3600,t/60%60,t%60].map((t,i)=>(!z||t|0)&&~~t+["hrs","min","sec"][i]+"."||0).slice(0,2+!m),(z?x.filter(x=>x):x).join(" "))
```
If the parameters made a little more sense, yes, it would be fewer.
Non-ES6, changing the name and using globals like @C5H8NNaO4 did, at 183 characters:
```
function t(t,z,m){return(x=[t/3600,t/60%60,t%60].map(function(t,i){return(!z||t|0)&&~~t+["hrs","min","sec"][i]+"."||0}).slice(0,2+!m),(z?x.filter(function(x){return x}):x).join(" "))}
```
[Answer]
# 165 chars
```
function x(T, Z, M){
f=Math.round;h=T/3600;m=h%1*60;s=m%1*60;
r=f(h)+'hrs '+f(m)+'min '+f(s)+'sec'
Z?r=r.replace(/0\w+/g,''):0
M?r=r.replace(/\d+sec/,''):0
return r}
```
I just realized that this solution doesn't work for T<60, so I added a few characters and that fixed it (see below):
## 167 chars
```
function x(T, Z, M){
f=Math.round;h=T/3600;m=h%1*60;s=m%1*60;
r=f(h)+'hrs '+f(~~m)+'min '+f(s)+'sec'
Z?r=r.replace(/0\w+/g,''):0
M?r=r.replace(/\d+sec/,''):0
return r}
```
If you don't care about getting the rounding quite right:
## 149 chars
```
function x(T, Z, M){
h=T/3600;m=h%1*60;s=m%1*60;
r=~~h+'hrs '+~~m+'min '+~~s+'sec'
Z?r=r.replace(/0\w+/g,''):0
M?r=r.replace(/\d+sec/,''):0
return r}
```
] |
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** [Update the question](/posts/4901/edit) so it's [on-topic](/help/on-topic) for Code Golf Stack Exchange.
Closed 11 years ago.
[Improve this question](/posts/4901/edit)
I was amazed to find that there is a way to reduce the times you loop on an array to find if a element is contained once.
One would think that the only way would be to loop through the whole array, and increasing a variable every time you find a match, and then check if it is equal to 1. However, lets [look at this JavaScript code](https://stackoverflow.com/a/9253345/908879):
```
function isOnce(itm,arr){
var first_match=-1;
for(var i=0,len=arr.length;i<len;i++){
if(arr[i]===itm){
first_match=i;
break;
}
}
if(first_match!=-1){
var last_match=-1;
for(i=arr.length-1;i>first_match;i--){
if(arr[i]===itm){
last_match=i;
break;
}
}
if(last_match==-1){
return true;
}
}
return false;
}
```
It can reduce the times you loop when these two points met:
* There are 2 or more matches
* The first and last match are at least 1 space apart
so, `arr=["a", ...(thousands of items here)... ,"a"]; //we only looped 2 times`
I was wondering if there are other ways to reduce the looping in \*certain cases.
\*There are obviously some cases that one will need to loop through every item on these worst-case scenarios. So it might not work all the time.
[Answer]
D
```
bool containsOnce(E,R)(R haystack,E needle){
bool foundOnce=false;
foreach(e;haystack){
if(e==needle){
if(foundOnce)return false;
foundOnce=true;
}
}
return foundOnce;
}
```
this is pretty much the best case on unsorted data, you loop until you find a match and then set a flag to true and continue looping, when you find the second match return false immediately, when you looped over the entire thing return state of the flag
this has better timebounds when the double match is found near the beginning of the array (and in general when the items are close together) (but is better in a code-golf contest ;) )
in interest of time bound you'll remain at O(n) regardless on any algorithm (sometimes there simply are no improvements possible except with micro-optimizations). as finding a single match (a subproblem of the current problem) in an unsorted array is O(n)
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/260696/edit).
Closed 10 months ago.
[Improve this question](/posts/260696/edit)
*This is my first codegolf post so let me know if I have missed anything. Thanks :)*
# **Description**
You are given a list of numbers with `2 < n <= 6` length i.e. [1, 10] or [75, 9, 9, 8, 2, 100]. Given the basic operators `+ - / *` you must try and generate all possible equations. The list of numbers to pull from is: `[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 25, 50, 75, 100]`.
Defining this list **as is** for your program does not count towards the byte count, same goes for defining the list of operators. There are two separate **winning** conditions: 1) Smallest program; 2) Fastest program.
Generating all equations when `n = 6` results in ~200 billion equations. It might be wise to verify that your code works with lower lengths values first, or a subset from the list of numbers.
**Rules**
1. Equations must be in [postfix notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation)
2. No duplicate equations i.e. `1 1 2 + +` and `1 1 2 + +`
3. Handle commutativity i.e. `1 10 + 2 4 + +` and `10 2 1 4 + + +`. Remove commutative equations so only one remains.
**Extra Challenges**
* Calculate all equations, only accepting positive 3 digit solutions. If at any stage during the process the solution becomes negative `1 100 -` or non-int `100 3 /`, stop processing the entire equation and move onto the next equation.
**Final Notes**
Some of you may have recognised the list of numbers from [Countdown](https://en.wikipedia.org/wiki/Countdown_(game_show)) or [Letters and Numbers](https://en.wikipedia.org/wiki/Countdown_(game_show)). I myself wrote a [program](https://github.com/Ghrafkly/countdownJava/tree/master/src/main/java/org/countdownJava/Current) (unoptimized, but functional) to calculate all possible 3 digit solutions under the shows rules. It took 90 minutes to run with multithreading, though the slowest part was calculating the equations, not generating them.
Good luck!
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 31 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
榀œ€`"+-/*"Igãâε¬s`s¦∍S«ðý}ÙIK
```
Goes for the code-golf portion. Brute-force approach, so pretty slow.
Doesn't handle the *Extra Challenge* portion.
[Try it online.](https://tio.run/##yy9OTMpM/f//8LJDyx41rTk6GUgkKGnr6mspeaYfXnx40bmth9YUJxQDZTt6gw@tPrzh8N7awzM9vf//jzbUMTTQMTeNBQA)
**Explanation:**
```
æ # Get the powerset of the (implicit) input-list
¦ # Remove the leading empty sublist
€œ # Map over each powerset-list, and get all its permutations
€` # Flatten the list of lists of lists one level down
"+-/*" # Push the string of operators
Ig # Push the input-length
ã # Get the cartesian power of the two
â # Get the cartesian product of the two lists to create all possible pairs
ε # Map over each pair of [list, operator-string]:
¬ # Push the head (the list) (without popping)
s # Swap so the pair is at the top of the stack again
` # Pop and push the list and string separately to the stack
s # Swap so the list is at the top of the stack
¦ # Remove its first item
∍ # Shorten the operator string to the length of this list
S # Convert the operator string to a list of characters
« # Merge it to the list of integers
ðý # Join it by spaces
}Ù # After the map: uniquify the results
IK # Remove the singular input-integers, since they're not equations
# (after which the result is output implicitly)
```
Since 05AB1E uses Reverse Polish/Postfix notation, here the program with additional footer to get the result of each equation: [Try it online](https://tio.run/##yy9OTMpM/f//8LJDyx41rTk6GUgkKGnr6mspeaYfXnx40bmth9YUJxQDZTt6gw@tPrzh8N7awzM9vf@XVdorKdgqKNlX6oXp/I821DE00DE3jQUA).
] |
[Question]
[
[Wren](https://wren.io/) is a small, fast, class-based concurrent scripting language. Does anyone have any tips for this language?
Please make sure to post 1 tip per answer, and don't post answers like "remove whitespace".
[Answer]
# `String.fromByte`
Instead of the standard `String.fromCodePoint(x)`, a method that saves a whole 5 bytes is:
```
String.fromByte
```
] |
[Question]
[
Generate the following list of lists consisting of the unique last digits of the powers from 1 to 9 for the numbers [0..9]
```
[[0], [1], [2, 4, 8, 6], [3, 9, 7, 1], [4, 6], [5], [6], [7, 9, 3, 1], [8, 4, 2, 6], [9, 1]]
```
e.g. For the number 2 we have:
\$2^1,2^2,2^3,2^4,2^5,... \to 2,4,8,16,32,64,128,... \to 2,4,8,6,4,8,... \to [2,4,8,6]\$
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer (as measured in bytes) wins and the usual golfing rules apply.
[Answer]
# Lua, 71 bytes
```
for i=0,9 do u=i a=i while a*i%10~=i do a=a*i%10 u=u..a end print(u)end
```
[Try it online!](https://tio.run/##yylN/P8/Lb9IIdPWQMdSISVfodQ2UyERiMszMnNSFRK1MlUNDeqAfKBUoi2EC1RTqqeXqJCal6JQUJSZV6JRqglk//8PAA)
Since you aren't specific about if you need a table/array or only printed results, I present my answer with printed results:
```
0
1
2486
3971
46
5
6
7931
8426
91
```
[Answer]
# CoffeeScript, 46 bytes
It was not specified whether a set can be considered a list, so this outputs a list of sets:
```
(new Set(v**x%10for x in[1..9])for v in[0..9])
```
Outputting a list of arrays would require **57 bytes**:
```
(Array.from new Set(v**x%10for x in[1..9])for v in[0..9])
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 61 bytes
```
f=t=>t>9?[]:[(g=x=>[x|0,...x%5>1?g(x*t%10):[]])(t),...f(-~t)]
```
[Try it online!](https://tio.run/##FclBCoAgEADA1wS7kVKHDgnaQ8RDmEoRbdQSHqKvG8111umeLn8uB4ud5lBK1KwNm2G0TllIOmtj89M2Uspc9aYbE@Saq65FZZ1DYPwrgngZXfG0X7QFuVGCCIjlAw "JavaScript (Node.js) – Try It Online")
---
# [JavaScript (Node.js)](https://nodejs.org), 62 bytes
```
_=>[...'0123456789'].map(g=(t,x)=>[x,...x%5>1?g(t,x*t%10):[]])
```
[Try it online!](https://tio.run/##FcrtCkAwFIDhq5EdcTLf1LgQLS0fi8bE0u5@@Ps@7yYecY/Xepro0NPsFuYG1vaI6Mc0SbO8KKva57iLk0hGTGjhYxt@g/Xylnbyb4HxaAxNzzm4UR@3VjMqLclCANwL "JavaScript (Node.js) – Try It Online")
---
# [JavaScript (Node.js)](https://nodejs.org), 64 bytes
```
_=>Array(10).fill(1).map(g=(x,t)=>[x=x*t%10,...x%5>1?g(x,t):[]])
```
[Try it online!](https://tio.run/##HclBCoAgEADA1wS7UUseugRr9A6JkEopLMMk7PUGzXV2/eh7DtsV69MvazacJ5ZDCPoF0SCZzTkQSIe@wDKkKiJLlTiVsRBNRUSpaKXo7V@dGkfMsz9v71Zy3oIBxPwB "JavaScript (Node.js) – Try It Online")
[Answer]
# JavaScript, ~~71~~ ~~69~~ 67 bytes
Thanks to user81655 and tsh for reducing two bytes each
```
(a=[...'0123456789']).map(v=>[...new Set(a.map(x=>+x?v**x%10:+v))])
```
```
console.log(
(a=[...'0123456789']).map(v=>[...new Set(a.map(x=>+x?v**x%10:+v))])
)
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes
```
TFN4Lm€θÙ,
```
[Try it online!](https://tio.run/##yy9OTMpM/f8/xM3PxCf3UdOaczsOz9T5/x8A "05AB1E – Try It Online")
[Answer]
# JavaScript, ~~98~~ 90 bytes
```
_=>{r=[];for(i=-1;++i<=9;){for(c=[],p=1;c[0]!=(a=(p*=i)%10);c.push(a));r.push(c)}return r}
```
[Try it online!](https://tio.run/##JcmxCsIwEIDhV9FBuLO2NJtyng/goINjKRKC0etQwyUtSOmzx4rbx/93drTRqYRUjvvsOd/5NCk3Lfm3gnBpqCjkyAfC6VfcsnaBDbmmbtcMliFsWXBjaiRXhSG@wCKS/ulw1kcatF/pnINKn@B8u16qmBY/xX/AAyLmLw)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 17 bytes
```
I﹪EχXιI…1§22553ιχ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzc/pTQnX8M3sUDD0EBHISC/PLVII1NHASwZlJiXnqqhZKiko@BY4pmXklqhoWRkZGpqDBTI1AQBHQVDAyBl/f//f92yHAA "Charcoal – Try It Online") Link is to verbose version of code. Outputs each list element on its own line with lists double-spaced. Explanation:
```
χ Predefined variable 10
E Map over implicit range
ι Current value
X Vectorised to power
… Range from
1 Literal string `1` to
22553 Literal string `22553`
§ Cyclically indexed by
ι Current value
I Cast to integer
﹪ Vectorised modulo by
χ Predefined variable 10
I Cast to string
Implicitly print
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 50 bytes
```
DeleteDuplicates/@Array[Mod[(#-1)^#2,a]&,{a=10,a}]
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773yU1J7Uk1aW0IAcoUJJarO/gWFSUWBntm58SraGsa6gZp2ykkxirplOdaGtooJNYG/s/oCgzr0TBIf3/fwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 71 bytes
```
l|d<-[1..9]=[foldl(\a x->a++[x|notElem x a])[][x^p`mod`10|p<-d]|x<-0:d]
```
[Try it online!](https://tio.run/##BcHBDoIwDADQX@lRQ0rgiBne/IpZQ8NAid3WCIce9u2O9z68fxeRWqUEh75v24FGv2YJcnkyGN65abyVlI@HLBEMmK6evL10ijlMfVfUYaBiDrtboBp5SzCC/rZ0gNT/vAq/94qz6gk "Haskell – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 55 bytes
```
R=range(10);print([[*{a**-~i%10for i in R}]for a in R])
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P8i2KDEvPVXD0EDTuqAoM69EIzpaqzpRS0u3LlPV0CAtv0ghUyEzTyGoNhbETgSzYzX//wcA "Python 3 – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 57 bytes
```
9*¶
$.`
.
$& $.(**) $.(***) $.(****
.\B
(.+?)( \1)+
$1
```
[Try it online!](https://tio.run/##K0otycxLNPz/n8tS69A2Li4VvQQuPS4VNQUVPQ0tLU0IBae1uPRinLi4NPS07TU1FGIMNbW5VIB6AQ "Retina – Try It Online") Explanation:
```
9*¶
$.`
```
List the digits from `0` to `9`.
```
.
$& $.(**) $.(***) $.(****
```
Calculate the first four powers of each digit.
```
.\B
```
Take the last digit of each power.
```
(.+?)( \1)+
$1
```
Remove duplicates.
[Answer]
# [Deadfish~](https://github.com/TryItOnline/deadfish-), 549 bytes
```
{{i}d}icc{dddd}dddc{iiii}iiiiic{ddddd}ic{iiiii}dddc{dddd}ddc{iiii}iiiic{ddddd}ic{iiiii}dddc{dddd}dcddddddc{i}ddc{d}iic{i}iic{d}ddc{i}c{iiii}dc{ddddd}ic{iiiii}dddc{dddd}c{d}iiic{i}iiic{d}dddc{i}ic{d}dciiiiic{iiii}iiiic{ddddd}ic{iiiii}dddc{dddd}ic{d}iic{i}c{iiii}dc{ddddd}ic{iiiii}dddc{dddd}iic{iiii}c{ddddd}ic{iiiii}dddc{dddd}iiic{iiii}dc{ddddd}ic{iiiii}dddc{ddd}ddddddc{d}dc{i}iiic{d}dddc{i}dddc{d}iiiciiiiic{iiii}iiiic{ddddd}ic{iiiii}dddc{ddd}dddddc{d}ddc{i}ddc{d}iiciiiiiicddddddc{i}c{iiii}dc{ddddd}ic{iiiii}dddc{ddd}ddddc{d}dddciiiiic{iiii}iiiicc
```
[Try it online!](https://tio.run/##jVBbCoAwDDuRh5JWMd9@lp59ro85RZgrbIw2ydLwtvKO81hKEYGygki4ltZDglpqF6Jrc28i5ol8AEc48pGhnVNBhvI7VTSVeCATxGQm1bnxprQ74wjdxMTHt@oQg18lbTGY288W3KLB/CbaBd/pIiR67nPmmp2PASrlAg "Deadfish~ – Try It Online")
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 10 bytes
```
9ʀƛn9ɾevtU
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=9%CA%80%C6%9Bn9%C9%BEevtU&inputs=&header=&footer=)
[Answer]
# [Kotlin](https://kotlinlang.org), ~~134 122~~ 112 bytes
[// this codegolf link specifies that lambda names could be ignored in calculating the bytes](https://codegolf.stackexchange.com/questions/126464/tips-for-golfing-in-kotlin)
```
var listOfPower =
```
```
{n:Int->List(9){n}.mapIndexed{index,_->(1f*n).pow(index).toInt()}.map{"$it".last().digitToInt()}.distinctBy{it}}
```
[Try it online!](https://tio.run/##y84vycnM@/@/Os/KM69E184ns7hEw1KzOq9WLzexwDMvJbUiNaU6E0TrxOvaaRimaeVp6hXkl2uAxTT1SvKB@jQ0wcqrlVQyS5T0chKBZmjqpWSmZ5aEwKRTgAZn5iWXOFVWZ5bU1v7/DwA "Kotlin – Try It Online")
~~```
{n:Int->List(9){n}.mapIndexed{index,_->(1f*n).pow(index).toInt()}.distinctBy{"$it".last()}.map{"$it".last().digitToInt()}}
```
[Try it online!](https://tio.run/##y84vycnM@/@/Os/KM69E184ns7hEw1KzOq9WLzexwDMvJbUiNaU6E0TrxOvaaRimaeVp6hXkl2uAxTT1SvKB@jQ0a/VSgDoz85JLnCqrlVQyS5T0chKLwRJAc1BEgCrTM0tCoPpq//8HAA "Kotlin – Try It Online")
```
{n:Int->List(9){n}.mapIndexed{index,_->(1f*n).pow(index)}.distinctBy{"${it.toInt()}".last()}.map{"${it.toInt()}".last().digitToInt()}}
```
[Try it online!](https://tio.run/##y84vycnM@/@/Os/KM69E184ns7hEw1KzOq9WLzexwDMvJbUiNaU6E0TrxOvaaRimaeVp6hXkl2uAxTRr9VKAOjLzkkucKquVVKozS/RK8oEmaWjWKunlJBaDGCCTcMgBdadnloRARWv//wcA "Kotlin – Try It Online")~~
#### Ungolfed:
```
var listOfPower =
{n:Int->List(9){n}.
mapIndexed{index,_->(1f*n).pow(index).toInt()}.
map{"$it".last().digitToInt()}.
distinctBy{it}}
```
create an array of size 9, set all of them to n,
set every single one to their power to their index, convert to int
remove duplicates by getting their last digit
create a list that holds in their last digits and return it
[Answer]
# Pyth, 10 bytes
```
m.ue*Ndd)T
```
[Try it here!](http://pythtemp.herokuapp.com/?code=m.ue%2aNdd%29T&debug=0)
] |
[Question]
[
# Introduction
A polyglot is a program that is valid in multiple languages at once. An iterative quine is a program that outputs another program that outputs another program that outputs the source of the original program. Note that the number of chained programs does not have to be 3; it could be 2, 4, or 97384.
# Challenge
Your task is to write a polyglot iterative quine. Each program in the program chain must be a polyglot.
* Each of your programs must take no input.
* As stated above, each of the programs must output the source of the next program in the chain. The last program in the chain must output the source code of the first program.
# Scoring
Your score is calculated as follows:
* For each program in the chain, take the number of languages it is valid in. Sum the results.
* Sum the byte count of each program in the chain.
* Divide the byte count by the number from the first program.
# Rules
* The length of the chain must be at least 2.
* Each program in the chain must be valid in at least 2 languages.
* The program with the lowest score wins.
* "Different language" is defined as follows:
+ A language where the source code of the compiler or interpreter is not the same as another, and the compiler or interpreter does not run the same language as another. Some examples of different languages are: Python 2 and 3, C and C++, Java and C, and Lua and Ruby. However, by this definition, using `tcc` instead of `gcc` does not count as a different language, because `tcc` runs the same language as `gcc`: C.
* Programs are allowed to throw errors, but only *after* they print out the output of the program. For example, `print(1/0);print(<quine stuff>)` in Python 3 would be invalid, but `print(<quine stuff);print(1/0)` would be.
[Answer]
# [Wumpus](https://github.com/m-ender/wumpus), [><>](https://esolangs.org/wiki/Fish), [Befunge-98](https://pythonhosted.org/PyFunge/), \$\frac{57+57}{3+3}=19\$
```
"]<0~[#34ooo!O;#53&o@,k*4e-1#'$ #o#!-1'#'+3*a9*c5+*68%2++
```
[Try it in Wumpus!](https://tio.run/##Ky/NLSgt/v9fKdbGoC5a2dgkPz9f0d9a2dRYLd9BJ1vLJFXXUFldRUE5X1lR11BdWV3bWCvRUivZVFvLzELVSFv7/38A "Wumpus – Try It Online") [Try it in ><>!](https://tio.run/##S8sszvj/XynWxqAuWtnYJD8/X9HfWtnUWC3fQSdbyyRV11BZXUVBOV9ZUddQXVld21gr0VIr2VRby8xC1Uhb@/9/AA) [Try it in Befunge-98!](https://tio.run/##S0pNK81LT9W1tPj/XynWxqAuWtnYJD8/X9HfWtnUWC3fQSdbyyRV11BZXUVBOV9ZUddQXVld21gr0VIr2VRby8xC1Uhb@/9/AA)
A modified version of a previous [polyglot of mine](https://codegolf.stackexchange.com/a/155627/76162) that makes it iterative by flipping the first `0` to a `1` and back again.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/196347/edit).
Closed 4 years ago.
[Improve this question](/posts/196347/edit)
# Introduction
Each Unicode codepoint can be represented as a sequence of up to 4 bytes. Because of this, it is possible to interpret some 2, 3, or 4-byte characters as multiple 1-byte characters. (See [here](http://www.ltg.ed.ac.uk/%7Erichard/utf-8.html) for a UTF-8 to bytes converter).
# Challenge
Given a UTF-8 character, output it split into a sequence of 1-byte characters. If the character is 1-byte already, return it unchanged.
* Your program must take one, and exactly one, UTF-8 character as input. You may use any input method you wish, as long as it has been decided on meta that is is a valid method. You cannot take input as a bytearray or series of bytes; then the challenge would just be converting hex to ASCII.
* Your program must output one or more ASCII 1-byte characters. Again, any output method is allowed as long as it has been marked valid on meta. Edit: As per the conversation in the comments, output should be in Code Page 850.
Note: see [this post](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) for valid I/O methods.
# Example I/O
>
> `܀ (0x700)`
>
> `܀ (0xdc 0x80)`
>
>
> `a (0x61)`
>
> `a (0x61)`
>
>
> `聂 (0x8042)`
>
> `Þüé (0xe8 0x81 0x82)`
>
>
>
# Rules
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins!
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), ~~73~~ 85 bytes
```
a=>Encoding.UTF8.GetBytes(a).Select(b=>Encoding.GetEncoding(850).GetString(new[]{b}))
```
[Try it online!](https://tio.run/##Sy7WTS7O/O9WmpdsU1xSlJmXruPpmleam1qUmJSTChWys1NIs/2faGvnmpecnwIU0AsNcbPQc08tcaosSS3WSNTUC07NSU0u0UhCUgOUhrE1LEwNNEECwWDzNPJSy6Njq5NqNTX/W3M55@cV5@ek6oUXZZak@mTmpWpAbNUDSiQnlmikaSjdaVDS1NQkSmki0SpfNDaB1f4HAA "C# (Visual C# Interactive Compiler) – Try It Online")
+12 bytes to use the updated code page
] |
[Question]
[
>
> tl;dr? See bottom for **The Competition**
>
>
>
## Integer literals
While programming, the 64-bit hexadecimal literal `0x123456789abcdefL` is difficult to gauge the size of. I find myself mentally grouping digits from the right by fours to see that it's 15 digits' worth.
Python PEP 515 allows you to express the above literal, inside code, as `0x123_4567_89ab_cdefL`. If you prefer binary, then it's even more invaluable: `0b1_0010_0011_0100_0101_0110_0111_1000_1001_1010_1011_1100_1101_1110_1111L`
## String representations
Python can also convert an integer into strings with spacing characters, as follows:
```
'{:#_b}'.format(81985529216486895L)
'{:#_x}'.format(81985529216486895L)
'{:,}'.format(81985529216486895L)
```
The first two produce what's shown above (although without the `L` suffix), while the last will produce
```
"81,985,529,216,486,895"
```
>
> Although with PEP 515, they would be better expressed as:
>
>
>
> ```
> '{:#_b}'.format(81_985_529_216_486_895L)
> '{:#_x}'.format(81_985_529_216_486_895L)
> '{:,}'.format(81_985_529_216_486_895L)
>
> ```
>
>
Note, though, the following:
* `'_'` is only legal for binary and hexadecimal strings - and Python will insert them every four characters (from the right);
* `','` is only legal for decimal strings - and Python will insert them every three characters (from the right);
* No other separator characters are allowed.
---
## Enough with the Python syntax lesson; on to C++!
C++14 also allows separators inside an integer literal to allow grouping, much like the above. Only (of course) it's a different character: the tick (single quote `'`). So the above literals would be:
```
0b1'0010'0011'0100'0101'0110'0111'1000'1001'1010'1011'1100'1101'1110'1111uL
0x123'4567'89ab'cdefuL
81'985'529'216'486'895uL
```
Python is often used to machine-generate C/C++ code, because it's so easy to do! But there's no native Python way to generate these new 'tick'-based identifiers - `.format()` can only use `_`. So, here's some code that I wrote to do it:
```
# Hex function with tick marks
def HexTicks(num) :
# Convert to hex (without leading 0x - yet)
s = '{:x}'.format(num)
# Insert tick marks
for i in range(len(s)-4, 0, -4) :
s = s[:i] + "'" + s[i:]
# Return the result
return "0x" + s + "uLL"
```
## The Competition
>
> Sorry @ASCII-only !
>
>
>
Write a Python 2.7.3 expression or lambda, smaller than the above function (not including whitespace or comments), that:
1. Takes any non-negative integer;
2. Produces the correct hexadecimal string for that integer;
3. With a leading `0x` and trailing `uLL`;
4. No leading zeroes as part of the hex number;
5. With tick marks (`'`) every four digits, counting backwards from the right;
6. No tick mark straight after the `0x`.
### ILLEGAL
```
0x0uLL # If integer was anything other than zero (2.)
12'3456 # No 0x or uLL (3.)
0x0'1234uLL # Leading zero (4.)
0x12'345uLL # Not grouped by four (5.)
0x'1234uLL # Tick mark before hex number (6.)
```
### Bonuses
A. Can be easily modified to produce capital hex letters - but not the `0x` or `uLL` parts;
>
> Note that `.format()` allows `'{:_X}'` to capitalise the hex characters - but `'{:#_X}'` will capitalise the `0X` too
>
>
>
B. An extra `digits` parameter that **will** add leading zeros to that number of digits (not resultant characters; just hex digits) - unless it's already got that many.
>
> For example: `HexTick(0x1234,6)` would produce `"0x00'1234uLL"`
>
>
>
[Answer]
# [Python 2](https://docs.python.org/2/), ~~68~~ 65 bytes
-3 bytes for both thanks to [tsh](https://codegolf.stackexchange.com/users/44718/tsh)
```
lambda n:"0x"+re.sub("(?!^)(?=(....)+u)","'","%xuLL"%n)
import re
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPSsmgQkm7KFWvuDRJQ0nDXjFOU8PeVkMPCDS1SzWVdJTUgVi1otTHR0k1T5MrM7cgv6hEoSj1f0FRZl6JRpqGhaGlhampkaWRoZmJhZmFpamm5n8A "Python 2 – Try It Online")
### Eligible for both bonuses, ~~76~~ 73 bytes
```
lambda x,d:"0x"+re.sub("(?!^)(?=(....)+u)","'","%%0%dxuLL"%d%x)
import re
```
[Try it online!](https://tio.run/##DcNhCoMgFADg/ztFeyB7jyTKzdAgukBHGIPComCVmII7veuDz/78cuwize07fYdtNEMWuWmgjJC7qTjDiIDd/UPYtVhcKA8EHB5XxkpmYuh7YIZFuq2bPZzP3JSsW3ePM6pKKymFFlX9UrXSkj8FUfoD "Python 2 – Try It Online")
] |
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
This question does not appear to be about code golf or coding challenges within the scope defined in the [help center](https://codegolf.stackexchange.com/help/on-topic).
Closed 5 years ago.
[Improve this question](/posts/176046/edit)
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
Output how many letters would be used if all the numbers from 1 to 1000 (one thousand) inclusive were written out in words.
*NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.*
You must actually calculate it - just printing the predetermined result is not allowed.
Output with [any acceptable method.](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods)
[Answer]
# Mathematica, 38 bytes
```
StringLength@StringJoin@IntegerName[Range[1000]]
```
@Doorknob has a leaner implementation:
```
Tr@StringLength@IntegerName@Range@1000
```
(\* 20961 \*)
---
*Explanation*
```
IntegerName[Range[10]]
```
(\* {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"} \*)
```
StringJoin@IntegerName[Range[10]]
```
(\* "onetwothreefourfivesixseveneightnineten" \*)
```
StringLength@StringJoin@IntegerName[Range[10]]
```
(\* 39 \*)
[Answer]
# [Common Lisp](http://www.clisp.org/), ~~104~~ ~~98~~ ~~85~~ ~~76~~ ~~75~~ 74 bytes
```
(princ(loop for i to 999 sum(count-if'both-case-p(format nil"~R"(1+ i)))))
```
[Try it online!](https://tio.run/##Fco7DoAgDADQqzQs1hgGR67hDbCR2ARow2f16lXf/ChzVzPUxpUwiygkacAwBEII0GdBklmH57ScMm5PsV9e8VslDqic3XM43Dfg9Wf2Ag "Common Lisp – Try It Online")
] |
[Question]
[
# Introduction
As you all know, German has umlauts. They're these things: `¨`
However, most keyboards don't have an umlaut key. That's fine, though, because you can write `ö`, `ä`, and `ü` as `oe`, `ae`, and `ue`.
# Challenge
* Your job is to to replace `ö`, `ä`, and `ü` with `oe`, `ae`, and `ue` (and likewise for their capital versions).
* You have to deal with both the combining diacritical mark and single characters. (Thank you @ETHProductions for pointing this out.)
* Capitalization of the base letter stays intact.
* Capitalization of the `e` depends on the capitalization of the surrounding letters after replacement. You should write it as `e` unless it's adjacent to a capital letter on both sides, in which case write it as `E`. (End of line and space are not capital letters.)
* Standard loopholes and I/O rules apply.
* This is code-golf, so shortest code in **UTF-8** bytes wins!
# Example Input and Output
**Test cases using precomposed characters**
```
ü = ue
üb = ueb
üB = ueB
Ü = Ue
Üb = Ueb
ÜB = UEB
```
**Test cases using combining diacritics**
```
ö = oe
öb = oeb
öB = oeB
Ö = Oe
Öb = Oeb
ÖB = OEB
```
[Answer]
# [QuadR](https://github.com/abrudz/QuadRS), 112 bytes
```
[öäüÖÄÜ].?
.̈.?
1(819⌶⍣(2=+/M≠819⌶M))(∊'oauOAU'M)['öäüÖÄÜ'⍳⊃M]'e',⍵p↓1↓M←⍵M
```
[Try it online!](https://tio.run/##TcyxSsQwGMDxPU@RLS3qSZ10OKQ5MjiEDmkHOW5o2iAZvNRqn0A56mFBEJw6CPoG4k23Zb2nyIvUL3FxSPL78ofvrivrdpqWdme/7N6@2yc7rmaXaHbo4U6i8@TCvezc8BmdzY9OuXv@@PvhcRy5fktM2WVpQXi8JP9XEDd8u@0jXxFFjt3w07jNWwKHu80rjHyaxLXIGU/zqwXOmcjxIhVMoKZVJ5W5bcy9qpHd4znuFLwyQIJoEEV2BBTQRhkAbfStYBTBAqnXen2Da11WD7rVFTKHHqpRHjJIetJAirKQM@Uhg6Snzxmjvw "QuadR – Try It Online")
*Replace…*
`[öäüÖÄÜ].?` any umlaut'ed character, optionally followed by a character
*… or…*
`.̈.?` any character and a combining umlaut, optionally followed by a character
*… with the result of the following function:*
`⍵M` the **M**atch
`M←` store in `M`
`1↓` drop one character from the left
`⍵p↓` drop one character if match had combing umlaut (`⍵p` is 0-indexed pattern number)
…`'e',` prepend the following character and an **e**:
`(`…`)[`…`]` index using:
`⊃M` the first character of the **M**atch
`'öäüÖÄÜ'⍳` …'s index in the list of umlaut'ed characters
… into:
`'oauOAU'M` the two-element list of the de-umlaut'ed characters and the **M**atch
`∊` **e**nlisted (flattened)
`1(`…`)` apply the following derived function with 1 as left argument:
`819⌶⍣(`…`)` casefold (to uppercase, because left argument would be 1) if:
`819⌶M` the lowercased **M**atch
`M≠` Boolean where the **M**atch differs from that (i.e. is uppercase)
`+/` sum that
`2=` 2 is equal to that
Equivalent to the tacit Dyalog APL function:
```
'[öäüÖÄÜ].?' '.̈.?'⎕R{1(819⌶⍣(2=+/M≠819⌶M))(∊'oauOAU'M)['öäüÖÄÜ'⍳⊃M]'e',⍵.PatternNum↓1↓M←⍵.Match}
```
[Answer]
# Perl 5 (`-pC -MUnicode::Normalize -Mutf8 -MList::Util=max`), ~~63~~, ~~58~~, 53 bytes
```
$_=NFD$_;s/([oau])\K̈(?=(.?))/max($1,$2)lt a?E:e/gei
```
[try it online](https://tio.run/##Zc/BSsQwEIDhe54ihx5acC0KgkRKIVov6vZiTypLko7rQNuUJAXxCfYh@ije9rrPZExy3VM@5h8GMoMZbrzPdtX28SHb3dkyf9Ni@Sjen06HvK7yy7ooylF859nVRXZdDI6KumFQ7gG9fwXrqBIWLF0sTns6G1B6nLWFnqovYYRyYCw5/tKKLhBemSCDeBInxzWgC22VCaGtsXUNJ2f3w3GJU1SPQhl0qCzRp0PY1xAhk2QkT@SkTbmFCJkkI2NuG/6nZ4d6sn4z3/vNyzNax1jncKjCp8Ogm1DpHhjbajOKAX8gDBf3efsP)
] |
[Question]
[
The following challenge is basically a simpler version of the one proposed by Dennis ([Lossy ASCII art compression](https://codegolf.stackexchange.com/questions/53199/lossy-ascii-art-compression)). I found the idea super interesting but a bit too convulted, and seeing as it didn't seem to be getting much attention I decided to modify it a little bit.
You'll be downloading 5 ASCII art text files, each of them composed only of the following characters:
```
@#+';:,.`
```
Each char represents a different brightness level (1-10 from @ to the whitespace).
Given a quality ratio q, which varies from 0.5 to 0.9 in 0.1 increments, your job is to **output a compressed version of each ASCII file, while making those files able to decompress themselves.**
That is to say, ImageX.txt is compressed by Program.py into CompImageX-xx.cpp (xx being the quality of the compressed image). Once CompImageX-xx.c is executed, a final decompressed image ImageX-xx.txt is created.
The .py and .c extensions are just an example, you can write the compressor and compressed images in any language that you want (doesn't have to be the same language for both, but you can't use different languages for different images).
The quality changes the image output in a relatively simple way. We'll call the array of usable chars Arr. Each char of ImageX becomes Arr[RoundHalfDown((Arr.Index(char)\*q))], with the exception of the whitespace which remains the same no matter the quality.
```
RoundHalfDown(0.6) = RoundHalfDown(0.7) = RoundHalfDown(1) = 1
RoundHalfDown(0.5) = RoundHalfDown(0.4) = RoundHalfDown(0) = 0
```
For a short example:
```
'#;@
```
at q=0.5 would become
```
#@+@`
```
You have to implement your own compressor, can't use any libraries that handle it for you.
You can view the images [here](http://jsfiddle.net/14u3vw4p/embedded/result/) and download them from [here](https://drive.google.com/open?id=0Byb-iITM2Kk2flpycFdMZHltVEZIaEpFN2pLd1QtZHVNeS1Xak5NNGxCTmRCZ2pYRDhiU3M).
**Your score is the square root of the size of your compressor, multiplied by the sum of the size of all the compressed files --> sqrt(c)\*sum(f). Lowest score wins.**
```
USER LANGUAGE SCORE
Dennis CJam 1046877
```
[Answer]
# CJam → CJam, score 1046877.4413
I'm not going to participate in my own challenge, but since this one doesn't contain its core part (figuring out the optimal transformation to make the original image more compressible), here I go:
```
q"@#+';:,.` ":P9,easdf*.4f+:iPf=S+er_N/z,:L;N-__&W%:Pf#2f+e`{(2b1>}%
e_P,2+b256b:c`P`":P,2+\256b\b{_2,#)_(@a?)+}%{(2-a\2b)*}%e_Pf="L"/N*"
```
The linefeed is for "readability" only.
It should be possible to improve the score by improving or simplifying the compression.
### Summary
```
e# Read the input and modify the palette according to the quality.
q"@#+';:,.` ":P9,easdf*.4f+:iPf=S+er
e# Compute the line length and the unique characters of the palette.
_N/z,:L;N-__&W%:P
e# Replace each character by its index in the palette, plus two.
f#2f+
e# Perform run-length ecnoding, saving the runs using bijective base-2 numeration.
e# All related code has been adapted from this answer:
e# http://codegolf.stackexchange.com/a/53065
e`{(2b1>}%
e# Convert from base length(palette)+2 to byte array (string).
e_P,2+b256b:c`
e# Push the palette and the code for the decoder.
P`":P,2+\256b\b{_2,#)_(@a?)+}%{(2-a\2b)*}%e_Pf="L"/N*"
```
### Score
```
$ LANG=en_US
$ for i in {1..5}; do for q in 0.{5..9}; do
> cjam comp.cjam $q < image$i.txt > image-$i-$q.cjam
> done; done
$ wc -c comp.cjam
136 comp.cjam
$ wc -c image*.cjam
2131 image-1-0.5.cjam
2248 image-1-0.6.cjam
2346 image-1-0.7.cjam
2350 image-1-0.8.cjam
2446 image-1-0.9.cjam
3006 image-2-0.5.cjam
3718 image-2-0.6.cjam
3894 image-2-0.7.cjam
3356 image-2-0.8.cjam
4064 image-2-0.9.cjam
2949 image-3-0.5.cjam
2947 image-3-0.6.cjam
3582 image-3-0.7.cjam
3784 image-3-0.8.cjam
3745 image-3-0.9.cjam
2879 image-4-0.5.cjam
2887 image-4-0.6.cjam
3379 image-4-0.7.cjam
3615 image-4-0.8.cjam
3537 image-4-0.9.cjam
4427 image-5-0.5.cjam
4802 image-5-0.6.cjam
5536 image-5-0.7.cjam
6030 image-5-0.8.cjam
6111 image-5-0.9.cjam
89769 total
```
] |
[Question]
[
**This question already has answers here**:
[Mathematical Combination](/questions/1744/mathematical-combination)
(36 answers)
Closed 10 years ago.
Given two integers - n and r, your task is to calculate the combinatorial nCr.
```
nCr = n! / r! (n-r)!
```
The caveat is that you have to write code to do this calculation in minimum number of characters.
Input
The first line will be number of testcases T. Then T lines follow, each containing two positive integers - n and r.
output
Print T lines, each line containing the value of nCr.
Constraints
```
1 <= T <= 100
1 <= r <= n <= 1000
```
You can assume that the value nCr will fit into a signed 64 bit integer.
[Answer]
# Golfscript, 31 characters
```
n%(;{~.@.@-]{1\,{)*}/}%~/\/}%n*
```
Explanation:
* `n/(;{...}%n*` splits the input by a newline, discards the first row (number of testcases), maps the rest and finally joins by a newline.
+ `~.@.@-` evals the input, rearranges it to `r n n r`, then subtracts `r` from `n`.
+ `]{...}%~` collects everything on the stack into and array, maps it and explodes the array
- `1\,{)*}/` is the factorial function: push a `1` below the number, then create an array `0...n`, then for each element, multiply the accumulator by the value + 1. The map-reduce implementation is one char longer: `,{)}%{*}*`
+ `/\/` divides `n!` first by factorial of the difference, then by `r!`.
] |
[Question]
[
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, [visit the help center](/help/reopen-questions).
Closed 12 years ago.
Code a daily horoscope for the 12 zodiac signs, it needs to be self-sustained (no external ressources), quite randomized but fixed by zodiac sign for each day.
It needs to extract three "variables" from 1 to 3 :
1. love
2. work
3. money
Each one ranked from 1 to 3.
Ex. of variables that can be used (vars fixed for a day or more, can be extended) :
* Year
* Month
* Day
* Day of week
* Math.PI
* Zodiac signs order (from 1 to 12)
[Answer]
## Python, 106 chars
```
import time,zlib
for i in range(12):n=zlib.crc32(time.strftime('%%Y%%j%d'%i));print 1+n%3,1+n/3%3,1+n/9%3
```
Calculates the CRC of a string made up of the current year, day of year, and zodiac sign. Grabs some bits of the result for the horoscope.
[Answer]
From SO : "Add year+month\*11+day\*13+sign, feed this in as a seed to your local PRNG. After that you can either generate one "next random number" mod 27, extracting your 3 3s from there, or run it three times mod 3."
] |
[Question]
[
**This question already has answers here**:
[Simple cat program](/questions/62230/simple-cat-program)
(330 answers)
Closed 17 days ago.
The well known `cat` command simply copies its stdin directly to stdout unchanged. But there are plenty of other commandline tools that exist...
What other commands can be used to duplicate the functionality of the venerable `cat`?
# Rules
1. You are not allowed to use any *shell* features, including pipes, file redirection, variables, etc.
2. Your answer can only *directly* invoke one command - e.g. `foo-cmd; bar` is disallowed because you are directly invoking both `foo-cmd` and `bar` (not to mention, the use of a semicolon breaks rule 1). However, commands that internally execute other commands (such as `xargs`) **are** allowed.
3. The command you use should already exist and be at least somewhat widely known. And an explanation of nontrivial answers would also be nice.
4. This contest is not about finding a single "best" cat implementation, and as such will not have a single accepted answer. Rather, this is an exercise in creativity: how many different ways can we collectively implement `cat`?
# Solutions
So far, we have a `cat` implementation for the following commands (add yours to the list when you answer):
* [`awk`](https://codegolf.stackexchange.com/a/269635/112209)
* [`sed`](https://codegolf.stackexchange.com/a/269637/111474)
[Answer]
# [sed](https://en.wikipedia.org/wiki/sed)
```
sed ""
```
Plain old sed with an empty string.
[Answer]
# [awk](https://en.wikipedia.org/wiki/AWK)
```
awk '1{print}'
```
Explanation:
* `1` -> match every line.
* `{print}` -> for each matched line, print it
Or, more tersely:
```
awk 1
```
Here, a missing block implies `{print}`.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/268589/edit).
Closed last month.
[Improve this question](/posts/268589/edit)
# Challenge
This challenge is based on the domino effect:
**Initially, each domino is located on one straight line and is in a vertical state. It can be dropped either to the left along the same straight line, or to the right. Then this domino will knock down the next one, and that one, perhaps, the other.**
**The dominoes are each of different heights, and they are located at different distances.**
**Your task is to find the minimum number of dominoes that need to be knocked down manually.**
# Input
* The first line of the input data contains one integer `n (1≤n≤1000)` — the number of dominoes.
* The second line of the input contains `n` integers `x (1≤x≤10**9)` — the coordinates of dominoes. *It is sorted!*
* The third line of the input data contains `n` integers `h (1≤h<10**9)` — the heights of the dominoes.
# Output
* Output one number - the minimum number of dominoes that need to be knocked down manually.
# Tests
```
Input:
10
10 20 30 40 50 60 70 80 90 100
19 19 8 19 19 19 1 10 20 30
Output: 3
Input:
6
10 20 30 40 50 60
17 9 13 21 7 3
Output: 2
Input:
10
10 20 30 40 50 60 70 80 90 100
15 16 11 17 18 19 1 9 18 30
Output: 2
```
[](https://i.stack.imgur.com/d9Z5h.png)
(Geogebra visualisation. "P" means pass, -> or <- : demolition directions)
# Scoring
This is [fastest-algorithm](/questions/tagged/fastest-algorithm "show questions tagged 'fastest-algorithm'"), so the fastest algorithm scores the most. Here are the points based on your algorithm's complexity:
```
5 points for O(n!),
25 for O(x^n),
50 for O(n^x) where x≥3,
75 for O(n^x) where 2≤x<3,
80 for O(n*log(n)),
90 for O(n),
100 for O(n^x) where x<1, or O(log^x(n))
```
The first solution gets a 1.1 coefficient (already expired); a solution with an explanation may get extra points.
[Answer]
# Python 3 + Google OR-Tools, unknown complexity (probably exponential)
Uses a slightly modified set cover formulation.
```
from ortools.sat.python import cp_model
def min_push(positions, heights):
model = cp_model.CpModel()
push = [{} for _ in positions]
for i, (p, h) in enumerate(zip(positions, heights)):
for d in (-1, 1):
j = i + d
while 0 <= j < len(positions):
if abs(positions[j] - p) > h:
break
push[i][j] = model.NewIntVar(0, 1, f'push_{(i,j)}')
j += d
push_t = [{} for _ in positions]
for i, d in enumerate(push):
for j, v in d.items():
push_t[j][i] = v
for d in push_t:
model.Add(sum(d.values()) <= 1)
for i, d_i in enumerate(push):
for j, v_ij in d_i.items():
for k, v_jk in push[j].items():
if ((j - i) > 0) != ((k - j) > 0):
model.Add(v_ij + v_jk <= 1)
model.Maximize(sum(v for d in push for v in d.values()))
solver = cp_model.CpSolver()
solver.Solve(model)
return int(len(positions) - solver.ObjectiveValue())
```
[Answer]
# MATLAB
I was trying to rewrite @user1502040's Python 3 + Google OR-Tools Answer in MATLAB.
\$ \color{red}{\text{But there are some mistakes in my MATLAB code. Any help would be appreciated.}} \$
```
clear all;close all;clc;
positions = [10 20 30 40 50 60 70 80 90 100];
heights = [19 19 8 19 19 19 1 10 20 30];
minPushes = min_push(positions, heights);
disp(minPushes);
positions = [10 20 30 40 50 60];
heights = [17 9 13 21 7 3];
minPushes = min_push(positions, heights);
disp(minPushes);
positions = [10 20 30 40 50 60 70 80 90 100];
heights = [15 16 11 17 18 19 1 9 18 30];
minPushes = min_push(positions, heights);
disp(minPushes);
function minPushes = min_push(positions, heights)
% Number of dominoes
numDominoes = length(positions);
% Decision variables: push(i,j) is 1 if domino i pushes domino j, otherwise 0
push = optimvar('push', numDominoes, numDominoes, 'Type', 'integer', 'LowerBound', 0, 'UpperBound', 1);
% Create an optimization problem
problem = optimproblem('ObjectiveSense', 'maximize');
% Constraints for reachable pushes
for i = 1:numDominoes
for j = 1:numDominoes
if i ~= j
% Domino i can push domino j only if it's within reach
distance = abs(positions(j) - positions(i));
if distance <= heights(i)
% Constraint is satisfied implicitly by the definition of push variable
else
% Domino i cannot push domino j because it's out of reach
problem.Constraints.(['outOfReach_' num2str(i) '_' num2str(j)]) = push(i, j) == 0;
end
end
end
end
% Each domino is pushed at most once
for j = 1:numDominoes
problem.Constraints.(['pushOnce_' num2str(j)]) = sum(push(:, j)) <= 1;
end
% Prevent cycles in pushes
for i = 1:numDominoes
for j = 1:numDominoes
if i ~= j
for k = 1:numDominoes
if j ~= k && i ~= k
if ((j - i) > 0) ~= ((k - j) > 0)
problem.Constraints.(['noCycle_' num2str(i) '_' num2str(j) '_' num2str(k)]) = push(i, j) + push(j, k) <= 1;
end
end
end
end
end
end
% Objective: maximize the number of pushes
problem.Objective = sum(sum(push));
% Solve the problem using an integer linear programming solver
options = optimoptions('intlinprog','Display','off');
[sol, fval, exitflag, output] = solve(problem,'Options',options);
% Calculate the minimum number of dominoes that need to be pushed manually
minPushes = numDominoes - fval;
end
```
] |
[Question]
[
**This question already has answers here**:
[Parse nested absolute values](/questions/267296/parse-nested-absolute-values)
(6 answers)
Closed 2 months ago.
**Looking at
[Arnauld's answer](https://codegolf.stackexchange.com/questions/267297/parse-nested-absolute-values-2/267300#267300), it seems like this version is not really more difficult than the other version, so I made it an optional requirement of the other challenge**
*The absolute value of a number \$x\$ is normally written as \$|x|\$. The left and right side of the absolute value uses the same symbol, so it is not immediately obvious how to parse nested absolute values e.g. \$||1-2|+|3-|4-5|||\$*
Your goal is to parse such an expression containing nested absolute values:
The expression will be given as a string of characters.
For simplicity the expression will only contain single digit numbers (or letters if that is easier in your language),
the operators `+` and `-` (you can use any two distinct characters to represent these operations) and the symbol `|` for the left and right side of a absolute value.
To make the challenger not too easy, it is allowed for numbers to be directly adjacent to absolute values so (`2|3|` and `|2|3` both are valid expressions). See the [first version](https://codegolf.stackexchange.com/questions/267296/parse-nested-absolute-values) if you do not want to handle that case
Your output should be the same expression in a form that allows to determine how the absolute values are bracketed.
The output has to satisfy the following rules:
* The expression within a absolute value must not end with an operator ( `+` or `-` )
* The expression within a absolute value cannot be empty
* Each `|` has to be part of exactly one absolute value
You may assume there is a valid way to parse the given input. If there is more than one way to parse the expression you can choose any valid solution.
Examples (all possible outputs):
```
|2| -> (2)
|2|+|3| -> (2)+(3)
|2|3|-4| -> (2)3(-4)
|2|3|-4| -> (2(3)-4)
|2|3-|4| -> (2)3-(4)
||2|| -> ((2))
||2|-|3|| -> ((2)-(3))
|-|-2+3|| -> (-(-2+3))
|-|-2+3|+|4|-5| -> (-(-2+3)+(4)-5)
|-|-2+|-3|+4|-5| -> (-(-2+(-3)+4)-5)
||1-2|+|3-|4-5||| -> ((1-2)+(3-(4-5)))
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") the shortest solution wins.
[code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") [parsing](/questions/tagged/parsing "show questions tagged 'parsing'")
[Answer]
# JavaScript (ES6), 52 bytes
I believe [my answer to the other version](https://codegolf.stackexchange.com/a/267298/58563) also works for this one... ¯\\_(ツ)\_/¯
```
f=s=>s>(s=s.replace(/\|(.*?[\d)])\|/,"($1)"))?f(s):s
```
[Try it online!](https://tio.run/##ddFNDoIwEAXgvacgxMWMdSDyszFBDyIuCILRECDUuJq749SogJQu2/elfdN79sx03t3aB9XNpej7MtHJQR9AJ9rrirbK8gL8lMHbHE/pBc@Ysr91Yb1DF/FYgsa97vOm1k1VeFVzhRJcDth1JgvR8X3HgQBX86zicJwfsgpCWz5kikZgyIdAEZotGyJeQATR/BYR0w5fIMKaJnnWIEZpkhJzQUyBsgkCc7AslNSg2Lg/oaQGxQuOSeQHThyQSDvkHb3/RgYnTp76KyUH5m9kcOIQ@xc "JavaScript (Node.js) – Try It Online")
] |
[Question]
[
# History
There's a room on StackOverflow in Russian where you can see such an interesting discussion:
>
> [](https://i.stack.imgur.com/qytqN.png)
>
>
>
Just because there are not enough real discussing in that room, @Grundy "plays ping-pong" to keep it unfrozen.
# Task
Implement a bot for StackExchange that posts "ping!" to the 115624 room if the previous message was "pong!" \*\*(and posted by another user) and "pong!" if the previous message was "ping!" (and posted by another user).
If you need a login and a password for SE account, use `l` and `p`.
\*\*It should not reply to its own messages
# Rules
Code-golf: the shortest answer wins.
*Nice golfing!*
[Answer]
Nobody golfs... so:
# Python 3 — 330 byte
```
from chatexchange.client import Client
s=Client("stackexchange.com");s.login('l','p');r=s.get_room('115624');r.join();o=lambda e,_:r.send_message("ping!")if e.message.content_source=='pong!'and e.user.id!=483667 else r.send_message('pong!')if e.message.content_source=='ping!'and e.user.id!=483667 else 0;r.watch_socket(o)
while 1:0
```
] |
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win.
Closed 3 years ago.
[Improve this question](/posts/204772/edit)
If you are given an array of numbers between 1 and 100 and an integer `n`, you must remove any instances of an item that appear greater than `n` times.
For example:
```
In : [92, 41, 81, 47, 28, 92, 84, 92, 81], n = 1
Out: [92, 41, 81, 47, 28, 84]
```
The most aesthetic/simple algorithm wins. And since this is a [popularity-contest](/questions/tagged/popularity-contest "show questions tagged 'popularity-contest'"), you get to decide!
[Answer]
# [J](http://jsoftware.com/), 21 16 15 bytes
```
(>:+/@(={:)\)#]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/NeystPUdNGyrrTRjNJVj/2tyKXClJmfkKxgqpClYGukomBjqKFgAsYm5joKRhQ5YzMIEShtC1BoRp/Y/AA "J – Try It Online")
Overall, we make a boolean mask and apply it to the original list: `(...)#]`
To construct the mask, for each prefix `\` we sum `+/@` the number of times an element equals the last element of that prefix `(={:)`, which gives us a list the same size as the original, where each element holds the number of times the element has appeared so far. This is:
```
1 1 1 1 1 2 1 3 2
```
for the example list.
Then we check which elements are less than or equal `>:` to the left arg:
```
1 1 1 1 1 0 1 0 0
```
producing the mask we want.
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/181629/edit).
Closed 4 years ago.
[Improve this question](/posts/181629/edit)
Shortest program wins, of course.
[Answer]
# Wolfram Language 171 bytes
Any modern 13-year interval will have between 20 and 24 Friday the 13ths.
```
SortBy[{{#[[1,1]],#[[-1,1]]},Total[#[[2]]&/@#]}&/@Partition[Table[{y,Length@Cases[DateObject@{y,m,13}~Table~{m,12},x_/;DayName@x==Friday]},{y,1900,2019}],13,1],Last][[-1]]
* {{2007, 2019}, 24} *)
```
The above generates all the Friday the 13ths for each year between 1900 and 2019, partitions the results into intervals of 13 years, and finds the total for each such interval. The interval of 2007-2019 has 24, the maximum number of Friday the 13ths.
If 2019 cannot be used, the correct answer will be the interval of 200-2018, which also contains 24 Friday the 13ths.
] |
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
This site is for programming contests and challenges. **General programming questions** are off-topic here. You may be able to get help on [Stack Overflow](http://stackoverflow.com/about).
Closed 6 years ago.
[Improve this question](/posts/154180/edit)
## Specification
This challenge is simple to state: your input is a non-empty array of nonnegative integers, and your task is to partition it into as few substrings as possible, such that each substring is a permutation of a consecutive integer range.
More formally, if the input array is `A`, then the output is minimum number of partition of `A` into `B`(s):
* Each arrays `B` form a partition of `A` into substrings. Inductively, this means that either `B` is the singleton array containing 1 element from `A`, or the elements of `B` is a subsequence of `A`, which when sorted are contiguous like `x,x+1,x+2,..`.
* The number of arrays `B` is minimal.
## Example
Consider the input array `A = [1,2,3,4,3,5]`.
Output is `2`
One possible minimal partitions are `B = [1,2,3],[4,3,5]`. That's the only partition to 2 substrings.
`{4,3,5}` in sorted order is `{3,4,5}` which is contiguous.
## Input
An array of integers `A`.
## Output
A number, indicate the smallest number of parts `A` can be splitted to.
## Winning criteria
Your submissions will be scored in bytes, with less bytes being better.
[Answer]
# [Kotlin](https://kotlinlang.org), 91 bytes
```
fold(mutableListOf<Int>()){r,i->r.indexOfFirst{it<i}.let{if(it<0)r+=i else r[it]=i
r}}.size
```
## Beautified
```
fold(mutableListOf<Int>()) {r,i->
r.indexOfFirst { it<i }.let {
if (it<0) r+=i else r[it]=i
r
}
}.size
```
## Test
```
fun MutableList<Int>.f() =
fold(mutableListOf<Int>()){r,i->r.indexOfFirst{it<i}.let{if(it<0)r+=i else r[it]=i
r}}.size
fun main(args: Array<String>) {
val i = mutableListOf(1,2,3,4,3,5)
println(i.f())
}
```
## TIO
[TryItOnline](https://tio.run/##VY7NCsIwEITvfYo9JliLvxdpC14EQenBo3iImJTFNJXNVtTSZ6+xHsSBhRm+XXauNVt0fWQaB/uG1dnqHXpOt47zxAgJWW9qexHVjxVmoELKlmIc55Sgu+hHYTZInlvkFLvE6uCMCGEiaZQhaOs10BH5lGFEXZd4fOnv30qhE4pKv4I1kXqmByZ0ZS6hjSDoriwgZPDXQUzjWTyPF2GWcli7hSO2TuCnt4y6/g0)
[Answer]
## JavaScript (ES6), 82 bytes
```
f=(a,n=Math.min(...a),i=a.indexOf(n))=>1/a[0]?i<0?1+f(a):f(a,a.splice(i,1)[0]+1):1
```
[Answer]
# Haskell, 139 bytes
```
import Data.List
l=length
q(x:r)=map([x]:)(q r)++[(x:y):v|(y:v)<-q r]
q[]=[[]]
s(x:y)=x+l y==last(x:y)
f x=minimum[l y|y<-q x,all(s.sort)y]
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
Œ!Iċ€1ṀạL
```
[Try it online!](https://tio.run/##y0rNyan8///oJEXPI92PmtYYPtzZ8HDXQp////9HG@ooGOkoGOsomIBJ01gA "Jelly – Try It Online")
### How it works
```
Œ!Iċ€1ṀạL Main link. Argument: A (array)
Œ! Take all permutations of A.
I Increments; compute the forward differences of each permutation.
ċ€1 Count the number of 1's i each array of deltas.
Ṁ Take the maximum.
L Compute the length of A.
ạ Take the absolute value of the difference of the maximum and the length.
```
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/149524/edit).
Closed 6 years ago.
[Improve this question](/posts/149524/edit)
# Introduction
Mathematicians often work with number sets. These are groups of numbers that share common properties. These are number sets are, in order from most specific to most broad:
```
Natural numbers (symbol N): These are the counting numbers: 1, 2, 3, ...
Integers (symbol Z): These are all the numbers without a fractional part: ..., -3, -2, -1, 0, 1, 2, 3, ...
Rational numbers (symbol Q): These numbers are the quotients of two integers, such as: 1.1 (11/10), 5.67 (567/100), or 0.333333333... (1/3)
-----The following two numbers sets are equally specific in describing numbers-----
Real numbers (symbol R): These are positive, zero, and negative numbers, such as: π (3.1415926...), e (2.7182818...), or √2 (1.4142135...)
Imaginary numbers (symbol I): Numbers that give negative values when squared; for this reason they aren't very useful in everyday life.
These numbers contain the letter i in them, with i representing the √-1.
Examples: 2i, -1.5i 78i, 9i, -3.1415i, i
-----------------------------------------------------------------------------------
Complex numbers (symbol C): The sum of a real and an imaginary number in the form a + bi, examples: 2 + 7i, 3 + 3i, 1 - i, -8 + i
```
Note that when there is only a single `i`, it is not written `1i`.
# Challenge
Given a number from one of these number sets, print the symbol for the most specific number set that could describe it.
# Test cases
```
Input Output
73.0 -> N
4/2 -> N
-73 -> Z
-1/3 -> Q
0.56 -> Q
0.555... -> Q
0.123123123... -> Q
3.1415926535... -> R
-1.37i -> I
7892/5 + 23/4i -> C
```
# Other info
* Natural numbers and integers may be given with a decimal point followed by a string of zeros
* To add on to the previous point, any input that can be converted into a simpler form shall have its output corresponding to the simplified input
* Rational numbers may be given with a `/` to represent a fraction, or a sequence of numbers occurring 3 or more times followed by `...`
* Numbers ending with `...` represent repeated decimals or un-terminated decimal real numbers
* Any number sets less specific than `Q` can also have inputs be given as a fraction
* You do not need to handle repeated decimals or un-terminated decimals for number sets other than Q and R
* Any error caused by lack of precision in floating point numbers will not invalidate a submission
This is code golf, so shortest code wins. If there is something unclear, let me know in the comments' section or edit the question.
[Answer]
# JavaScript (ES6), ~~121~~ 110 bytes
```
s=>[...'QRCI'].find((_,i)=>[/(.+)\1\1\.\./,/\.\./,/.+[+-].*i/,/i/][i].test(s))||'QNZ'[k=eval(s),k%1?0:k>0?1:2]
```
### Test cases
```
let f =
s=>[...'QRCI'].find((_,i)=>[/(.+)\1\1\.\./,/\.\./,/.+[+-].*i/,/i/][i].test(s))||'QNZ'[k=eval(s),k%1?0:k>0?1:2]
console.log(f('73.0' )) // -> N
console.log(f('4/2' )) // -> N
console.log(f('-73' )) // -> Z
console.log(f('-1/3' )) // -> Q
console.log(f('0.56' )) // -> Q
console.log(f('0.555...' )) // -> Q
console.log(f('0.123123123...' )) // -> Q
console.log(f('3.1415926535...')) // -> R
console.log(f('-1.37i' )) // -> I
console.log(f('7892/5 + 23/4i' )) // -> C
```
### Formatted and commented
```
s => // given the input string s
[...'QRCI'].find( // we first apply some regular expressions:
(_, i) => [ // i = index
/(.+)\1\1\.\./, // i = 0 (Q): 3x the same pattern, followed by '..' -> rational
/\.\./, // i = 1 (R): '..' without the repeated pattern -> real
/.+[+-].*i/, // i = 2 (C): a real part +/- an imaginary part -> complex
/i/ // i = 3 (I): just an imaginary part -> imaginary
][i].test(s) // this is a find(), so we exit as soon as something matches
) || 'QNZ'[ // if all regular expressions failed:
k = eval(s), // assume the expression can now be safely evaluated as JS code
k % 1 ? // if there's a decimal part:
0 // -> rational
: // else:
k > 0 ? // if strictly positive:
1 // -> natural
: // else:
2 // -> integer
] //
```
] |
[Question]
[
**This question already has answers here**:
[Evaluate the primorial of a number [duplicate]](/questions/11719/evaluate-the-primorial-of-a-number)
(18 answers)
Closed 6 years ago.
For the purposes of this question, the prime factorial of a number n is the result of multiplying all prime numbers smaller than n, and then multiplying the result by n.
## Your Task:
Write a program or function to find the prime factorial of a number, as outlined above.
## Input:
An integer n where n is greater than one, and the prime factorial of n is smaller than the largest integer your language can support. However, remember [this standard loophole](https://codegolf.meta.stackexchange.com/a/8245/69331). Reasonable integer limits only.
## Output:
The prime factorial of the input.
## Test Cases:
```
4 -> 24
7 -> 210
32 -> 641795684160
```
## Scoring:
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), lowest score in bytes wins!
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
’ÆRP×
```
**[Try it online!](https://tio.run/##y0rNyan8//9Rw8zDbUEBh6f////fHAA "Jelly – Try It Online")**
## How?
```
’ÆRP× Full program.
’ Decrement.
ÆR Inclusive prime range.
P Product.
× Multiply by the input.
```
The non-built-in would be **7 bytes**: `’ÆPÐfP×`
[Answer]
# Pyth, 10 bytes
```
*Q*FfP_TSt
```
I'm pretty sure this can be golfed some more...
---
```
*Q*FfP_TSt Full program, takes input from stdin and outputs to stdout
*Q Implicitly output $input multiplied by
*F The product of
St(Q) All numbers less than $input (Q is added automtaically by Pyth)
fP_T As long as they are prime
```
[Answer]
# MATLAB/Octave, 23 bytes
```
@(n)prod(primes(n-1))*n
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mG/PfQSNPs6AoP0WjoCgzN7VYI0/XUFNTK@9/moaJJleahjmIMDbS/A8A)
] |
[Question]
[
**This question already has answers here**:
[Enumerate valid Brainf\*\*k programs](/questions/55363/enumerate-valid-brainfk-programs)
(3 answers)
Closed 6 years ago.
## Create a bijective function between the syntactically valid [BF programs](http://esolangs.org/wiki/Brainfuck) and the natural numbers
This means that you will assign each BF program a nonnegative integer (0,1,2,...) in such a way that each number gets a BF program without syntax errors (and without whitespace or comments).
Note that something like [Binaryf\*\*\*](http://esolangs.org/wiki/Binaryfuck), for two reasons. Both `+>` and `>` map to 2, and no valid program maps to `6` (since `[` is not a valid BF program).
You may either create two programs, one to map BF programs to numbers, one to map numbers to valid BF programs (which will be inverses) (in which case your score is the sum of their lengths), or you can create one program which does both tasks (in which case your score is just length of that one program).
**Note:** The program(s) must run in polynomial time (in terms of the length of the input). (This rule is to prevent boring brute force approaches.)
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest program(s) wins!
[Answer]
## Haskell, 215+242=457
I haven't significantly golfed this. Its more of a example.
From BF to number
```
c '>'=1
c '<'=2
c '+'=3
c '-'=4
c '.'=5
c ','=6
i 0 ""=0
i 0 ('[':t)=7+7*(i 1 t)
i 0 (h:t)=(c h)+7*(i 0 t)
i b (']':t)=0+8*(i (b-1) t)
i b ('[':t)=7+8*(i (b+1) t)
i b (h:t)=(c h)+8*(i b t)
main=interact(show.i 0)
```
From number to BF
```
c 1='>'
c 2='<'
c 3='+'
c 4='-'
c 5='.'
c 6=','
i 0 0=""
i 0 n = case divMod n 7 of
(m,0)->'[':i 1 (m-1)
(m,x)->(c x):i 0 m
i b n = case divMod n 8 of
(m,0)->']':i (b-1) m
(m,7)->'[':i (b+1) m
(m,x)->(c x):i b m
main=interact(i 0.read)
```
It works through a combination of [Bijective numeration](https://en.wikipedia.org/wiki/Bijective_numeration) and [Mixed radix](https://en.wikipedia.org/wiki/Mixed_radix).
The encoder has two modes: no unmatched brackets mode and unmatched brackets mode.
If there are no unmatched brackets, 0 maps to the empty program, and each of the characters `><+-.,[` is mapped to a number from 1 to 7. `]` is not included since a BF program can not have `]` until it an unmatched bracket. This digit becomes the least significant digit, and is in base 7.
Once there are unmatched brackets, the digits are in base 8, with `]` assigned to `0`. In particular, there is no number assigned to the ending the program (since you can not end the program while there are unmatched brackets). Once all brackets are matched, it returns to no unmatched brackets mode. To output `0` exactly while in this mode, you must match all brackets, and then end.
Example: `.-,.><++.,[>]` -> 4228460766 -> `.-,.><++.,[>]`
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/112634/edit).
Closed 6 years ago.
[Improve this question](/posts/112634/edit)
### Problem
Given a file with:
```
56 (65%), 33(75%), , 44, "“hello”,(5) world", goodbye
89 (25%), 33(75%), , 44, "hello world", goodbye
92 (97%), 33(75%), , 44, "hello world", goodbye
```
### Goal
Write back to that file with:
```
56, 33, , 44, "“hello”,(5) world", goodbye
89, 33, , 44, "hello world", goodbye
92, 33, , 44, "hello world", goodbye
```
### Example implementation [Python 518 bytes]
```
import csv
from sys import argv
from itertools import takewhile, imap
with open(argv[1], 'r+') as f0:
r = csv.reader(f0, delimiter=',', quotechar='"')
w = csv.writer(f0, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
rows = tuple(imap(lambda line: ''.join(
'{}\0'.format(''.join(
takewhile(lambda ch: ch != '(', col))).rstrip() for col in line), r))
f0.seek(0)
tuple(imap(lambda line: w.writerow(line.split('\0')), rows))
```
[Answer]
**Perl: 15 Bytes +1 for -p option**
```
s/ ?\([^,"]+//g
```
**Usage:**
```
perl -pe 's/ ?\([^,"]+//g' file.csv
```
] |
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/79568/edit).
Closed 7 years ago.
[Improve this question](/posts/79568/edit)
Goal: Create the smallest possible code to open a separate window, in which there are 100 circles of random sizes and colors.
Rules: All circles must be visible to the unassisted, naked eye, so in other words more than 2 pixels across, the background must be black, at least 5 different colors must be recognizable, and at all circles must fit within the window.
[Answer]
# Mathematica 106 bytes
The code is fairly straightforward. A palette is a floating window. The 100 circles are stored in an array. The first `r`yields coordinates; the second `r` yields a radius.
```
CreatePalette[{Graphics[Array[{RandomColor[],Disk[99~(r=RandomReal)~{2},r@5]}&,100],Background->Black]}]
```
[](https://i.stack.imgur.com/CumAz.png)
[Answer]
## Java, 352 Bytes
Yeah, I know, an applet, but still...
```
import java.applet.*;import java.awt.*;import java.util.*;public class C extends Applet{public void paint(Graphics a){Random b=new Random();int x,y,diameter;setBackground(Color.black);for(int c=1;c<=100;c++){a.setColor(new Color(b.nextInt(0xFFFFFF)));d=b.nextInt(getWidth()/10);x1=b.nextInt(getWidth());y1=b.nextInt(getHeight());a.drawOval(x,y,d,d);}}}
```
Ungolfed Code:
```
import java.applet.*;
import java.awt.*;
import java.util.*;
public class C extends Applet {
public void paint(Graphics a) {
Random b = new Random();
int x, y, d;
setBackground(Color.black);
for (int c = 1; c <= 100; c++) {
a.setColor(new Color(b.nextInt(0xFFFFFF)));
d = b.nextInt(getWidth() / 10);
x = b.nextInt(getWidth());
y = b.nextInt(getHeight());
a.drawOval(x, y, d, d);
}
}
}
```
[Answer]
# Python 2 PIL - 199 bytes
Making some assumptions of the rules based on OP's answer. Not optimally golfed in the sense that the image could be 5 pixels across and the circles could be all the same place with grayscale colors, but goes with the spirit of the rules.
```
import Image,ImageDraw,random
h=999
i=Image.new('RGB',(h,h))
g=random.randint
exec"r,x,y=g(0,50),g(0,h),g(0,h);ImageDraw.Draw(i).ellipse((x-r,y-r,x+r,y+r),(g(0,255),g(0,255),g(0,255)));"*100
i.show()
```
] |
[Question]
[
**This question already has answers here**:
[Enlarge ASCII art](/questions/19450/enlarge-ascii-art)
(38 answers)
Closed 7 years ago.
Your task is to write a program/function to scale up an image (list of strings) by a factor of `n`.
# Specs
* You will receive two inputs: an image, and a positive integer.
* The image will only contain ASCII printable characters (U+0020-U+007F).
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest solution in bytes wins.
# Testcases
### Testcase 1
```
abc
xyz
2
aabbcc
aabbcc
xxyyzz
xxyyzz
```
### Testcase 2
```
|_|
3
|||___|||
|||___|||
|||___|||
```
[Answer]
## Actually, 23 bytes
```
╗'
@s`╜;)*(Zk♂ΣiΣn`M'
j
```
Takes the string input (with newlines represented as `\n`s to make multi-line input work) as the first input and the integer as the second.
[Try it online!](http://actually.tryitonline.net/#code=4pWXJwpAc2DilZw7KSooWmvimYLOo2nOo25gTScKag&input=ImFiY1xueHl6Igoz)
Explanation (newlines replaced with `\n`):
```
╗'\n@s`╜;)*(Zk♂ΣiΣn`M'\nj
╗ push n to reg0
'\n@s split s on newlines
`╜;)*(Zk♂ΣiΣn`M for each line:
╜;)*(Z make n copies and zip them
k♂ΣiΣ join the strings ("abc" -> ["abc", "abc"] -> "aabbcc" with n = 2)
n make n copies of the result line
'\nj join on newline
```
] |
[Question]
[
**This question already has answers here**:
[Exponentiation of natural numbers using only primitive integer operations [duplicate]](/questions/54300/exponentiation-of-natural-numbers-using-only-primitive-integer-operations)
(8 answers)
[Multiply two numbers without using any numbers](/questions/40257/multiply-two-numbers-without-using-any-numbers)
(13 answers)
Closed 7 years ago.
# Challenge
Your goal is, given two positive integer numbers a and b, to calculate (and output) a ^ b without using either multiplication, division and the power itself (not directly, at least).
And, of course, built-in exponentiation functions.
# Scoring
This is code-golf, so the shorter, the better.
# Test cases
```
Input => Output
2, 3 => 8
5, 5 => 3125
100, 4 => 100000000
17, 9 => 118587876497
0, 1 => 0
3921, 0 => 1
```
[Answer]
# k (19 bytes)
This is slow and uses lots of memory:
```
{#,//(x#,:)/[y;0b]}
```
The `/`s are not division, it's the [converge](http://code.kx.com/wiki/Reference/Slash#converge) operator.
] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.