title: Is It Mountainous?

text:
# Question
Title: Is It Mountainous?
# Challenge

For this challenge, a mountainous string is one that conforms to the grammar rule `M: x(Mx)*` where at each production, the all x's are the same character. When indented, a mountainous string might look something like this:

```
A
 B
  C
   D
  C
   E
    F
   E
  C
 B
A

```

As you can see, it looks a bit like a mountain from the side.

# Formal Definition

* Any single character `a` is mountainous.
* If `S` is a mountainous string and `a` is a character, then `aSa` is mountainous, where juxtaposition represents string concatenation.
* If `aSa` and `aTa` are mountainous strings, then `aSaTa` is a mountainous string. Note that this rule implies that this pattern holds for any number of repetitions. (i.e. `aSaTaUa`, `aSaTaUaVa`, `aSaTaUaVaWa`... are all mountainous.)

# Examples

All odd-length palindromes are mountainous, for instance:

```
t
 a
  c
   o
  c
 a
t

```

`qwertytrasdfdgdsarewqjklkjq` is a less trivial example:

```
q
 w
  e
   r
    t
     y
    t
   r
    a
     s
      d
       f
      d
       g
      d
     s
    a
   r
  e
 w
q
 j
  k
   l
  k
 j
q

```

# Example Outputs

```
a                           ==> true
aaa                         ==> true
mom                         ==> true
tacocat                     ==> true
qwertytrasdfdgdsarewqjklkjq ==> true
wasitacaroraratisaw         ==> true
abcbcbcbcba                 ==> true
aaaaabcbbba                 ==> true

<empty string>              ==> false
aa                          ==> false
pie                         ==> false
toohottohoot                ==> false
asdfdghgfdsa                ==> false
myhovercraftisfullofeels    ==> false

```

# Rules

* This is a decision problem, so any representation of true or false is valid output as long as it is correct, consistent, unambiguous, and the program terminates in a finite amount of time. Be sure to state your output convention with your solution.
    + It should be trivial to determine whether the output indicates true or false without having to know what the input string is. Note that this does not mean the truthy or falsy outputs have to be constant, however the convention of "print a mountainous string if the string is mountainous and a non-mountainous string if not mountainous" is a banned loophole for obvious reasons.
    + On the other hand, a convention like "throws an exception for false and exits silently for true" would be fine, as well as "prints a single character for true and anything else for false"
* This is code golf, so the shortest program wins.
* Standard loopholes are banned.

# Answer
> 8 votes
# Japt v2, ~~14~~ 13 bytes

```
e/.).\1/_g
¥g

```

Test it online!

# Answer
> 8 votes
# Clean, ~~94~~ ~~89~~ ~~87~~ 80 bytes

```
import StdEnv
?[a,b,c:s]=[a: ?if(a==c)s[b,c:s]]
?l=l
$s=limit(iterate?s)==[hd s]

```

Try it online!

# Answer
> 6 votes
# Perl, 22 bytes

Includes `+` for `p`

```
perl -pe '$_=/^((.)((?1)\2)*)$/' <<< abcbcbcbcba

```

Prints 1 for true, nothing for false

# Answer
> 5 votes
# Brain-Flak, 78 bytes

```
({()<<>(([{}]({}))([{}]({}))<>[({}<>)])>{[()()]((<()>))}<{}{}{}<>>}(())){{}}{}

```

Try it online!

Prints 1 for true, nothing for false.

To verify a mountainous word, it is sufficient to assume the word goes "down" the mountain whenever possible.

# Answer
> 4 votes
# Prolog (SWI), 29 bytes

```
a-->[X],+X.
+X-->[];a,[X],+X.

```

Try it online!

This program defines a DCG rule `a//0` that matches any string (list of characters) that is a mountainous string.

## Explanation

For this program I use a slightly different but equivalent definition for mountainous strings than what is described in the challenge: A mountainous string is a character `c` followed by a number (could be zero) of mountainous strings with `c` tacked onto the ends of them. In a more terse regex derived notation, a mountainous string must match the pattern `c(Mc)*` where `M` is a mountainous string and `*` means that the expression in parentheses is repeated zero or more times. Note that while each `c` must be the same character, each `M` does not need to be the same mountainous string.

### Proof of Equivalence

It is clear that rules 1 and 2 from the challenge are equivalent to my rule where `Mc` occurs zero and one times respectively.

In the case that the mountainous string has `Mc` occurring `n` times where `n > 1` then the string can be rewritten as `cMcSc` where `S` is the latter `n - 1` times that `Mc` occurs excluding the last `c` (note that `M` is any mountainous string and not necessarily the same as other `M`). Since `M` is a mountainous string, by rule 2, `cMc` must be a mountainous string. Either `S` is a mountainous string in which case `cSc` is a mountainous string or `S` can be rewritten as `cMcTc` where `T` is the latter `n - 2` times that `Mc` occurs excluding the last `c`. This line of reasoning can keep on being applied until string not guaranteed to be mountainous contains `Mc` once which would mean it would have to be mountainous as well. Thus since `cMc` is mountainous and if `cMc` and `cM'c` are mountainous then `cMcM'c` must be mountainous the whole string must be mountainous.

For the converse, for a string `cScTc` where `cSc` and `cTc` are mountainous then either `cSc` is a mountainous string by rule 2 or by rule 3. If it is a mountainous string by rule 2 then `S` must also be a mountainous string. If it is a mountainous string by rule 3 then `cSc` must be of the form `cUcVc` where `cUc` and `cVc` are mountainous strings. Since the longer of `cUc` and `cVc` must still be at least two characters shorter than `cSc` and rule 3 requires at least 5 character to be applied then after a finite number of applications of rule 3 each string between the `c`s selected by applications of rule 3 must be a mountainous string. The same line of reasoning can be applied to `cTc` thus the string is mountainous by my definition.

Since any string that matches my definition is mountainous and my definition matches all mountainous strings, it is equivalent to the one given in the question.

### Explanation of Code

Overall the `a//0` DCG rule, defined on the first line, matches any mountainous string. The `+//1` DCG rule (like predicates, DCG rules can be give operator names), defined on line two, matches any string that is made up of a sequence of zero or more mountainous strings with the character passed as its arguments `X` tacked onto the ends of them. Or to borrow the regex-like notation I used above, `a//0` matches `c(Mc)*` but outsources the job of actually matching the `(Mc)*` to `+//1` which takes `c` as its argument `X`.

Line by line the codes behaves as follows:

```
a-->[X],+X.

```

This line defines the DCG rule `a`. The `[X]` states that the first character must be equal to the currently undefined variable `X`. This results in `X` being set equal to the first character. The `+X` then states that the rest of the string must match the DCG rule `+//1` with the character that `X` is set to as its argument.

```
+X-->[];a,[X],+X.

```

This line defines the `+//1` DCG rule. The `;` represents an or in Prolog which means that the string can match either `[]` or `a,[X],+X`. The `[]` represents the empty string so `+//1` is always capable of matching the empty string. If the string is not empty then the start of it must match `a//0` and so must be a mountainous string. This must then be followed by whatever character `X` is set to. Finally the rest of the string must match `+X`.

# Answer
> 3 votes
# Python 2, ~~89~~ 83 bytes

```
f=lambda s:re.search(M,s)and f(re.sub(M,r'\1',s))or len(s)==1
import re;M=r'(.).\1'

```

Try it online!

Thanks to ovs for 6 bytes.

# Answer
> 2 votes
# Husk, 15 bytes

```
εωφΓ§?t·:⁰`(=←t

```

Try it online! Type inference takes about 40 seconds, so be patient.

## Explanation

```
εωφΓ§?t·:⁰`(=←t  Implicit input, say s = "abacdca"
 ω               Apply until fixed point is reached
  φ              this self-referential anonymous function (accessed with ⁰):
                  Argument is a string x.
   Γ              Deconstruct x into head h and tail t.
    §?t·:⁰`(=←t   Call this function on h and t. It is interpreted as §(?t)(·:⁰)(`(=←t)).
                  § feeds h to (·:⁰) and (`(=←t)), and calls (?t) on the results.
                  The semantics of ? cause t to be fed to all three functions.
          `(=←t   First, check whether h equals the first element (←) of the tail of t.
     ?t           If it does (e.g. if h='a' and t="bacdca"), return tail of t ("acdca").
                  Otherwise (e.g. if h='b' and t="acdca"),
       · ⁰        call the anonymous function recursively on t: "aca"
        :         and prepend h to the result: "baca".
                 Final result is "a".
ε                Is it a 1-element string? Implicitly print 0 or 1.

```

The idea is to repeatedly replace a substring of the form `aba` with `a` until this is no longer possible. The input is mountainous if and only if this results in a single-character string (which is what `ε` tests). The only dangerous situation is when we have a string like this, where `aba` doesn't seem to be a peak:

```
a
 b
  a
   c
  a
   d
  a
 b
a

```

Fortunately, we can always transform it into one:

```
a
 b
a
 c
a
 d
a
 b
a

```

# Answer
> 2 votes
# Retina 0.8.2, 15 bytes

```
+`(.).\1
$1
^.$

```

Try it online! Trivial port of @ETHproductions' Japt answer.

# Answer
> 2 votes
# JavaScript (Node.js), 53 bytes

I suppose this is nearly the most straightforward method to do so?

```
f=s=>(w=s.replace(/(.).\1/,"$1"))==s?w.length==1:f(w)

```

Try it online!

# JavaScript (Node.js), 72 bytes

Less trivial one, but much longer.

```
s=>[...s].reduce((a,x)=>(a[a.length-2]==x?a.pop():a.push(x),a),[])==s[0]

```

Try it online!

---
Tags: code-golf, string, decision-problem
---


title: Implement the Boids algorithm

text:
# Question
Title: Implement the Boids algorithm
# Introduction

The Boids Algorithm is a relatively simple demonstration of emergent behavior in a group. It has three main rules, as described by its creator, Craig Reynolds:

> The basic flocking model consists of three simple steering behaviors which describe how an individual boid maneuvers based on the positions and velocities its nearby flockmates:
>
> * **Separation**: steer to avoid crowding local flockmates.
> * **Alignment**: steer towards the average heading of local flockmates.
> * **Cohesion**: steer to move toward the average position of local flockmates.
>
> Each boid has direct access to the whole scene's geometric description, but flocking requires that it reacts only to flockmates within a certain small neighborhood around itself. The neighborhood is characterized by a distance (measured from the center of the boid) and an *angle*, measured from the boid's direction of flight. Flockmates outside this local neighborhood are ignored. The neighborhood could be considered a model of limited perception (as by fish in murky water) but it is probably more correct to think of it as defining the region in which flockmates influence a boids steering.

I am not perfect when explaining things, so I highly recommend checking out the source. He also has some super informative pictures on his site.

# Challenge

Given the number of boids (simulated entities) and the number of frames, output an animation of the simulation.

* The boids should be rendered as a red circle, with a line inside of the circle showing its heading, which is the direction the boid is pointing in:

* The angle of each boid (as described by Reynolds) should be a full 300 degrees. (not 360)
* The starting heading and position of each boid should be uniformly random (but seeded, so that the output is still determinate), as well as the position.
* If the radius of the boid is 1, than the radius of the neighborhood should be 3.
* The number of boids will be anywhere from 2-20.
* The number of frames will be anywhere from 1-5000
* The animation should be played with a minimum of 10 milliseconds per frame and a maximum of 1 second times the number of boids. (2 boids = 2 seconds per frame max, 3 boids = 3 seconds per frame max, et cetera)
* The output animation should be at least 5 boid-radii by 5 boid-radii, times half the number of boids. So, the minimum size for 2 boids would be 10 boid-radii by 10 boid-radii, the minimum for 3 boids would be 15 boid-radii by 15 boid-radii, et cetera.
* The radius of each boid must be a minimum of 5 pixels and a maximum of 50 pixels.
* The speed of each boid needs to be limited so that it doesn't move more than 1/5th of its radius in one frame.
* The output needs to be determinate, so that the same input will produce the same output if run multiple times.
* If a boid reaches a border, it should wrap back to the other side. Likewise, the neighborhood around each boid should also wrap around the borders.

## Rules for the algorithm

In this case, each boid has a sector around it spanning 300 degrees, centered on the boid's heading. Any other boids in this "neighborhood" are considered "neighbors", or (to use Reynolds' term) "flockmates".

1. Each boid should adjust its heading to avoid collisions and maintain a comfortable distance of one boid-radius with its neighbors. (This is the "Separation" aspect of the algorithm. The one boid-radius may be bypassed, but it should be like a rubber band, snapping back into place.)
2. Each boid should additionally adjust its heading to be closer to the average heading of the other boids in its neighborhood, as long as it doesn't interfere with the first rule. (This is the "Alignment" aspect of the algorithm)
3. Each boid should turn itself towards the average position of its flockmates, as long as this doesn't cause collision or significantly interfere with the second rule.

In his paper on the subject, he explains this as follows:

> To build a simulated flock, we start with a boid model that supports geometric flight. We add behaviors that correspond to the opposing forces of collision avoidance and the urge to join the flock. Stated briefly as rules, and in order of decreasing precedence, the behaviors that lead to simulated flocking are:
>
> * Collision Avoidance: avoid collisions with nearby flockmates
> * Velocity Matching: attempt to match velocity with nearby flockmates
> * Flock Centering: attempt to stay close to nearby flockmates

## More detailed description of movement:

* The standard implementation of the Boids Algorithm usually does a calculation for each of the rules, and merges it together.
* For the first rule, the boid goes through the list of neighboring boids within its neighborhood, and if the distance between itself and the neighbor is less than a certain value, a vector pushing the boid away from is neighbor is applied to the boid's heading.
* For the second rule, the boid calculates the average heading of its neighbors, and adds a small portion (we'll use 1/10 in this challenge) of the difference between its current heading and the average heading to its current heading.
* For the third and final rule, the boid averages the positions of its neighbors, calculates a vector that points towards this location. This vector is multiplied by an even smaller number than what was used for rule 2 (for this challenge, 1/50 will be used) and applied to the heading.
* The boid is then moved in the direction of its heading

Here is a helpful pseudocode implementation of the Boids Algorithm.

# Example Input and Output

Input:
> 5, 190 (5 boids, 190 frames)

Output:
>

# Winning criterion

This is , so the smallest solution in bytes wins.

# Answer
> 8 votes
# Processing 3.3.6 (Java), ~~932~~ ~~931~~ ~~940~~ ~~928~~ ~~957~~ ~~917~~ 904 bytes

<sup> -1 byte from Jonathan Frech
+11 bytes to better match the spec
-2 bytes from Kevin Cruijssen
-12 bytes for changing args to t()
+29 bytes because I was doing ghosting wrong, see commented version below
-40 bytes for using for loops instead of separate calls for each ghost
-13 bytes for using default frameRate, 30
</sup>

Well, it's a start, for someone who doesn't Java-golf. :)

```
int n=15,f=400,i,j,z=255,w=500;float d=200./n;PVector m;B[]a=new B[n];void setup(){size(500,500);fill(z,0,0);randomSeed(n);for(i=0;i<n;a[i++]=new B(new PVector(random(w),random(w)),m.fromAngle(random(TAU))));}void draw(){background(z);for(B b:a)b.u();if(frameCount%f<1)setup();}class B{PVector p,v,e,q,r;ArrayList<B>n;B(PVector m,PVector o){p=m;v=o;}void u(){e=v.copy();n=new ArrayList();for(B b:a){if(b!=this)for(i=-w;i<=w;i+=w)for(j=-w;j<=w;j+=w)t(i,j,b);}if(n.size()>0){q=new PVector();r=q.copy();for(B b:n){q.add(b.v);r.add(b.p);if(p.dist(b.p)<=d)e.add(p).sub(b.p);}e.add(q.div(n.size()).sub(v).div(10));e.add(r.div(n.size()).sub(p).div(50));}p.add(e.limit(d/10));v=e.mult(10);p.set((p.x+w)%w,(p.y+w)%w);noStroke();ellipse(p.x,p.y,d,d);stroke(0,0,z);line(p.x,p.y,p.x+v.x,p.y+v.y);}void t(int x,int y,B o){m=o.p.copy().add(x,y);if(2*d>=p.dist(m)&q.angleBetween(v,q.sub(m,p))<=5*PI/6)n.add(new B(m,o.v));}}

```

I don't know any reasonable way to do input in Processing, so the first two variables are the inputs (and I didn't count their values (5 bytes) toward the byte count). If this is a problem, I can try other things.

I also don't know of a good way to allow trying it online (the Processing.js project can't deal with this code style) without hosting things myself; and that is something I'm not eager to attempt. Let me know if there is anything clever I can do.

# Formatted code, with comments

```
int n=15, // Number of boids
    f=400, // Number of frames
    i,j,z=255,w=500; // temp*2, and two constants
float d=200./n; // Boid diameter
PVector m; // temp
B[]a=new B[n];
void setup(){ // This is automatically called at startup
  size(500,500); // Can't use variables for this without extra bytes for settings()
  fill(z,0,0);
  randomSeed(n); // seeded from number of Boids, so that n=19 is very different from n=20
  for(i=0;i<n;a[i++]=new B(new PVector(random(w),random(w)),m.fromAngle(random(TAU))));
}
void draw(){ // This is automatically called each frame
  background(z);
  for(B b:a)
    b.u();
  if(frameCount%f<1) // When desired frames length is hit, reset everything.
    setup();         // Could also use noLoop() instead of setup() to just stop instead.
                     // Or, remove this if statement altogether to go on to infinity.
}
class B{ // Boid
  PVector p,v,e,q,r; // Position, Velocity, Next velocity, and two temp vectors
  ArrayList<B>n; // List of neighbors
  B(PVector m,PVector o){
    p=m;
    v=o;
  }
  void u(){ // Update function, does rules and redraw for this Boid
    e=v.copy();
    n=new ArrayList();
    for(B b:a){ // Test a Boid and its eight ghosts for neighborship
      if(b!=this) // Note: Assumes neighborhood diameter < min(width,height)
        // The ghosts are to check if it'd be closer to measure by wrapping
        // We need eight for wrapping north, east, south, west, northeast,
        // northwest, southeast, and southwest. And also the non-wrapped one.
        // The above assumption ensures that each ghost is further apart than
        // the neighborhood diameter, meaning that only one neighbor might be
        // found for each boid. To test this, place a boid in each corner, right
        // to the edge, facing away from center. Each boid should find three
        // neighbors, that are the three other boids.
        for(i=-w;i<=w;i+=w)for(j=-w;j<=w;j+=w)t(i,j,b);
    }
    if(n.size()>0){
      q=new PVector();
      r=q.copy();
      for(B b:n){
        q.add(b.v); // Velocity matching, pt 1
        r.add(b.p); // Flock centering, pt 1
        if(p.dist(b.p)<=d)
          e.add(p).sub(b.p); // Collision avoidance
      }
      e.add(q.div(n.size()).sub(v).div(10)); // Velocity matching, pt 2
      e.add(r.div(n.size()).sub(p).div(50)); // Flock centering, pt 2
    }
    p.add(e.limit(d/10)); // Update vectors
    v=e.mult(10);
    p.set((p.x+w)%w,(p.y+w)%w); // Wrapping
    noStroke();
    ellipse(p.x,p.y,d,d); // Draw Boid, finally
    stroke(0,0,z);
    line(p.x,p.y,p.x+v.x,p.y+v.y);
  }
  void t(int x,int y,B o){ // Test if a Boid (or a ghost) is a neighbor
    m=o.p.copy().add(x,y);
    if(2*d>=p.dist(m)&q.angleBetween(v,q.sub(m,p))<=5*PI/6)
      n.add(new B(m,o.v));
  }
}

```

## Sample output

n = 15, frames = 400:

Or, the same animation, but showing the neighborhood of each boid.

# Answer
> 4 votes
# JavaScript (ES6) + HTML5, 1200 bytes

Here's my current solution using the Canvas API. The `eval()` returns a curried function whose first input is the `Boid` population, and second is the number of animation frames. You can use `Infinity` for continuous animation.

The `eval(...)` is 1187 bytes and `<canvas id=c>` is 13 bytes, making a total of 1200. The CSS is unnecessary, but for convenience, it allows you to see the edges of the canvas.

```
eval("L7F7{function B8{t=this,t.a=o8*T,t.x=o8*S,t.y=o8*S}C=this.c,D=C.getContext`2d`,({abs:z,random:o,atan2:k,cos:u,sin:g,PI:P,T=2*P,G={c:_7A[r='filter'](b7b!=t)[i](9)79)),n:_7A[r](b7b!=t)[i](9)7({a,x,y:y-S})),s:_7A[r](b7b!=t)[i](9)7({a,x,y:y+S})),e:_7A[r](b7b!=t)[i](9)7({a,x:x-S,y})),w:_7A[r](b7b!=t)[i](9)7({a,x:x+S,y}))},M=I7[I,I+T,I-T][p]((a,x)7z(x)<z(a)?x:a)}=Math),B.prototype={d8{with(D)save8,translate(x,y),rotate(a),beginPath8,arc(0,0,5,0,T),fillStyle='red',fill8,beginPath8,moveTo(0,0),lineTo(10,0),strokeStyle='blue',stroke8,restore8},n:_7(({c,n,s,e,w}=G),c8.concat(n8,s8,e8,w8)[r](b7(d=b.x-x,f=b.y-y,400>d*d+f*f&&z(z(k(f,d)-a)/P-1)>1/6))),s8{q=(j=t.n8).length,v=t.v8||0,l=t.l8||0,f=t.f8||0,a=t.a=(t.a+v+l/10+f/50)%T,t.x=(x+u(a)+S)%S,t.y=(y+g(a)+S)%S},v:_7([d,f]=j[r](b7225>(b.x-x)**2+(b.y-y)**2)[p='reduce'](([d,f],b)7[x+d-b.x,y+f-b.y],[0,0]),d||f?M(k(f,d)-a):0),l:_7j[i](b7M(b.a-a))[p]((a,x)7a+x,0)/q,f:_7([d,f]=j[p](([d,f],b)7[d+b.x,f+b.y],[-x*q,-y*q]),d||f?M(k(f,d)-a):0)},S=C.width=C.height=50*L,A=Array(L).fill().map(_7new B),R=_7{D.clearRect(0,0,S,S),A[i='map'](b79=b).d8),A[i](b79=t=b).s8),F--&&setTimeout(R,10)},R8}".replace(/[789]/g,m=>['=>','()','({a,x,y}'][m-7]))
(10)(Infinity)
```

```
canvas{border:1px solid}
```

```
<canvas id=c>
```

### Edit

As requested, another snippet with an input for Boid population:

```
b.onchange=()=>{eval("L7F7{function B8{t=this,t.a=o8*T,t.x=o8*S,t.y=o8*S}C=this.c,D=C.getContext`2d`,({abs:z,random:o,atan2:k,cos:u,sin:g,PI:P,T=2*P,G={c:_7A[r='filter'](b7b!=t)[i](9)79)),n:_7A[r](b7b!=t)[i](9)7({a,x,y:y-S})),s:_7A[r](b7b!=t)[i](9)7({a,x,y:y+S})),e:_7A[r](b7b!=t)[i](9)7({a,x:x-S,y})),w:_7A[r](b7b!=t)[i](9)7({a,x:x+S,y}))},M=I7[I,I+T,I-T][p]((a,x)7z(x)<z(a)?x:a)}=Math),B.prototype={d8{with(D)save8,translate(x,y),rotate(a),beginPath8,arc(0,0,5,0,T),fillStyle='red',fill8,beginPath8,moveTo(0,0),lineTo(10,0),strokeStyle='blue',stroke8,restore8},n:_7(({c,n,s,e,w}=G),c8.concat(n8,s8,e8,w8)[r](b7(d=b.x-x,f=b.y-y,400>d*d+f*f&&z(z(k(f,d)-a)/P-1)>1/6))),s8{q=(j=t.n8).length,v=t.v8||0,l=t.l8||0,f=t.f8||0,a=t.a=(t.a+v/3+l/10+f/50)%T,t.x=(x+u(a)+S)%S,t.y=(y+g(a)+S)%S},v:_7([d,f]=j[r](b7225>(b.x-x)**2+(b.y-y)**2)[p='reduce'](([d,f],b)7[x+d-b.x,y+f-b.y],[0,0]),d||f?M(k(f,d)-a):0),l:_7j[i](b7M(b.a-a))[p]((a,x)7a+x,0)/q,f:_7([d,f]=j[p](([d,f],b)7[d+b.x,f+b.y],[-x*q,-y*q]),d||f?M(k(f,d)-a):0)},S=C.width=C.height=50*L,A=Array(L).fill().map(_7new B),R=_7{D.clearRect(0,0,S,S),A[i='map'](b79=b).d8),A[i](b79=t=b).s8),F--&&setTimeout(R,10)},R8}".replace(/[789]/g,m=>['=>','()','({a,x,y}'][m-7]))(+b.value)(Infinity);b.remove()}
```

```
input{display:block}canvas{border:1px solid}
```

```
<input id=b><canvas id=c>
```

---
Tags: code-golf, graphical-output, animation, simulation
---


title: How many draws are there in Quarto?

text:
# Question
Title: How many draws are there in Quarto?
# Introduction

This challenge is similar to Project Euler problems. I came up with it because I was playing a deceivingly simple board game and couldn't come up with an efficient solution to answer a simple question about its mechanics.

Quarto is a fun variant of 4 in a row. It is played on a 4 by 4 board with 16 unique pieces (no pieces are duplicated). Every turn each player places 1 piece on the board. Each piece has 4 binary characteristics (short/tall, black/white, square/circular, hollow/solid). The goal is to make four in a row, either horizontally, vertically or along the 2 diagonals, for any of the four characteristics! So 4 black pieces, 4 white pieces, 4 tall pieces, 4 short pieces, 4 square pieces, 4 circular pieces, 4 hollow pieces or 4 solid pieces.

The picture above shows a finished game, there is a four in a row because of 4 square pieces.

# Challenge

In Quarto, some games may end in a draw.

The total number of possible end positions is `16!`, about 20 trillion.

***How many of those end positions are draws?***

# Rules

1. The solution must be a program that **calculates** and outputs the total number of end positions that are draws. The correct answer is `414298141056`
2. You may only use information of the rules of the game that have been deduced manually (no computer assisted proof).
3. Mathematical simplifications of the problem are allowed, but must be explained and proven (manually) in your solution.
4. The winner is the one with the most optimal solution in terms of CPU running time.
5. *To determine the winner, I will run every single solution with a reported running time of less than 30m on a MacBook Pro 2,5 GHz Intel Core i7 with 16 GB RAM*.
6. No bonus points for coming up with a solution that also works with other board sizes. Even though that would be nice.
7. If applicable, your program must compile within 1 minute on the hardware mentioned above (to avoid compiler optimization abuse)
8. Default loopholes are not allowed

# Submissions

Please post:

1. The code or a github/bitbucket link to the code.
2. The output of the code.
3. Your locally measured running time
4. An explanation of your approach.

# Deadline

The deadline for submissions is March 1st, so still plenty of time.

# Answer
> 3 votes
# C: 414298141056 draws found in about 5 2.5 minutes.

Just simple depth-first search with a symmetry-aware transposition table. We use the symmetry of attributes under permutation and the 8-fold dihedral symmetry of the board.

```
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

typedef uint16_t u8;
typedef uint16_t u16;
typedef uint64_t u64;

#define P(i, j) (1 << (4 * (i) + (j)))

#define DIAG0 (P(0, 0) | P(1, 1) | P(2, 2) | P(3, 3))
#define DIAG1 (P(3, 0) | P(2, 1) | P(1, 2) | P(0, 3))

u64 rand_state;

u64 mix(u64 x) {
    u64 a = x >> 32;
    u64 b = x >> 60;
    x ^= (a >> b);
    return x * 7993060983890856527ULL;
}

u64 rand_u64() {
    u64 x = rand_state;
    rand_state = x * 6364136223846793005ULL + 1442695040888963407ULL;
    return mix(x);
}

u64 ZOBRIST_TABLE[(1 << 16)][8];

u16 transpose(u16 x) {
    u16 t = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (x & P(j, i)) {
                t |= P(i, j);
            }
        }
    }
    return t;
}

u16 rotate(u16 x) {
   u16 r = 0;
   for (int i = 0; i < 4; i++) {
       for (int j = 0; j < 4; j++) {
           if (x & P(3 - j, i)) {
                r |= P(i, j);
            }
       }
   }
   return r;
}

void initialize_zobrist_table(void) {
    for (int i = 0; i < 1 << 16; i++) {
        ZOBRIST_TABLE[i][0] = rand_u64();
    }
    for (int i = 0; i < 1 << 16; i++) {
        int j = i;
        for (int r = 1; r < 8; r++) {
            j = rotate(j);
            if (r == 4) {
                j = transpose(i);
            }
            ZOBRIST_TABLE[i][r] = ZOBRIST_TABLE[j][0];
        }
    }
}

u64 hash_board(u16* x) {
    u64 hash = 0;
    for (int r = 0; r < 8; r++) {
        u64 h = 0;
        for (int i = 0; i < 8; i++) {
            h += ZOBRIST_TABLE[x[i]][r];
        }
        hash ^= mix(h);
    }
    return mix(hash);
}

u8 IS_WON[(1 << 16) / 8];

void initialize_is_won(void) {
    for (int x = 0; x < 1 << 16; x++) {
        bool is_won = false;
        for (int i = 0; i < 4; i++) {
            u16 stride = 0xF << (4 * i);
            if ((x & stride) == stride) {
                is_won = true;
                break;
            }
            stride = 0x1111 << i;
            if ((x & stride) == stride) {
                is_won = true;
                break;
            }
        }
        if (is_won == false) {
            if (((x & DIAG0) == DIAG0) || ((x & DIAG1) == DIAG1)) {
                is_won = true;
            }
        }
        if (is_won) {
            IS_WON[x / 8] |= (1 << (x % 8));
        }
    }
}

bool is_won(u16 x) {
    return (IS_WON[x / 8] >> (x % 8)) & 1;
}

bool make_move(u16* board, u8 piece, u8 position) {
    u16 p = 1 << position;
    for (int i = 0; i < 4; i++) {
        bool a = (piece >> i) & 1;
        int j = 2 * i + a;
        u16 x = board[j] | p;
        if (is_won(x)) {
            return false;
        }
        board[j] = x;
    }
    return true;
}

typedef struct {
    u64 hash;
    u64 count;
} Entry;

typedef struct {
    u64 mask;
    Entry* entries;
} TTable;

Entry* lookup(TTable* table, u64 hash, u64 count) {
    Entry* to_replace;
    u64 min_count = count + 1;
    for (int d = 0; d < 8; d++) {
        u64 i = (hash + d) & table->mask;
        Entry* entry = &table->entries[i];
        if (entry->hash == 0 || entry->hash == hash) {
            return entry;
        }
        if (entry->count < min_count) {
            min_count = entry->count;
            to_replace = entry;
        }
    }
    if (to_replace) {
        to_replace->hash = 0;
        to_replace->count = 0;
        return to_replace;
    }
    return NULL;
}

u64 count_solutions(TTable* ttable, u16* board, u8* pieces, u8 position) {
    u64 hash = 0;
    if (position <= 10) {
        hash = hash_board(board);
        Entry* entry = lookup(ttable, hash, 0);
        if (entry && entry->hash) {
            return entry->count;
        }
    }
    u64 n = 0;
    for (int i = position; i < 16; i++) {
        u8 piece = pieces[i];
        u16 board1[8];
        memcpy(board1, board, sizeof(board1));
        u8 variable_ordering[16] = {0, 1, 2, 3, 4, 8, 12, 6, 9, 5, 7, 13, 10, 11, 15, 14};
        if (!make_move(board1, piece, variable_ordering[position])) {
            continue;
        }
        if (position == 15) {
            n += 1;
        } else {
            pieces[i] = pieces[position];
            n += count_solutions(ttable, board1, pieces, position + 1);
            pieces[i] = piece;
        }
    }
    if (hash) {
        Entry* entry = lookup(ttable, hash, n);
        if (entry) {
            entry->hash = hash;
            entry->count = n;
        }
    }
    return n;
}

int main(void) {
    TTable ttable;
    int ttable_size = 1 << 28;
    ttable.mask = ttable_size - 1;
    ttable.entries = calloc(ttable_size, sizeof(Entry));
    initialize_zobrist_table();
    initialize_is_won();
    u8 pieces[16];
    for (int i = 0; i < 16; i++) {pieces[i] = i;}
    u16 board[8] = {0};
    printf("count: %lu\n", count_solutions(&ttable, board, pieces, 0));
}

```

Measured score (@wvdz):

```
$ clang -O3 -march=native quarto_user1502040.c
$ time ./a.out
count: 414298141056

real    1m37.299s
user    1m32.797s
sys     0m2.930s

```

Score (user+sys): 1m35.727s

# Answer
> 1 votes
# Java, 414298141056 draws, 23m42.272s

I hope it's not frowned upon to post a solution to one's own challenge, but the reason that I posted this challenge in the first place was that it drove me crazy that I couldn't come up with an efficient solution myself. My best try would take days to complete.

After studying user1502040's answer I actually managed to modify my code to run within a somewhat reasonable time. My solution is still significantly different, but I did steal some ideas:

* Instead of focusing on end positions, I focus on actually playing the game, putting one piece after another on the board. This allows me to build a table of semantically identical positions with the correct count.
* Realizing the order in which pieces are placed matters: they should be placed such that you maximize the chance of an early win.

The main difference between this solution and user1502040's is that I don't use a Zobrist table, but a canonical representation of a board, where I consider each board to have 48 possible transpositions over the characteristics (2 * 4!). I don't rotate or transpose the whole board, but just the characteristics of the pieces.

This is the best I could come up with. Ideas for obvious or less obvious optimizations are most welcome!

```
public class Q {

    public static void main(String[] args) {
        System.out.println(countDraws(getStartBoard(), 0));
    }

    /** Order of squares being filled, chosen to maximize the chance of an early win */
    private static int[] indexShuffle = {0, 5, 10, 15, 14, 13, 12, 9, 1, 6, 3, 2, 7, 11, 4, 8};

    /** Highest depth for using the lookup */
    private static final int MAX_LOOKUP_INDEX = 10;

    public static long countDraws(long board, int turn) {
        long signature = 0;
        if (turn < MAX_LOOKUP_INDEX) {
            signature = getSignature(board, turn);
            if (cache.get(turn).containsKey(signature))
                return cache.get(turn).get(signature);
        }
        int indexShuffled = indexShuffle[turn];
        long count = 0;
        for (int n = turn; n < 16; n++) {
            long newBoard = swap(board, indexShuffled, indexShuffle[n]);
            if (partialEvaluate(newBoard, indexShuffled))
                continue;
            if (turn == 15)
                count++;
            else
                count += countDraws(newBoard, turn + 1);
        }
        if (turn < MAX_LOOKUP_INDEX)
            cache.get(turn).put(signature, count);
        return count;
    }

    /** Get the canonical representation for this board and turn */
    private static long getSignature(long board, int turn) {
        int firstPiece = getPiece(board, indexShuffle[0]);
        long signature = minTranspositionValues[firstPiece];
        List<Integer> ts = minTranspositions.get(firstPiece);
        for (int n = 1; n < turn; n++) {
            int min = 16;
            List<Integer> ts2 = new ArrayList<>();
            for (int t : ts) {
                int piece = getPiece(board, indexShuffle[n]);
                int posId = transpositions[piece][t];
                if (posId == min) {
                    ts2.add(t);
                } else if (posId < min) {
                    min = posId;
                    ts2.clear();
                    ts2.add(t);
                }
            }
            ts = ts2;
            signature = signature << 4 | min;
        }
        return signature;
    }

    private static int getPiece(long board, int position) {
        return (int) (board >>> (position << 2)) & 0xf;
    }

    /** Only evaluate the relevant winning possibilities for a certain turn */
    private static boolean partialEvaluate(long board, int turn) {
        switch (turn) {
            case 15:
                return evaluate(board, masks[8]);
            case 12:
                return evaluate(board, masks[3]);
            case 1:
                return evaluate(board, masks[5]);
            case 3:
                return evaluate(board, masks[9]);
            case 2:
                return evaluate(board, masks[0]) || evaluate(board, masks[6]);
            case 11:
                return evaluate(board, masks[7]);
            case 4:
                return evaluate(board, masks[1]);
            case 8:
                return evaluate(board, masks[4]) || evaluate(board, masks[2]);
        }
        return false;
    }

    private static List<Map<Long, Long>> cache = new ArrayList<>();
    static {
        for (int i = 0; i < 16; i++)
            cache.add(new HashMap<>());
    }

    private static boolean evaluate(long board, long[] masks) {
        return _evaluate(board, masks) || _evaluate(~board, masks);
    }

    private static boolean _evaluate(long board, long[] masks) {
        for (long mask : masks)
            if ((board & mask) == mask)
                return true;
        return false;
    }

    private static long swap(long board, int x, int y) {
        if (x == y)
            return board;
        if (x > y)
            return swap(board, y, x);
        long xValue = (board & swapMasks[1][x]) << ((y - x) * 4);
        long yValue = (board & swapMasks[1][y]) >>> ((y - x) * 4);
        return board & swapMasks[0][x] & swapMasks[0][y] | xValue | yValue;
    }

    private static long getStartBoard() {
        long board = 0;
        for (long n = 0; n < 16; n++)
            board |= n << (n * 4);
        return board;
    }

    private static List<Integer> allPermutations(int input, int size, int idx, List<Integer> permutations) {
        for (int n = idx; n < size; n++) {
            if (idx == 3)
                permutations.add(input);
            allPermutations(swapBit(input, idx, n), size, idx + 1, permutations);
        }
        return permutations;
    }

    private static int swapBit(int in, int x, int y) {
        if (x == y)
            return in;
        int xMask = 1 << x;
        int yMask = 1 << y;
        int xValue = (in & xMask) << (y - x);
        int yValue = (in & yMask) >>> (y - x);
        return in & ~xMask & ~yMask | xValue | yValue;
    }

    private static int[][] transpositions = new int[16][48];
    static {
        for (int piece = 0; piece < 16; piece++) {
            transpositions[piece][0] = piece;
            List<Integer> permutations = allPermutations(piece, 4, 0, new ArrayList<>());
            for (int n = 1; n < 24; n++)
                transpositions[piece][n] = permutations.get(n);
            permutations = allPermutations(~piece & 0xf, 4, 0, new ArrayList<>());
            for (int n = 24; n < 48; n++)
                transpositions[piece][n] = permutations.get(n - 24);
        }
    }

    private static int[] minTranspositionValues = new int[16];
    private static List<List<Integer>> minTranspositions = new ArrayList<>();
    static {
        for (int n = 0; n < 16; n++) {
            int min = 16;
            List<Integer> elems = new ArrayList<>();
            for (int t = 0; t < 48; t++) {
                int elem = transpositions[n][t];
                if (elem < min) {
                    min = elem;
                    elems.clear();
                    elems.add(t);
                } else if (elem == min)
                    elems.add(t);
            }
            minTranspositionValues[n] = min;
            minTranspositions.add(elems);
        }
    }

    private static final long ROW_MASK = 1L | 1L << 4 | 1L << 8 | 1L << 12;
    private static final long COL_MASK = 1L | 1L << 16 | 1L << 32 | 1L << 48;
    private static final long FIRST_DIAG_MASK = 1L | 1L << 20 | 1L << 40 | 1L << 60;
    private static final long SECOND_DIAG_MASK = 1L << 12 | 1L << 24 | 1L << 36 | 1L << 48;

    private static long[][] masks = new long[10][4];
    static {
        for (int m = 0; m < 4; m++) {
            long row = ROW_MASK << (16 * m);
            for (int n = 0; n < 4; n++)
                masks[m][n] = row << n;
        }
        for (int m = 0; m < 4; m++) {
            long row = COL_MASK << (4 * m);
            for (int n = 0; n < 4; n++)
                masks[m + 4][n] = row << n;
        }
        for (int n = 0; n < 4; n++)
            masks[8][n] = FIRST_DIAG_MASK << n;
        for (int n = 0; n < 4; n++)
            masks[9][n] = SECOND_DIAG_MASK << n;
    }

    private static long[][] swapMasks;
    static {
        swapMasks = new long[2][16];
        for (int n = 0; n < 16; n++)
            swapMasks[1][n] = 0xfL << (n * 4);
        for (int n = 0; n < 16; n++)
            swapMasks[0][n] = ~swapMasks[1][n];
    }
}

```

Measured score:

```
$ time java -jar quarto.jar
414298141056

real    20m51.492s
user    23m32.289s
sys     0m9.983s

```

Score (user+sys): 23m42.272s

---
Tags: code-challenge, game, permutations, fastest-code, board-game
---


title: The Keyboard Shift Cipher

text:
# Question
Title: The Keyboard Shift Cipher
Given the following input:

* An integer `n` where `n > 0`.
* A string `s` where `s` is not empty and `s~=[0-9A-Z]+` (alpha-numeric capitals only).

Using a standard, simplified QWERTY keyboard (as shown below):

```
1234567890
QWERTYUIOP
ASDFGHJKL
ZXCVBNM

```

Perform the following operation:

* Find the original row that each character is in on the keyboard.
* Replace the letter with the correct shifted equivalent for `n` based on its original position + n.
    + E.G. `s="AB"` and `n=2`: `A` would become `D` and `B` would become `M`.
* If `keyboard_row[position + n] > keyboard_row.length`, wrap back to the start.
    + E.G. `s="0P"` and `n=2`: `0` would become `2` and `P` would become `W`.

# Examples:

```
f("0PLM",1)    = 1QAZ
f("ZXCVB",2)   = CVBNM
f("HELLO",3)   = LYDDW
f("0PLM",11)   = 1QSV
f("0PLM",2130) = 0PHX

```

# Rules

---

*This is slightly more difficult than it seems at first glance.*

# Answer
# Jelly, 13 bytes

```
ØQØDṭ,ṙ€¥⁸F€y

```

Try it online!

### How it works

```
ØQØDṭ,ṙ€¥⁸F€y  Main link. Left argument: n (integer). Right argument: s (string)

ØQ             Qwerty; set the return value to
               ["QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM"].
  ØD           Digits; yield "0123456789".
    ṭ          Tack, yielding ["QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM", "0123456789"].
        ¥⁸     Call the two links to the left as a dyadic chain, with right
               argument n.
      ṙ€       Rotate each string in the array n units to the left.
     ,         Yield the pair of the unmodified and the rotated string array.
          F€   Flatten each, mapping, e.g., ["QWERTYUIOP", ..., "0123456789"] to
               "QWERTYUIOPASDFGHJKLZXCVBNM0123456789".
            y  Translate s according to the mapping we've built.

```
> 11 votes

# Answer
# Python 2, 110 bytes

```
lambda s,n,y='1234567890'*99+'QWERTYUIOP'*99+'ASDFGHJKL'*99+'ZXCVBNM'*99:''.join(y[y.find(c)+n%630]for c in s)

```

Try it online!

This uses a big enough string (99 copies of each row) and the LCM between the rows lengths (630) to find the correct substitution avoiding individual correction between each row.
> 9 votes

# Answer
# Java 8, ~~159~~ 158 bytes

```
n->s->{for(int i=s.length,j;i-->0;)for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))if((j=x.indexOf(s[i])+n)>=n)s[i]=x.charAt(j%x.length());}

```

-1 byte thanks to *@OlivierGrégoire* modifying the input-array instead of printing directly.

**Explanation:**

Try it online.

```
n->s->{  // Method with integer and character-array parameters, and no return-type
  for(int i=s.length,j;i-->0;)
         //  Loop over the input character-array with index
    for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))
         //   Inner loop over the qwerty-lines
      if((j=x.indexOf(s[i])+n)>=n)
         //    If the current qwerty-line contains the character
         //     Set `j` to the index of this character on that line + input `n`
        s[i]=x.charAt(j%x.length());}
         //     Replace the character at index `i`
         //     with the new character (at index `j` modulo length_of_qwerty_line)

```
> 7 votes

# Answer
# Retina, 49 bytes

```
"$&"+T`9o`dQW\ERTYUI\OPQASDFG\HJK\LAZXC\VBNMZ
0A`

```

Try it online! Takes input `n` and `s` on separate lines. Explanation:

```
"$&"+

```

Repeat `n` times.

```
T`9o`dQW\ERTYUI\OPQASDFG\HJK\LAZXC\VBNMZ

```

Shift all the characters one key to the right.

```
0A`

```

Delete `n`.
> 5 votes

# Answer
# JavaScript (ES6), ~~101~~ 99 bytes

Takes input in currying syntax `(s)(n)`. Works with arrays of characters.

```
s=>n=>s.map(c=>(S='1QAZ2WSX3EDC4RFV5TGB6YHN7UJM8IK_9OL_0P')[(p=S.search(c)+n*4)%(-~'9986'[p%4]*4)])

```

### Test cases

```
let f =

s=>n=>s.map(c=>(S='1QAZ2WSX3EDC4RFV5TGB6YHN7UJM8IK_9OL_0P')[(p=S.search(c)+n*4)%(-~'9986'[p%4]*4)])

console.log(JSON.stringify(f([..."0PLM"])(1)))    // 1QAZ
console.log(JSON.stringify(f([..."ZXCVB"])(2)))   // CVBNM
console.log(JSON.stringify(f([..."HELLO"])(3)))   // LYDDW
console.log(JSON.stringify(f([..."0PLM"])(11)))   // 1QSV
console.log(JSON.stringify(f([..."0PLM"])(2130))) // 0PHX
```

### How?

We look for the position **p** of each character of the input within a string **S** where the keyboard rows are interleaved: the first 4 characters are **'1QAZ'** (first column of the keyboard), the next 4 characters are **'2WSX'** (second column of the keyboard) and so on. Unused positions are padded with underscores and the last ones are simply discarded.

```
col # | 0    | 1    | 2    | 3    | 4    | 5    | 6    | 7    | 8    | 9
------+------+------+------+------+------+------+------+------+------+---
row # | 0123 | 0123 | 0123 | 0123 | 0123 | 0123 | 0123 | 0123 | 0123 | 01
------+------+------+------+------+------+------+------+------+------+---
char. | 1QAZ | 2WSX | 3EDC | 4RFV | 5TGB | 6YHN | 7UJM | 8IK_ | 9OL_ | 0P

```

This allows us to easily identify the row with **p mod 4** and eliminates the need for explicit separators between the rows.

We advance by **4n** positions, apply the correct modulo for this row (40, 40, 36 and 28 respectively) and pick the replacement character found at this new position in **S**.
> 5 votes

# Answer
# Jelly, 18 bytes

```
ØQØDṭẋ€‘}Ẏ©iÐ€⁸+ị®

```

Try it online!
> 3 votes

# Answer
# C,  ~~152~~  149 bytes

*Thanks to @gastropner for saving three bytes!*

```
j,l;f(S,n){for(char*s=S,*k;*s;++s)for(k="1234567890\0QWERTYUIOP\0ASDFGHJKL\0ZXCVBNM\0";l=strlen(k);k+=l+1)for(j=l;j--;)k[j]-*s||putchar(k[(j+n)%l]);}

```

Try it online!

**Unrolled:**

```
j,l;
f(S,n)
{
    for (char*s=S, *k; *s; ++s)
        for (k="1234567890\0QWERTYUIOP\0ASDFGHJKL\0ZXCVBNM\0"; l=strlen(k); k+=l+1)
            for (j=l; j--;)
                k[j]-*s || putchar(k[(j+n)%l]);
}

```
> 3 votes

# Answer
# Red, 152 bytes

```
f: func[s n][foreach c s[foreach[t l]["1234567890"10"QWERTYUIOP"10"ASDFGHJKL"9"ZXCVBNM"7][if p: find t c[if(i:(index? p)+ n // l)= 0[i: l]prin t/(i)]]]]

```

Try it online!

Ungolfed:

```
f: func [s n][1
    foreach c s [
        foreach [t l] ["1234567890"10"QWERTYUIOP"10"ASDFGHJKL"9"ZXCVBNM"7][
            p: find t c
            if p [
                i: (index? p) + n // l
                if i = 0 [i: l]
                prin t/(i) ]]]]

```
> 2 votes

# Answer
# Haskell, 99 bytes

```
f(s,n)=[dropWhile(/=c)(cycle r)!!n|c<-s,r<-words"1234567890 QWERTYUIOP ASDFGHJKL ZXCVBNM",elem c r]

```

Try it online!
> 2 votes

# Answer
# Perl 5, 94 + 1 (`-p`) = 95 bytes

```
$s=<>;for$i(1234567890,QWERTYUIOP,ASDFGHJKL,ZXCVBNM){eval"y/$i/".(substr$i,$s%length$i)."$i/"}

```

Try it online!
> 1 votes

# Answer
# Japt, 20 bytes

Running out the door to dinner so more golfing and an explanation to follow.

```
;£=D·i9òs)æøX)gV+UbX

```

Try it
> 1 votes

# Answer
# Perl, ~~59~~ ~~58~~ ~~57~~ 56 bytes

Includes `+` for `-p`

Give input on STDIN as 2 lines, first the string, then the repeat

```
(echo 0PLM; echo 2130) | perl -pe '$a="OPQWERTYUILASDF-MZXCVBNM0-90";eval"y/HI$a/J$a/;"x<>'

```
> 1 votes

# Answer
# Perl 5, 85 bytes

**84 bytes code + 1 for `-p`.**

```
eval join"",map"y/$_/@{[/./&&$'.$&]}/;",(1234567890,QWERTYUIOP,ASDFGHJKL,ZXCVBNM)x<>

```

Try it online!
> 0 votes

# Answer
# Clean, ~~144~~ 119 bytes

```
import StdEnv

```

#

```
\n s=[l.[(i+n)rem(size l)]\\c<-s,l<-["1234567890","QWERTYUIOP","ASDFGHJKL","ZXCVBNM"],i<-[0..]&j<-:l|j==c]

```

Try it online!

Lambda function with the signature `Int ![Char] -> [Char]`
> 0 votes

# Answer
# Ruby, 101 bytes

```
->s,n{n.times{s.tr! '1234567890QWERTYUIOPASDFGHJKLZXCVBNM','2345678901WERTYUIOPQSDFGHJKLAXCVBNMZ'};s}

```

Try it online!

I'm honestly a little disappointed that I couldn't do better with 'cleverer' methods. The closest I got was along the lines of

```
a=%w{1234567890 QWERTYUIOP ASDFGHJKL ZXCVBNM}
b=a.map{|r|r[1..-1]<<r[0]}*''
a*=''
n.times{s.tr! a,b}

```

for a net gain of 7 characters.
> 0 votes

---
Tags: code-golf, keyboard, cipher
---


title: Perfect Squares Without Borders

text:
# Question
Title: Perfect Squares Without Borders
Given `n=m^2`, return a list of integers that do not border the `m x m` grid of integers from `1 to n`.

## Examples

### n=1 (m=1)

Grid:

```
[1]

```

Return:

```
[]

```

### n=4 (m=2)

Grid:

```
[1,2]
[3,4]

```

Return:

```
[]

```

### n=9 (m=3)

Grid:

```
[1,2,3]
[4,5,6]
[7,8,9]

```

Return:

```
[5]

```

### n=16 (m=4)

Grid:

```
[ 1, 2, 3, 4]
[ 5, 6, 7, 8]
[ 9,10,11,12]
[13,14,15,16]

```

Return:

```
[6,7,10,11]

```

---

For higher values of `m`, this answer does a great visualization.

---

Rules:

* You may take in either `m` or `n` (where `n = m*m`).
    + If taking in `n` you are allowed to have undefined behavior where there exists no `m` for `n` (E.G. 15).
    + `n > 0`, `m > 0`: Both must be integer values.
* The output may be as a 1D/2D array, matrix or whitespace delimited
* The output must be in order from least to greatest.
    + If outputting as a matrix this means it must be as it would be in the grid.
* This is , lowest byte-count wins.

# Answer
# C, 50 bytes

```
i;f(m){for(i=m;++i<m*m-m;)i%m>1&&printf("%d ",i);}

```

Try it online!
> 6 votes

# Answer
# Octave, 31 bytes

```
@(m)vec2mat(1:m*m,m--)(2:m,2:m)

```

Returns a matrix.

Try it online!
> 6 votes

# Answer
# Octave, 26 bytes

```
@(m)find((t=[0:m-2 0])'*t)

```

The code defines an anonymous function that inputs `m` and outputs a (possibly empty) column vector.

Try it online!

### Explanation

```
@(m)                          % Define anonymous function of m
          t=[0:m-2 0]         % Build row vector [0 1 2 ... m-2 0] and assign it
                              % to variable t
         (           )'       % Complex-conjugate transpose into a column vector
                       *t     % Matrix-multiply that column vector times the row
                              % vector t. This gives an m×m matrix with zeros in
                              % the border and nonzeros in the other entries.
    find(                )    % Linear indices of nonzero entries. The result is
                              % in increasing order

```
> 6 votes

# Answer
# Jelly, 8 bytes

```
’Ṗ×+€ṖḊ€

```

A monadic link taking `m` and returning a list of lists (the inner rows).

**Try it online!**

### How?

```
’Ṗ×+€ṖḊ€ - Link m                    e.g. 5
’        - decrement                      4
 Ṗ       - pop (implicit range of input)  [1,2,3]
  ×      - multiply by m                  [5,10,15]
     Ṗ   - pop m                          [1,2,3,4]
   +€    - add €ach                       [[6,7,8,9],[11,12,13,14],[16,17,18,19]]
      Ḋ€ - dequeue €ach                   [[7,8,9],[12,13,14],[17,18,19]]

```
> 5 votes

# Answer
# Haskell, 31 bytes

```
f m=[i|i<-[m..m*m-m],mod i m>1]

```

Try it online!

Math version:

```
f(m) = {i : i ∈ (m, m² - m), i mod m < 1}

```

:P
> 4 votes

# Answer
# , ~~44~~ ~~43~~ 32 bytes

```
function(n)(x=n:(n^2-n))[x%%n>1]

```

Try it online!

Returns a vector.
> 4 votes

# Answer
# Pure Bash, 49

The boring answer:

```
for((i=$1;i++<$1*$1-$1;));{ ((i%$1>1))&&echo $i;}

```

Try it online.

---

Or the interesting answer for 52:

```
(($1>2))&&eval echo \$[$1*{1..$[$1-2]}+{2..$[$1-1]}]

```

Try it online.
> 4 votes

# Answer
# Jelly, 8 bytes

```
sÆ½ḊṖ$⁺€

```

Try it online!
> 3 votes

# Answer
# Proton, 28 bytes

```
k=>filter(u=>1<u%k,k..k*~-k)

```

Try it online!

Takes **m** as input.

### How?

Filters the integers in **\[k, k2-k)** that, when divided by **k**, yield a remainder higher than **1**. This ensures that both ends are trimmed, because the first one yields **0** and the last one yields **1**. It is also guaranteed to return a higher value for any valid integer, because they are consecutive.
> 3 votes

# Answer
# Wolfram Language (Mathematica), 31 bytes

```
Table[# i+j+1,{i,#-2},{j,#-2}]&

```

Try it online!
> 3 votes

# Answer
# 05AB1E, 9 bytes

```
LItä¦¨ε¦¨

```

Try it online!
> 2 votes

# Answer
# Bash + GNU utilities, 35

```
seq $1 $[$1*$1-$1]|sed 1~$1d\;2~$1d

```

Try it online.
> 2 votes

# Answer
# , 23 19 bytes

-4 bytes thanks to FrownyFrog!

```
1 1}:@}.-@%:}:\1+i.

```

Try it online!

My original olution:

# , 23 bytes

```
[:|:@}:@}.^:2-@%:]\1+i.

```

Takes n as input, returns a matrix

## How it works

`1+i.` \- generates a list 1..n

`-@%:` \- finds the square root of n and negates it (m)

`]\` \- makes a table (matrix) m x m from the list

`^:2` \- do the following twice:

`|:@}:@}.` \- drop the first row, then drop the last row, then transpose

`[:` \- cap the fork

Try it online!
> 2 votes

# Answer
# Python 2, 44 bytes

```
lambda t:[k for k in range(t,~-t*t)if k%t>1]

```

Try it online!

I promise this is my last answer (to this challenge) today. Takes **m** as input.
> 2 votes

# Answer
# Julia 0.6, 36 bytes

```
m->reshape(1:m*m,(m,m))[2:m-1,2:m-1]

```

Try it online!
> 2 votes

# Answer
# Ruby, 32 bytes

```
->m{(m..m*m-m).reject{|e|e%m<2}}

```

Takes `m`, returns a one-dimensional array.

Try it online!
> 2 votes

# Answer
# MATL, 8 bytes

```
:G\1>&*f

```

Input is `m`. Output is the numbers in increasing order.

**Try it online!**

### Explanation

Consider input `4` as an example.

```
:     % Implicit input: m. Push range [1 2 ... m-1 m]
      % STACK: [1 2 3 4]
G\    % Modulo m, element-wise
      % STACK: [1 2 3 0]
1>    % Greater than 1, element-wise.
      % STACK: [0 1 1 0]
&*    % Matrix of pair-wise products
      % STACK: [0 0 0 0;
                0 1 1 0;
                0 1 1 0;
                0 0 0 0]
f     % Column vector of linear indices of nonzeros. Implicit display
      % STACK: [ 6;
                 7;
                10;
                11]

```
> 2 votes

# Answer
# APL (Dyalog Classic), 14 bytes

```
1+⊢⊥¨∘⍳2⍴0⌈-∘2

```

Try it online!
> 2 votes

# Answer
# Japt, 14 bytes

```
²õ òU ÅkJ ®ÅkJ

```

Takes `m` as input

## Explanation

```
 ²õ òU ÅkJ ®ÅkJ
                // U = input                         | 3
U²              // U squared                         | 9
  õ             // Range [1...U²]                    | [1,2,3,4,5,6,7,8,9]
    òU          // Cut into slices of U              | [[1,2,3],[4,5,6],[7,8,9]]
       Å        // Remove the first item             | [[4,5,6],[7,8,9]]
        kJ      // Remove the last item              | [[4,5,6]]
           ®    // Map:                              |
            ÅkJ //   Remove the first and last items | 5

```

Try it online!

---

The solution that takes `n` is also 14 bytes:

```
õ òU¬ ÅkJ ®ÅkJ

```

Try it online!
> 2 votes

# Answer
## Batch, 85 bytes

```
@for /l %%i in (3,1,%1)do @for /l %%j in (3,1,%1)do @cmd/cset/a(%%i-2)*%1+%%j-1&echo(

```

I can't easily loop from `2` to `m-1` so I loop from `3` to `m` and adjust in the calculation.
> 2 votes

# Answer
# Pari/GP, 26 bytes

```
n->[x|x<-[n..n^2-n],x%n>1]

```

Try it online!
> 2 votes

# Answer
# Japt, 12 bytes

I spent so long golfing the extraction of elements that I ran out of time to golf the array generation. I'm also only now noticing that we can take `n` as input instead so I may be able to save something there. To be revisited ...

```
òUnU²)òU m¤c

```

Try it

---

## Explanation

```
                 :Implicit input of integer U=m     :e.g., 4
   U²            :U squared                         :16
 Un              :Minus U                           :12
ò                :Range [U,U**2-U]                  :[4,5,6,7,8,9,10,11,12]
      òU         :Partitions of length U            :[[4,5,6,7],[8,9,10,11],[12]]
         m       :Map
          ¤      :  Remove first 2 elements         :[[6,7],[10,11],[]]
           c     :Flatten                           :[6,7,10,11]

```
> 2 votes

# Answer
# Husk, 9 bytes

```
‼ȯTthS↑CN

```

Try it online!

## Explanation

```
‼ȯTthS↑CN  Implicit input, say m=4.
       CN  Cut the natural numbers by m: [[1,2,3,4],[5,6,7,8],[9,10,11,12],..
     S↑    Take first m lists: [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
‼ȯ         Do this twice:
    h       Remove last row,
   t        remove first row,
  T         transpose.
           Result is [[6,7],[10,11]]; print it implicitly.

```
> 2 votes

# Answer
## TI-BASIC, ~~44~~ 43 bytes (tokenized)

```
DC 4D 3F CE 4D 6D 32 3F CF 3F DE 2A 08 09 3F D0 3F 4D 71 32 3F 23 4D 70 32 70 58 70 32 B1 58 83 72 11 2B 58 2B 30 2B 72 0D 71 31

```

Readable version:

```
:Input M
:If M≤2
:Then
:Disp "{}
:Else
:M-2
:seq(M+2+X+2int(X/Ans),X,0,Ans²-1

```

---

It was unfortunately necessary to print empty lists manually since TI-BASIC does not normally allow that. If `m` were given greater than two, the code could be reduced to just **29 bytes**.
> 2 votes

# Answer
# Pyth, 10 bytes

```
mtPdtPcQS*

```

**Try it here!**

Takes **m** as input.
> 1 votes

# Answer
# Java 8, ~~241~~ ~~183~~ ~~170~~ ~~162~~ ~~160~~ ~~132~~ 122 bytes

```
j->{if(j<3)return new int[1];int e[]=new int[j*j-4*j+4],x=0,i=0;for(;++i<=j*j;)if(!(i<j|i>j*j-j|i%j<2))e[x++]=i;return e;}

```

Try it online!

Java makes it very tough(lots of bytes) when you have to create an array of somewhat "unknown" size.

* -8 bytes thanks to Magic Octopus Urn
* -28 bytes thanks to Mr. Xcoder
* -10 bytes thanks to Kevin Cruijssen
> 1 votes

# Answer
# Red, 63 62 bytes

```
f: func[n][repeat i(n - 2 * n)[if(a: n + i)// n > 1[print a]]]

```

Try it online!

This is a Red port of totallyhuman's Haskell / Mr. Xcoder's Python 2 solution
> 1 votes

# Answer
# Javascript (~~63~~ 55 bytes)

```
m=>[...Array((m-2)*m)].map((x,i)=>i+m).filter(x=>x%m>1)

```

## Explanation

```
m =>                    // function signature is m
    [...Array((m-2)*m)] // create an array of size m^2 - 2m,
                        // m^2 is the full array size, taking out 2m removes the top and bottom edges
                        // filled with undefined
    .map((x,i)=>i+m)    // fill with values m to n-m
                        // (skips the top and bottom edges of the square)
    .filter(x=>x%m>1)   // filter out x%m < 2, the left and right sides of the square

```
> 1 votes

# Answer
# Pyt, 13 bytes

```
ĐĐ⁻⁻ř*⇹⁻⁻ř⁺ɐ+

```

Port of Jonathan Allan's Jelly answer

Explanation:

```
                    Implicit input (takes m)
ĐĐ                  Triplicate the input (push it on the stack two more times)
  ⁻⁻                Decrement top of stack twice
    ř               Push [1,2,...,m-2]
     *              Multiplies by m
      ⇹             Swaps top two items on stack
       ⁻⁻           Decrement (m-2 is now on top)
         ř          Push [1,2,...,m-2]
          ⁺         Increment each element by 1
           ɐ+       Add [2,3,...,m-1] to each element of [m,2m,...,m(m-2)]
                    Implicit print

```

Try it online!
> 1 votes

# Answer
# Perl, ~~30~~ 29 bytes

```
perl -E 'say$_+=@a+2for(@a=2..~-<>)x@a' <<< 4

```
> 1 votes

# Answer
## JavaScript, 47 bytes

```
  m=>{for(i=m;++i<m*m-m;)if(i%m>1)console.log(i)} // here's the 47-byte script
```

Also, 49 bytes:

```
  m=>{for(i=m;(i%m>1&&console.log(i))|++i<m*m-m;);} // here's the 49-byte script
```
> 1 votes

# Answer
# Clean, 45 bytes

```
import StdEnv
$m=[i\\i<-[m..m*m-m]|i rem m>1]

```

Try it online!

This is just totallyhuman's Haskell answer but in Clean.
> 1 votes

# Answer
# Python, 111 bytes

```
def f(s):
 r=[]
 for i in[i[1:-1]for i in[[(j*s)+i+1 for i in range(s)]for j in range(s)][1:-1]]:r+=i
 return r

```
> 1 votes

# Answer
# APL, 28 Bytes

Will run given value for `m`

```
1 1↓¯1 ¯1↓m m⍴⍳m*2

```

Try it...

### Explanation

`m*2` squares m

`⍳m*2` gets list from 1 to m\*2

`m m⍴⍳m*2` wraps list to m by m matrix

`¯1 ¯1↓m m⍴⍳m*2` drops -last row an column

`1 1↓¯1 ¯1↓m m⍴⍳m*2` drops first row and column
> 1 votes

---
Tags: code-golf, matrix
---


title: The Pyramid of Languages

text:
# Question
Title: The Pyramid of Languages
Write a code that runs or compiles in as many programming languages as possible and prints a newline separated list of names of previous and current programming languages.

* Every used language must have 1 character longer name than previous; ex. `C#`, `C++`, `Ruby`, `Jelly`, `Python`...
* Each language must output a list of language names separated with a newline, sorted by length.
    + **Output must be a pyramid:** The list can only contain used language names, that are shorter than the running script language name + the running script language's name.
* Leading and trailing newlines are allowed.
* Standard loopholes are forbidden.
* It's not allowed to create custom programming languages just to increase the score.
* Version numbers don't count in language name, but you can specify it in your post if there are any incompatible changes in new versions of the language.
* You can decide if you want to use the shortcut for the language name or it's full name, but you can't submit both forms in one answer. You can use ex. either `SPL` or `Shakespeare Programming Language`.
    + Only letters, numbers, ASCII symbols and single spaces (not leading nor trailing) count in language name length.

## Examples

Example outputs for C, C# and C++:

### `C`

```
C

```

### `C#`

```
C
C#

```

### `C++`

```
C
C#
C++

```

# Answer
> 20 votes
# 10 languages , rk, \>\<\>, Rail, Width, Gol\>\<\>, Fission, Cardinal, brainfuck, Befunge-98, 991 bytes

```
//Q rk:start print: "C^nrk" rk:end @,k*97C'a"rk"a"><>"a-1"Sail"a"Width"a"Gol><>"a"Fission"a"Cardinal"a"brainfuck"a"Befunge-98"
main(){puts("C");}
/*
$'main'
 \-[C\n\rk\n\><>\n\Rail]o

++++[++++>---<]>.>++++++++++.[------->+++<]>.-------.>++++++++++.[->++++++<]>++.--.++.>++++++++++.>-[--->+<]>---.[------>+<]>--.++++++++.+++.>++++++++++.[------>+<]>.+++[->++++<]>+.-----.--[--->+<]>--.------------.>++++++++++.[->+++++++<]>+.[--->+<]>++.---.--[->+++<]>.--.++.>++++++++++.[->+++++++<]>.[-->+++<]>.++++++++++..----------.++++++.-.>++++++++++.+[->++++++<]>+.-[-->+++<]>--.--[--->+<]>---.--------------.+++++.+++++.-------------.+++++++++++.>++++++++++.+[--->++++<]>--.[--->+<]>----.+++[->+++<]>++.++++++++.+++++.--------.-[--->+<]>--.+[->+++<]>+.++++++++.
R"C"N"rk"N"><>"N'S_!"ail"N"Width"N"Gol><>"N"Fission"*
/"><>krC"oaoooaooooE ao'liaR>'~ooooaoS"Width"aoS"Gol><>"; QQaAWAmcOAWAaicmaiWAAiwAOaOwWAAAOawmmFOcQww
 %"C"++++++++++,"rk","><>",=--t++,"ail"~,"Width","Gol><>","Fission","Cardinal"
 */

```

Try it online!

568 bytes of this is just the brainfuck code. The Befunge-98 program produces:

```
C
rk
><>
Rail
Width
Gol><>
Fission
Cardinal
brainfuck
Befunge-98

```

# Answer
> 10 votes
# 7 languages (J, es, zsh, Bash, Straw, Retina, Fission), 222 bytes

```
echo 'J'
#0 : 0
echo es #(10)#»:::J>>(es)>>(zsh)>>(Bash)>>(Straw)>>
(echo zsh;)
if [[ $BASH_VERSION ]]; then echo Bash; fi
#              ;R"J"N"es"N"zsh"N"Bash"N"Straw"N'Q+!"etina"N"Fission"N;
K`J¶es¶zsh¶Bash¶Straw¶Retina

```

Try it online!

# Answer
> 1 votes
# rk, sed, Swap, 65 bytes

```
s/.*/rk\nsed/
rk:start print: "rk"
r>"pawSdeskr"oo52*oooo52*ooooo

```

rk: Try it online!

sed: Try it online!

Swap: Try it online!

---
Tags: polyglot, rosetta-stone
---


# Question
Title: Compressing the Atomic Ionization Energies
This is a different type of compression challenge. In a normal challenge, you are required to recreate a list exactly. Here, you are allowed to round the values in any way you wish. What's the catch? Your score is penalized based on how wrong your output is.

At the bottom of this question is a list of the first ionization energies for the first 108 elements. Your program, upon execution, should output a reasonably accurate copy of this list. There will be no input or arguments. For scoring purposes your output should be deterministic (same output every time).

**Output format**

Your program/function must output a list of 108 numbers, sorted in order of increasing atomic number. This list can be in any appropriate format. The source data below is provided in the correct order, from hydrogen to hassium.

## Scoring

**Your score will be your program's length in bytes plus a rounding penalty.** A rounding penalty is calculated for each element and summed to give the total penalty.

As an example, let's take the number `11.81381`. Let's say that your program outputs an incorrect value of `11.81299999`.

1. First, both numbers are multiplied by the same power of 10 such that there is no longer a decimal point in the true value: `1181381, 1181299.999`. Trailing zeros in the true value are considered significant.
2. Then, the absolute difference is taken to determine the absolute error: `81.001`.
3. Finally, we calculate this element's penalty as `max(0, log10(err * 4 - 1)) -> 2.50921`. This formula was chosen such that an error \< 0.5 gives no penalty (since the answer is correct within rounding), while also giving an asymptotic 50% chance that rounding the number to any particular decimal place would provide a net benefit in score (assuming no other compression).

Here is a Try-It-Online implementation of a penalty-calculating program. The input to this program is provided as a list of numbers, one per line. The output of this program is the total penalty and a per-element breakdown of scoring.

## Data

The list of numbers below is the target data, in the correct order from atomic number 1 to 108.

Source

```
13.598434005136
24.587387936
5.391714761
9.322699
8.2980190
11.260296
14.53413
13.618054
17.42282
21.564540
5.1390767
7.646235
5.985768
8.151683
10.486686
10.36001
12.96763
15.7596112
4.34066354
6.11315520
6.56149
6.82812
6.746187
6.76651
7.434018
7.9024678
7.88101
7.639877
7.726380
9.3941990
5.9993018
7.899435
9.7886
9.752392
11.81381
13.9996049
4.177128
5.69486720
6.21726
6.63390
6.75885
7.09243
7.11938
7.36050
7.45890
8.33686
7.576234
8.993822
5.7863552
7.343917
8.608389
9.00966
10.45126
12.1298431
3.893905548
5.211664
5.5769
5.5386
5.473
5.5250
5.582
5.64371
5.670385
6.14980
5.8638
5.93905
6.0215
6.1077
6.18431
6.254159
5.425871
6.825069
7.549571
7.86403
7.83352
8.43823
8.96702
8.95883
9.225553
10.437504
6.1082871
7.4166796
7.285516
8.414
9.31751
10.7485
4.0727409
5.278424
5.380226
6.3067
5.89
6.19405
6.2655
6.0258
5.9738
5.9914
6.1978
6.2817
6.3676
6.50
6.58
6.65
4.90
6.01
6.8
7.8
7.7
7.6

```

## Baselines & Tips

The source data above is 906 bytes, with certain compression tools able to get it to sub-500 bytes. Interesting solutions are those that attempt to perform intelligent rounding, use algebraic formulas, or other techniques to output approximate values in fewer bytes than compression alone. It is difficult, however, to judge these tradeoffs across languages: for some languages compression alone might be optimal, while many other languages might lack compression tools altogether, so I expect a wide variation in score across languages. This is fine, as I'm going by the "competition within languages, not between them" philosophy.

I anticipate that it might be useful to attempt to take advantage of trends in the periodic table. Below is a graph I found of ionization energies, so that you can see some of these trends.

# Answer
> 6 votes
# Clean, 540 bytes + 64.396 Penalty = 604.396

***Note:*** *for the sake of readability, I've escaped every byte in the `[Char]` literal as most of them are non-printable. However, they are counted as only one byte per escape (except the null, quote, and newlines) as Clean naturally takes source files encoding-independently (except nulls).*

```
import StdEnv,GenLib
c[h:t]=[(toInt h>>i)rem 2\\i<-[0..7]]++c t
c[]=[]
r[]=[]
r l=[7<<29+2^62+sum[d<<p\\d<-l&p<-[32..53]]:r(drop 22l)]
u::Maybe[Real]
u=uncompress{e\\e<-[108:r(c['\145\062\353\227\045\336\021\131\341\224\212\225\230\140\121\241\231\027\321\306\361\254\075\154\161\041\144\255\346\110\371\126\172\155\361\127\152\023\350\222\117\116\341\222\155\357\351\072\341\153\315\025\171\317\141\367\076\232\377\323\206\301\257\235\103\154\157\274\035\010\347\167\142\370\355\074\172\320\347\036\165\262\210\364\177\025\144\176\303\223\143\116\340\270\012\172\062\377\257\141\265\320\342\261\225\347\215\165\044\152\017\011\133\251\027\347\243\307\231\304\165\351\325\035\036\053\010\341\344\131\363\207\072\045\327\012\130\347\167\023\312\023\210\013\347\244\236\020\172\153\362\370\142\123\276\116\226\341\211\245\105\136\145\146\130\367\123\026\312\244\225\347\152\225\145\142\207\164\227\145\360\105\140\201\041\271\141\273\274\230\020\101\166\101\133\171\063\155\302\062\036\061\335\147\130\365\175\201\203\035\357\341\272\172\270\067\047\002\200\223\342\156\230\253\152\347\105\322\335\117\203\220\242\342\316\137\311\247\004\155\164\124\131\205\325\203\116\306\365\170\325\032\143\337\017\331\232\006\266\122\176\305\334\137\214\312\130\035\110\306\206\227\001\000\150\353\121\132\146\246\226\231\071\365\050\140\063\063\333\314\314\307\314\354\231\231\171'])]}

```

Try it online!

This is the first challenge where I've been able to utilize Clean's generic compression ability (technically not actually compression, it's binary serialization) to gain an actual benefit.

I started with a `[Real]` \- a list of 64-bit floating-point numbers, those from the question. After serializing this list, I simplified the top 10 bits (which were the same for each number), and the optimal configuration of the bottom 32 bits into the constant `7<<29+2^62`. The remaining 22 bits per number were translated into 2.75 characters each, and encoded in a string.

This leaves the entire compressed constant at **only 302 bytes**, including every escape!

# Answer
> 5 votes
# Python 3, ~~355 + 202~~ 353 bytes + 198 penalty = 551

```
for i in'趐㠡愍噢甹靍跄땠㖀侙㹐哜洫毙蛿ꐏⴰ㾤䑎䜕䘻䙱䵤剄刋侈偯懌㹴刼旧斆竼醽⭼㭉䂹䔏䙜䧕䨝䲠䶦囊仟嶡㰽䱴妝巋泍繆⢉㙁㨎㦨㣺㦄㨜㫀㬈䀅㴋㷔㺯㾕䁡䄛㡼䜍亘凞册埘嵙嵃怊沨㾗䴵䯘垗惿濥⩦㛳㠂䆧㵑䁻䄺㺻㸰㹟䂅䅥䉊䎫䒀䔺㌃㺑䛊儳倩伞':print(ord(i)/2665)

```

Try it online!

I used `0xffff (65535)` as upper bound because it's the max value that can be stored in a single 3-bytes unicode character.
Since the highest ionization energy is ~24.587, that gives a ratio of `2665`.
To generate the string itself I used the snippet `''.join([chr(int(round(n*2665)))for n in ionization_energies])` (on python2 you need to use `unichr`), your console may or may not be able to print the characters.

---

### 4-bytes characters, 462 bytes + 99 penalty = 561

```
for i in'':print(ord(i)/45312)

```

Try it online!
Same idea, but the max value is `0x110000`

# Answer
> 4 votes
# C, 49 bytes + 626.048 penalty = 675.048

```
f(i){for(i=0;i<108;)printf("%f\n",5.5+i++/13%2);}

```

Try it online!

# Answer
> 4 votes
## CJam (389 bytes + 33.09 penalty =\> 422.09)

xxd-encoded:

```
0000000: 2256 3232 7c24 1bf9 7116 2f43 c82b 110e  "V22|$..q./C.+..
0000010: 6b93 4525 1cb3 4118 4afc 4d05 5c22 e15a  k.E%..A.J.M.\".Z
0000020: 11bc 563c 38e4 626c 1efb 6b10 c229 0e35  ..V<8.bl..k..).5
0000030: 873d 15df 2f71 36ca 404d 54d9 4979 17ba  .=../q6.@MT.Iy..
0000040: 4938 a953 6fb6 5f04 75f0 5c22 5c6b 39e5  I8.So._.u.\"\k9.
0000050: 3073 6fbd 343e fb36 4fff 357c 8c36 10f3  0so.4>.6O.5|.6..
0000060: 3b3c 37cd 3f1c 10a1 3f06 933d 0f1d fa3d  ;<7.?...?..=...=
0000070: 67e8 4549 6a9c 2f7f 24be 3f99 4713 e147  g.EIj./.$.?.G..G
0000080: 011c e14f 20d5 577f 668d 2135 30c2 2d47  ...O .W.f.!50.-G
0000090: 45d1 315e bc35 8936 0987 385e d238 7a9f  E.1^.5.6..8^.8z.
00000a0: 3af1 3b55 f441 2cbc 3c4e 8843 7ceb 2e25  :.;U.A,.<N.C|..%
00000b0: 1d93 3a60 15f1 4237 3fb0 4404 f949 e750  ..:`..B7?.D..I.P
00000c0: 423d b21e 265b 7cf6 2958 df2c 4edf 2c27  B=..&[|.)X.,N.,'
00000d0: c32b e42c 992c d32d 1394 2d2e 3cd9 3119  .+.,.,.-..-.<.1.
00000e0: b22e 74c3 2f41 cb30 9630 6ea4 313c dd32  ..t./A.0.0n.1<.2
00000f0: 04a1 2b34 0be1 364c 6fb8 3c32 61af 3e74  ..+4..6Lo.<2a.>t
0000100: e23e 55c3 4160 af43 6f8e 436a f544 733d  .>U.A`.Co.Cj.Ds=
0000110: eb49 e030 6e71 b43b 2ad7 3a24 af41 d345  .I.0nq.;*.:$.A.E
0000120: 5c22 c84a 7f9d 204a 3ea5 2a1d 0dcb 2b05  \".J.. J>.*...+.
0000130: 2cfd 32ba af31 46da 320f ef30 1ab5 2fe5  ,.2..1F.2..0../.
0000140: 2ff7 314a c632 20ba 3278 b6b4 34d1 b5a7  /.1J.2 .2x..4...
0000150: b0b6 bebd bc22 7b69 3235 362b 3262 283b  ....."{i256+2b(;
0000160: 287d 2531 6125 7b32 253a 2b5f 323e 315c  (}%1a%{2%:+_2>1\
0000170: 2b32 6232 405f 2c33 2d5c 323c 3262 2d23  +2b2@_,3-\2<2b-#
0000180: 642f 4e7d 2f                             d/N}/

```

Basically this is

```
"MAGIC STRING"{i256+2b(;(}%1a%{2%:+_2>1\+2b2@_,3-\2<2b-#d/N}/

```

This uses a custom variable-width floating point format to store the numbers. Two bits suffice for the exponent; the mantissa gets anywhere from 5 bits to 47 bits, in multiples of 7. The remaining bit per byte serves as the separator.

There seems to be some corruption going on when I copy the magic string to make an online demo, so that scores about 2 penalty points more. I'll have to figure out how to build the URL directly...

---

Generation program:

```
e# Score calculation
{1$`'.+'.%1=,10\#_@*@@*-z 4*1- 0e> ml10ml/0e>}:E;

q~]

e# Custom float format
e# Exponent goes from 2^1 to 2^4, so 2 bits
e# Each byte has 1 bit for continuation, so 7 bits available
e# That means the options for the mantissa are 5 bits, 12 bits, 19 bits, 26 bits, 33 bits, 40 bits, 47 bits
{
  :X
  0\{2/\)\_2<!}g
  e# Stack: exponent mantissa
  2 47#*i2b(;
  e# Stack: exponent mantissa-bits
  W%7/W%Wf%:M
  7,{
    )M<e_
    1_$+2b2@,#d/
  }%
  2 3$#f*
  X\f{E}
  _,,.+
  _:e<
  #)<

  \(4+2b(;\+e_7/
  _,,:!W%\.+2fb:c
}%
""*`

```

Online demo

# Answer
> 4 votes
# Jelly,  ~~379 361~~  360 bytes \+ 0 Penalty = 360

-18 using an observation from Peter Taylor (order 10 values have leading 1 or 2, while order 1 values do not).

```
<3Ḣ‘_L⁵*×Ḍ
“KẸ⁺dzⱮÑ2⁵İ2ṭ¬⁴²¬¶9°ß°øİẆGẊœ%X(¢ṆḢ/8¬Ɗ’b7µ18,-;_3+\⁺Ṭœṗ“SŒƥŻƭ°}MḋṘḥfyɼ{ṅĊLƝġœ⁺ḟ8ḶhỊDṭ&æ%*ɱ¬ =¦ẉ Qh"¶:ḌĊ€ĖṢė°ġṀƬmẓSṃ÷E⁴Ȥ⁼ḋ#ØĖḂ2øzẸżƈ¥Ȧƥ7¢®|ḳẊṆƙƲɦḟɼṖỊɲṁẉɗ6ẇSɗ⁴ẉİt]ẓeṆHṚƑ½>]ɦ~T¢~ẆẆA`/6ƭṡxṠKG£Ḅ+wḃḣỤw×ḌŻƲF>Ụ]5bJḤḟCḞİḶ|ȥ9Ỵ0ụKṗT⁴ƥƁṖı×ṄtTĊG©ṀḥṬƭʂd½ḊȦÑƒŀṣ¹ʋṖẓYL²ṅṿ&ẏdDṬIɦỵ¹b,ḷṣƭ#P'µ{GTƇẹ¥L8SƥÑṆẈėẎßṀḷƓ⁷ðḳċ¿ḶM_ḲẈg9ḢĠi+LṭẹḲẎ¤g<ṘJJĿßæ⁺(ɲỴ3ɲgkSḃIƙṭ.Ỵ&_:cĿƝı’D¤Ç€

```

**Try it online!**

### How?

Creates these two constants (AKA nilads):

* (A) all the decimal digits used (i.e. the numbers all joined up ignoring where they join and their decimal place separators), and
* (B) the number of significant figures used by each number

Then uses those to reconstruct floating point representations of the numbers.

The full program is of this form:

```
<3Ḣ‘_L⁵*×Ḍ
“...’b7µ18,-;_3+\⁺Ṭœṗ“...’D¤Ç€

```

(where `...` are encoded numbers for constructing B, and A)
and works like this:

```
<3Ḣ‘_L⁵*×Ḍ - Link 1, conversion helper: list of digits  e.g. [1,2,9,6,7,6,3]
<3         - less than three?                                [1,1,0,0,0,0,0]
  Ḣ        - head                                            1
   ‘       - increment                                       2
     L     - length                                          7
    _      - subtract                                        -5
      ⁵    - literal ten                                     10
       *   - exponentiate                                    0.00001
         Ḍ - undecimal (convert from base 10)                1296763
        ×  - multiply                                        12.96763
           - i.e. go from digits to a number between 3 and 30

“...’b7µ18,-;_3+\⁺Ṭœṗ“...’D¤Ç€ - Main link: no arguments
“...’                          - base 250 literal = 16242329089425509505495393436399830365761075941410177200411131173280169129083782003564646
     b7                        - to base seven = [2,0,4,3,2,4,2,4,3,2,3,3,4,2,3,5,3,3,0,3,4,2,4,4,1,4,3,4,3,2,1,5,3,5,1,5,0,3,3,3,3,3,3,3,4,3,4,2,3,2,4,5,4,0,1,3,2,4,2,5,4,2,2,4,2,3,4,4,3,3,3,2,3,3,3,3,4,4,3,3,2,0,5,3,5,2,3,1,1,6,2,3,3,3,3,3,3,1,3,3,3,3,2,3,3]
       µ                       - start a new monadic chain, call that x
        18,-                   - integer list literal = [18,-1]
            ;                  - concatenate with x = [18,-1,2,0,4,3,2,4,2,4,3,2,3,3,4,2,3,5,3,3,0,3,4,2,4,4,1,4,3,4,3,2,1,5,3,5,1,5,0,3,3,3,3,3,3,3,4,3,4,2,3,2,4,5,4,0,1,3,2,4,2,5,4,2,2,4,2,3,4,4,3,3,3,2,3,3,3,3,4,4,3,3,2,0,5,3,5,2,3,1,1,6,2,3,3,3,3,3,3,1,3,3,3,3,2,3,3]
             _3                - subtract three = [15,-4,-1,-3,1,0,-1,1,-1,1,0,-1,0,0,1,-1,0,2,0,0,-3,0,1,-1,1,1,-2,1,0,1,0,-1,-2,2,0,2,-2,2,-3,0,0,0,0,0,0,0,1,0,1,-1,0,-1,1,2,1,-3,-2,0,-1,1,-1,2,1,-1,-1,1,-1,0,1,1,0,0,0,-1,0,0,0,0,1,1,0,0,-1,-3,2,0,2,-1,0,-2,-2,3,-1,0,0,0,0,0,0,-2,0,0,0,0,-1,0,0]
                \              - cumulative reduce with:
               +               -   addition    = [15,11,10,7,8,8,7,8,7,8,8,7,7,7,8,7,7,9,9,9,6,6,7,6,7,8,6,7,7,8,8,7,5,7,7,9,7,9,6,6,6,6,6,6,6,6,7,7,8,7,7,6,7,9,10,7,5,5,4,5,4,6,7,6,5,6,5,5,6,7,7,7,7,6,6,6,6,6,7,8,8,8,7,4,6,6,8,7,7,5,3,6,5,5,5,5,5,5,5,3,3,3,3,3,2,2,2]
                               -                 ("B" significant figures, with 1 extra for the very first entry and a missing last entry)
                 ⁺             - repeat (the cumulative addition to get
                               -         partition positions) = [15,26,36,43,51,59,66,74,81,89,97,104,111,118,126,133,140,149,158,167,173,179,186,192,199,207,213,220,227,235,243,250,255,262,269,278,285,294,300,306,312,318,324,330,336,342,349,356,364,371,378,384,391,400,410,417,422,427,431,436,440,446,453,459,464,470,475,480,486,493,500,507,514,520,526,532,538,544,551,559,567,575,582,586,592,598,606,613,620,625,628,634,639,644,649,654,659,664,669,672,675,678,681,684,686,688,690]
                  Ṭ            - untruth (1s at those indices) = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,1,0,1]
                           ¤   - nilad followed by link(s) as a nilad:
                     “...’     -   base 250 literal = 1359843400513624587387936539171476193226998298019011260296145341313618054174228221564540513907677646235598576881516831048668610360011296763157596112434066354611315520656149682812674618767665174340187902467878810176398777726380939419905999301878994359788697523921181381139996049417712856948672062172666339067588570924371193873605074589083368675762348993822578635527343917860838990096610451261212984313893905548521166455769553865473552505582564371567038561498058638593905602156107761843162541595425871682506975495717864037833528438238967028958839225553104375046108287174166796728551684149317511074854072740952784245380226630675896194056265560258597385991461978628176367665065866549060168787776
                          D    -   decimal (to base 10) = [1,3,5,9,8,4,3,4,0,0,5,1,3,6,2,4,5,8,7,3,8,7,9,3,6,5,3,9,1,7,1,4,7,6,1,9,3,2,2,6,9,9,8,2,9,8,0,1,9,0,1,1,2,6,0,2,9,6,1,4,5,3,4,1,3,1,3,6,1,8,0,5,4,1,7,4,2,2,8,2,2,1,5,6,4,5,4,0,5,1,3,9,0,7,6,7,7,6,4,6,2,3,5,5,9,8,5,7,6,8,8,1,5,1,6,8,3,1,0,4,8,6,6,8,6,1,0,3,6,0,0,1,1,2,9,6,7,6,3,1,5,7,5,9,6,1,1,2,4,3,4,0,6,6,3,5,4,6,1,1,3,1,5,5,2,0,6,5,6,1,4,9,6,8,2,8,1,2,6,7,4,6,1,8,7,6,7,6,6,5,1,7,4,3,4,0,1,8,7,9,0,2,4,6,7,8,7,8,8,1,0,1,7,6,3,9,8,7,7,7,7,2,6,3,8,0,9,3,9,4,1,9,9,0,5,9,9,9,3,0,1,8,7,8,9,9,4,3,5,9,7,8,8,6,9,7,5,2,3,9,2,1,1,8,1,3,8,1,1,3,9,9,9,6,0,4,9,4,1,7,7,1,2,8,5,6,9,4,8,6,7,2,0,6,2,1,7,2,6,6,6,3,3,9,0,6,7,5,8,8,5,7,0,9,2,4,3,7,1,1,9,3,8,7,3,6,0,5,0,7,4,5,8,9,0,8,3,3,6,8,6,7,5,7,6,2,3,4,8,9,9,3,8,2,2,5,7,8,6,3,5,5,2,7,3,4,3,9,1,7,8,6,0,8,3,8,9,9,0,0,9,6,6,1,0,4,5,1,2,6,1,2,1,2,9,8,4,3,1,3,8,9,3,9,0,5,5,4,8,5,2,1,1,6,6,4,5,5,7,6,9,5,5,3,8,6,5,4,7,3,5,5,2,5,0,5,5,8,2,5,6,4,3,7,1,5,6,7,0,3,8,5,6,1,4,9,8,0,5,8,6,3,8,5,9,3,9,0,5,6,0,2,1,5,6,1,0,7,7,6,1,8,4,3,1,6,2,5,4,1,5,9,5,4,2,5,8,7,1,6,8,2,5,0,6,9,7,5,4,9,5,7,1,7,8,6,4,0,3,7,8,3,3,5,2,8,4,3,8,2,3,8,9,6,7,0,2,8,9,5,8,8,3,9,2,2,5,5,5,3,1,0,4,3,7,5,0,4,6,1,0,8,2,8,7,1,7,4,1,6,6,7,9,6,7,2,8,5,5,1,6,8,4,1,4,9,3,1,7,5,1,1,0,7,4,8,5,4,0,7,2,7,4,0,9,5,2,7,8,4,2,4,5,3,8,0,2,2,6,6,3,0,6,7,5,8,9,6,1,9,4,0,5,6,2,6,5,5,6,0,2,5,8,5,9,7,3,8,5,9,9,1,4,6,1,9,7,8,6,2,8,1,7,6,3,6,7,6,6,5,0,6,5,8,6,6,5,4,9,0,6,0,1,6,8,7,8,7,7,7,6]
                               -                          ("A" all the required digits in order)
                   œṗ          - partition at truthy indices = [[1,3,5,9,8,4,3,4,0,0,5,1,3,6],[2,4,5,8,7,3,8,7,9,3,6],[5,3,9,1,7,1,4,7,6,1],[9,3,2,2,6,9,9],[8,2,9,8,0,1,9,0],[1,1,2,6,0,2,9,6],[1,4,5,3,4,1,3],[1,3,6,1,8,0,5,4],[1,7,4,2,2,8,2],[2,1,5,6,4,5,4,0],[5,1,3,9,0,7,6,7],[7,6,4,6,2,3,5],[5,9,8,5,7,6,8],[8,1,5,1,6,8,3],[1,0,4,8,6,6,8,6],[1,0,3,6,0,0,1],[1,2,9,6,7,6,3],[1,5,7,5,9,6,1,1,2],[4,3,4,0,6,6,3,5,4],[6,1,1,3,1,5,5,2,0],[6,5,6,1,4,9],[6,8,2,8,1,2],[6,7,4,6,1,8,7],[6,7,6,6,5,1],[7,4,3,4,0,1,8],[7,9,0,2,4,6,7,8],[7,8,8,1,0,1],[7,6,3,9,8,7,7],[7,7,2,6,3,8,0],[9,3,9,4,1,9,9,0],[5,9,9,9,3,0,1,8],[7,8,9,9,4,3,5],[9,7,8,8,6],[9,7,5,2,3,9,2],[1,1,8,1,3,8,1],[1,3,9,9,9,6,0,4,9],[4,1,7,7,1,2,8],[5,6,9,4,8,6,7,2,0],[6,2,1,7,2,6],[6,6,3,3,9,0],[6,7,5,8,8,5],[7,0,9,2,4,3],[7,1,1,9,3,8],[7,3,6,0,5,0],[7,4,5,8,9,0],[8,3,3,6,8,6],[7,5,7,6,2,3,4],[8,9,9,3,8,2,2],[5,7,8,6,3,5,5,2],[7,3,4,3,9,1,7],[8,6,0,8,3,8,9],[9,0,0,9,6,6],[1,0,4,5,1,2,6],[1,2,1,2,9,8,4,3,1],[3,8,9,3,9,0,5,5,4,8],[5,2,1,1,6,6,4],[5,5,7,6,9],[5,5,3,8,6],[5,4,7,3],[5,5,2,5,0],[5,5,8,2],[5,6,4,3,7,1],[5,6,7,0,3,8,5],[6,1,4,9,8,0],[5,8,6,3,8],[5,9,3,9,0,5],[6,0,2,1,5],[6,1,0,7,7],[6,1,8,4,3,1],[6,2,5,4,1,5,9],[5,4,2,5,8,7,1],[6,8,2,5,0,6,9],[7,5,4,9,5,7,1],[7,8,6,4,0,3],[7,8,3,3,5,2],[8,4,3,8,2,3],[8,9,6,7,0,2],[8,9,5,8,8,3],[9,2,2,5,5,5,3],[1,0,4,3,7,5,0,4],[6,1,0,8,2,8,7,1],[7,4,1,6,6,7,9,6],[7,2,8,5,5,1,6],[8,4,1,4],[9,3,1,7,5,1],[1,0,7,4,8,5],[4,0,7,2,7,4,0,9],[5,2,7,8,4,2,4],[5,3,8,0,2,2,6],[6,3,0,6,7],[5,8,9],[6,1,9,4,0,5],[6,2,6,5,5],[6,0,2,5,8],[5,9,7,3,8],[5,9,9,1,4],[6,1,9,7,8],[6,2,8,1,7],[6,3,6,7,6],[6,5,0],[6,5,8],[6,6,5],[4,9,0],[6,0,1],[6,8],[7,8],[7,7],[7,6]]
                            Ç€ - call the last link (1) as a monad for €ach = [13.598434005136,24.587387936000002,5.391714761,9.322699,8.298019,11.260295999999999,14.534129999999998,13.618053999999999,17.422819999999998,21.56454,5.1390766999999995,7.646235,5.985767999999999,8.151683,10.486686,10.360009999999999,12.96763,15.759611200000002,4.34066354,6.1131552000000005,6.561490000000001,6.82812,6.746187,6.76651,7.434018,7.902467799999999,7.881010000000001,7.639876999999999,7.72638,9.394199,5.9993018,7.8994349999999995,9.7886,9.752392,11.81381,13.9996049,4.177128,5.6948672,6.2172600000000005,6.633900000000001,6.758850000000001,7.09243,7.1193800000000005,7.360500000000001,7.458900000000001,8.336860000000001,7.5762339999999995,8.993822,5.7863552,7.343916999999999,8.608388999999999,9.00966,10.45126,12.129843099999999,3.893905548,5.211664,5.5769,5.538600000000001,5.473,5.525,5.582,5.6437100000000004,5.670385,6.149800000000001,5.8638,5.939050000000001,6.0215000000000005,6.1077,6.184310000000001,6.254159,5.425871,6.825069,7.549570999999999,7.8640300000000005,7.833520000000001,8.43823,8.967020000000002,8.95883,9.225553,10.437504,6.1082871,7.416679599999999,7.285515999999999,8.414,9.31751,10.7485,4.072740899999999,5.278423999999999,5.3802259999999995,6.3067,5.89,6.194050000000001,6.2655,6.0258,5.973800000000001,5.9914000000000005,6.1978,6.281700000000001,6.3676,6.5,6.58,6.65,4.9,6.01,6.800000000000001,7.800000000000001,7.7,7.6000000000000005]

```

# Answer
> 3 votes
# Bubblegum, 403 + 9.12 = 412.12

```
00000000: 1551 5116 c030 04fb 7718 af20 e2fe 17db  .QQ..0..w.. ....
00000010: f2d1 454d 4322 cae7 d8d5 ef4d 142c db87  ..EMC".....M.,..
00000020: 5bdc 2bd8 785d 6cf4 22ec bc32 7167 f43c  [.+.x]l."..2qg.<
00000030: be38 8bf0 c4cb 8345 fb54 4759 9423 f8a6  .8.....E.TGY.#..
00000040: 2dd6 3b93 6919 3ee8 691b 8fba b758 5b47  -.;.i.>.i....X[G
00000050: 236b 6cfc 380b 1a3d 26c0 b278 de04 0845  #kl.8..=&..x...E
00000060: 85f7 c222 fdb0 288b f19d 4344 5a7b f503  ..."..(...CDZ{..
00000070: 6ada e011 1533 69f0 41f4 fdc8 64e8 be8d  j....3i.A...d...
00000080: e02a 0026 6c5d 3a83 7f70 2f1b ab88 8ca7  .*.&l]:..p/.....
00000090: 5fa8 e36a b64d 1425 f73a ee0c aab9 eb1a  _..j.M.%.:......
000000a0: 3b5f 1282 c9ba 9401 8c62 58b4 b5c7 6e24  ;_.......bX...n$
000000b0: 6d1c d7c4 aa7f c626 7e44 d569 8a21 c7d6  m......&~D.i.!..
000000c0: df65 d78f 1157 b495 4ea5 7b28 77ab 4035  .e...W..N.{(w.@5
000000d0: 9d45 561b fdae 9869 e34b d44c ea45 6b31  .EV....i.K.L.Ek1
000000e0: 46c7 63f1 ecfc bd03 645a 4f24 645a a4f6  F.c.....dZO$dZ..
000000f0: 1a56 ceab 7b33 ade1 3202 681b d19f a088  .V..{3..2.h.....
00000100: 1f7a 4b97 1c7d 9952 d1b5 21dc 571c d9dc  .zK..}.R..!.W...
00000110: 2702 a204 a254 f665 08e2 ed0a d451 c2a7  '....T.e.....Q..
00000120: 6344 df39 5c65 98f3 7092 d537 2bc3 897e  cD.9\e..p..7+..~
00000130: 25ac 9a34 7a17 b324 17fb 5238 64d9 79e6  %..4z..$..R8d.y.
00000140: cc94 a475 edbc 3675 6372 45d2 01ec c9ae  ...u..6ucrE.....
00000150: e44c 403c d1da 5eec 841e 6d73 acfd 6d6e  .L@<..^...ms..mn
00000160: 3f8d 94cb 4e39 507c 995a 4f3d ac94 9da8  ?...N9P|.ZO=....
00000170: afa5 cb13 2378 3994 da2d 0a2e 5a35 b754  ....#x9..-..Z5.T
00000180: 0943 9a0b 2b92 d151 1a6a 77a6 9c96 abb3  .C..+..Q.jw.....
00000190: ffc1 07                                  ...

```

Try it online!

# Answer
> 3 votes
# Jelly, 164 bytes + 409.846 = 573.846

```
“?#4ß<Ʋƒ⁻µ`kḞÑ6{ɱ~.ṣ¬⁷Ḷlŀ⁸ẎṘ£ỌgfĖỌƒ⁻ḋN?ḤḞ{ị#qp⁵mp&WṘƙ=/rŻ-vn⁼ẊTị}W;!z€ȦMẊẇİ_D8ỴtṫQAẎḣṬr¥1J3Ƙ~ʋ$ĿẠ7þƭ8ṛM{ịḟƇỵ÷b?°6I@?Ȥ⁾d⁹DẈcȷv5ⱮAJb}øDȯRµ’Ds3Ḍ÷³×⁵$2R;6r⁵¤¤;15r18¤¤¦Y

```

Try it online!

There is a compressed number in there that is the concatenation of the first three digits of each energy (including trailing zeroes). I get a list of these three digit numbers with `Ds3Ḍ` then divide each by 100 with `÷³`. Some of the numbers should only be divided by 10, so I multiply some of these by 10 to improve the score slightly (`×⁵$2R;6r⁵¤¤;15r18¤¤¦`).

**Previous version**:

Jelly, 50 bytes + 571.482 penalty = 621.482

```
“¡9;ẋkñ¬nƑḳ_gÐ.RḊụʠṁṬl⁾l>ɼXZĖSṠƈ;cḶ=ß³ṾAiʠʠɼZÞ⁹’DY

```

Try it online!

Rounded each energy to it's nearest single digit integer. Concatenated together this gives `995989999958689999467777788889689999466777777889679999456656666666666657888899996778994556666666666677567888`. `“¡9;ẋkñ¬nƑḳ_gÐ.RḊụʠṁṬl⁾l>ɼXZĖSṠƈ;cḶ=ß³ṾAiʠʠɼZÞ⁹’` is a base 250 number which yields this. `DY` joins the digits of this number with newlines.

# Answer
> 3 votes
# Jelly, 116 bytes \+ 429.796016684433 Penalty = 545.796016684433

```
“tẏØA5X¶tɱḅÐ-ı3OMm⁾¦ȷ #""*00-.Bı0FF_y¤ß÷!"&&)+5,=æ)8=Nc¡ÑÞŒŒŒÞßßñçðıȷñ÷Ø#,//6==@Nȷ*(6AR£ÑØøðñ÷ıııñ÷øþ !€ı#/-,‘+47÷12

```

**Try it online!**

Nothing particularly spectacular, a code-page index list, `“...‘` (numbers between 0 and 249), to each of which we add **47**, `+47`, and then divide by **12**, `÷12`.

# Answer
> 3 votes
# Java 8, 48 bytes + 625.173330827107 Penalty = 673.173330827107

```
v->{for(int i=108;i-->0;System.out.println(6));}

```

Try it online.

Initial version that prints 108 times `6`. Will try to improve from here.

# Answer
> 3 votes
# , 390 bytes + 183.319 Penalty = 573.319

```
d=.'5@-103659=-/-02247,...../////1-/1135,-...////0/0-/0124+--------.--....-.///00012.//012,--.-...--......,..///'
f=.'[ZG@=:U]JX-`~/PD~kB+XrjlKzx_hG~ynkq~1e5_k)+DMAY~nB\ M,y5YUOTZ`c.v}"*29JrVvsK~~6K*I<I?j'';F>y3:"~~3<DRZaz!ppf\'
p=.'tj1;p#Iq<M{^Z1c l~''@/q^aH9*~`J}~v8F~gQiGy8~%ye^F`Gt~-~G1ev>R4E$~F{/mKJ[S~HCrfxXkscWHku;t"c IWZF.n1l',9$' '
echo,.(_40+a.i.d)+(100%~_32+a.i.f)+1e4%~_32+a.i.p

```

Try it online!

I rounded the numbers to four decimal digits and split them into one list for integer parts, one list for the first 2 fraction digits and one for the second 2 fraction digits. I encoded each number with a printable character. For decoding I simpy extract the ingerer and fraction parts of a number from the associated character lists and assemble them back to float.

# , 602 bytes + 0 Penalty = 602

```
q=.'qy7?JOZp@''T1}Ciz={3L/0rHp/r}`M{m^ZHZSy55MYPBaNcV+\?A%/{eyQxQPkDs8W''@m$\6wZsV%KjI''_9"o\XMCP+vU=S3''c3\IKD@ovEW''4LX2O=>n&dgNktY><Ru_TvNpArL?}Y642=}5Hb"yYsD19$<OP2<|Jo)!8S`^9N3w{Q]968P2VF`[(2HOa%XL*V|,[8PcL)}w8"*l%JNC{amnCNx\yH73(pmJGCDq?8@D$ww{X`t0[o.`$''RB&eXiP|_u#9WBFS%U:3|O.U+is5E$A[c{1MpJ@Dw&^rpM_N:M^:o&!HPX9?0i}{j?%2W20z>Q?AOw!fuTWC"Q{-Er'
f=:3 :0
a=.0$0 while.*#y do.l=.1+{.y
a=.a,<' '-.~":}.l{.y
y=.l}.y
end.a
)
echo;(('.',~":"0)&.>_40+a.i.'5@-103659=-/-02247,...../////1-/1135,-...////0/0-/0124+--------.--....-.///00012.//012,--.-...--......,..///'),.(f 12,10#.inv 94x#._32+a.i.q),.<CR

```

Try it online!

This time I went for a slightly different approach. I split the numbers to 2 streams - the first one contains the integer parts which are simply encoded with a single printable character. The second stream contains the entire fractional parts. I removed all intervals between the digits and prepended each substring with its length 1-9 (I tweaked the first fraction, wich is 13 digits long). Then I encoded this list as a base 94 number, presented it as a list of characters.

About 20 bytes can be saved if the verb is rewriten as tacit one.

---
Tags: number, code-challenge, compression
---