Title: How many lights are on?

Body:
You are little speck on a Cartesian plane. Pondering your existence, you decide to roam around your plane and touch things. You notice that every coordinate pair you visit has a light switch. To entertain yourself, you decide to toggle every switch that you come across.

The Challenge: Create a program that will take an input of random length, using only the characters v,^,<, and >. These characters correspond to movements.

< moves you one unit to the left

^ moves you one unit up

> moves you one unit to the right

v moves you one unit down

Using this randomly generated input, calculate how many switches will be left in the ON position, assuming you start at (0,0), all lights begin in the OFF state, and you don't turn on any lights until you make your first move. (Meaning, if you start at (0,0), and move up 1 unit to (0,1), there will now be 1 light on). If you come across a switch that is on the ON position, it will be turned OFF.

Test cases:

```<code>v>v<^^<v<<^<^><<>^^>>><v>vv^v>v^><><<^>><<<vvv^vvv>v>>v><vv^^<<>vv^^>v^<>>^^<^^>^^v<^>^<vvv^v^v><^<<v<<>><<>v>>^><^>^^<>>>>vv>^<<^<<><vvv<v^>>vvv>v^>>><<v^>^^^^v>>^>^v>v<vv^<>^<<v>vv>><^^<^><vv^^v<v<v^^^>v<^vv^v<><vv^^^>v^>v>vv<<^><v<^v><<v^^v>>v<vv<><^^^v<^v><><<^^<>^>><^^^>vv^<>>>>^<^<<<<>>>v<<v<v<vv><<vv<vv<^v^^^>>vv<>v>><<<v^>vv><v<<<v<<>^vvv^<v^v>^^v^v><<v^>>>v<v<v^>>>v><>>>^<><<<<>vv>v><v>v><^v<>v>>>vv<<>^>^>v<^><^<^vv^><^^>v<^^v>v^v<^^^^vv<>v<>><v^^><>v<<<>v^<v^^><>^<>^<>><>^^<>^v><>>><v<^^>>v>^^^<v
</code>```

yields 125 lights on.

```<code>>>><^>>>^vv><^^v^<<<>>^<>>^<^>^<<^^v^<v^>>^<<><<>^v<^^^vv>v><^>>^<^<v><^v<^<<^^v><>>^v<^>^v<vvv<<<v^vv>>^vv>^^<>>vv>^<^>vv<>v^<^v<^^<v^^^<<^><><>^v>vvv<^vvv<vv><vv<^^v^^<^^>>><<<>^<>>><^<<<>><>^v><^^vv<>>><^^^<^>>>>v<v^><<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>v<^<<^^<v<vv<<><v<v^<>^<>v>>v<^v>v<>^^vvv<>vv^v^<><v^vv^<^v^v><>^><v^<>>^^^<>>vv^<v>^^v><v<^>^^^^^^><>>vvv<<><><v<^>v<>v^v<<<<>v^>>>>^v>^^<v^>v><v^<^^v<<<<v<<<>^v<^>^v>v^^>v^^vvv>vv<>^>v><v<>^<vv><>>><<^>>><<v>v^^<^<<<<v^<>>>v<<<^v^vv<>^v>v<<<<>^^>><v><>v<v><^^>><>^>^>v>>><v>^vvvv<><><^>>^v^><<>^v<><><^><<<>v^^>v>^>v^<v^vv<>><^vv^^>^^><vv<<>v>v^^>><v^>^<^<>>>vv<>^>v>v^<>v<^<<v>>>^<>v^>v>>vv^^<>>v<v<<^<>v>v^<^^^>v^^>v>v>vv<^<v>v^^><<<v<><>^^<>v>v>^^v>v>v^v>>^<v^v>><>^^>^<>>>^vv^><v^<^>v^>^v><^>^^^vv^^v<>vv<>>^><<^v>^v^>>v>^v^<<^^^vv<<vvv>^vv^v<<<v^^<<><vv<>>^^vv>^^^vv>><><v>v<^v^>>>vv^><>><v<^v<>^><v<^^^^>><^<>v>^v<^vv>v>v<^<>v>v>^<vv>v<^>vvv<v^<vv<vv<>v>^><v^v<>>>>>v>><^v<>v>^v><v^v^vv<>^<vvv^>><v^<vvv^^<^vvv^v^<>><v>v^^v<><>v^^^v<<<^><v<<<>><<vv<<><vvv^v>>v^v<v^>>><<v<>^v><>vv<<v>v^vv>v^v<^<vv<><><^v>^<vv>v^^>>^^^><vv<><^>>>^<v^<<^^>^>vv^><v<vvv>^^>>>^><<vv>vv>^<>>^^><^v><<>^<<<v^>^
</code>```

yields 1408 lights on.

To generate input, you may use the following Python script:

import random
length = random.randint(15, 10000)
walk = ''
chars = ['v', '<', '>', '^']
for i in range(length):
    walk += random.choice(chars)
print(walk)
```

Standard code-golf scoring, winner is the smallest number of bytes.


问:
Given an integer, compute its Levenshtein code
Disclaimer: Levenshtein coding is completely unrelated to the Levenshtein edit distance metric.

<Insert long story about why Levenshtein codes need to be calculated here.>

The code

Levenshtein coding is a system of assigning binary codes to nonnegative integers that retains some weird property in probability which isn't relevant for this challenge. We will denote this code as L(n). Wikipedia describes this as a five-step process:

Initialize the step count variable C to 1.

Write the binary representation of the number without the leading 1 to the beginning of the code.

Let M be the number of bits written in step 2.

If M is not 0, increment C, repeat from step 2 with M as the new number.

Write C 1 bits and a 0 to the beginning of the code.

However, the code can also be described recursively:

If the number is 0, then its code is 0.

Write the binary representation of the number without the leading 1 to the beginning of the code.

Let M be the number of bits written in step 2.

Write L(M) to the beginning of the code.

Write a 1 bit to the beginning of the code.

For those who prefer examples, here is the recursive process for L(87654321), with  denoting concatenation:

The challenge

Write a program or function that, given a number n, outputs the bitstring L(n) in any reasonable format (this includes returning a number with said bits). Standard loopholes are, as always, disallowed.

Examples

Input: 5

Output: 1110001

Input: 30

Output: 111100001110

Input: 87654321

Output: 111110000101001001110010111111110110001

Input: 0

Output: 0

答:
Ruby, 38 bytes

Very similar to Neil's JavaScript answer.

```<code>f=->n{("%b"%n).sub(/1\K/){f[$'.size]}}
</code>```

See it on repl.it: https://repl.it/CnhQ

ContentLicense: CC BY-SA 3.0

Body:
Ruby, 38 bytes

Very similar to Neil's JavaScript answer.

f=->n{("%b"%n).sub(/1\K/){f[$'.size]}}

See it on repl.it: https://repl.it/CnhQ


问:
All in all it's just, uh, another trick in code golf
The purpose of this challenge is to produce an ASCII version of the cover of this great album by the rock band Pink Floyd.

The brick junctions are made of characters _ and |. Bricks have width 7 and height 2 characters, excluding junctions. So the basic unit, including the junctions, is:

```<code>_________
|       |
|       |
_________
</code>```

Each row of bricks is offset by half a brick width (4 chars) with respect to the previous row:

```<code>________________________________________
  |       |       |       |       |
  |       |       |       |       |
________________________________________
      |       |       |       |       |
      |       |       |       |       |
________________________________________
  |       |       |       |       |
  |       |       |       |       |
</code>```

The wall is parameterized as follows. All parameters are measured in chars including junctions:

Horizontal offset of first row, F. This is the distance between the left margin and the first vertical junction of the upmost row. (Remember also the half-brick relative offset between rows). Its possible values are 0, 1, ..., 7.

Total width, W. This includes junctions. Its value is a positive integer.

Total height, H. This includes junctions. Its value is a positive integer.

The top of the wall always coincides with the top of a row. The bottom may be ragged (if the total height is not a multiple of 3). For example, here's the output for 6, 44, 11:

```<code>____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
  |       |       |       |       |       |
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
</code>```

and a visual explanation of parameters:

```<code>          F=6
         ......
     .   ____________________________________________
     .         |       |       |       |       |
     .         |       |       |       |       |
     .   ____________________________________________
     .     |       |       |       |       |       |
H=11 .     |       |       |       |       |       |
     .   ____________________________________________
     .         |       |       |       |       |
     .         |       |       |       |       |
     .   ____________________________________________
     .     |       |       |       |       |       |

         ............................................
                             W=44
</code>```

Additional rules

You may provide a program or a function.

Input format is flexible as usual. Output may be through STDOUT or an argument returned by a function. In this case it may be a string with newlines or an array of strings.

Trailing spaces or newlines are allowed.

Shortest code in bytes wins.

Test cases

Inputs are in the order given above, that is: horizontal offset of first row, total width, total height.

```<code>6, 44, 11:
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
  |       |       |       |       |       |
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |

2, 20, 10:
____________________
  |       |       |
  |       |       |
____________________
      |       |
      |       |
____________________
  |       |       |
  |       |       |
____________________

1, 1, 1:
_

1, 2, 3:
__
 |
 |

3, 80, 21:
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
</code>```

答:
QBasic, <s>121</s> 109 bytes

(Tested on QB64)

Thanks to @DLosc for golfing my IF statement with a mathematical equivalent.  That was worth 12 bytes.

General Method:

Loop through each cell one at a time and determine whether it should be a _,  , or | depending on its location.  MOD statements and boolean logic are used to determine brick boundaries and how much to stagger the bricks.

Code:

```<code>INPUT F,W,H
FOR y=0TO H-1:FOR x=0TO W-1
?CHR$((y MOD 3>0)*(((x-(y MOD 6>3)*4)MOD 8=F)*92+63)+95);
NEXT:?:NEXT
</code>```

Usage Note:

QBasic expects input to be numbers separated by commas.

ContentLicense: CC BY-SA 4.0

Body:
QBasic, <s>121</s> 109 bytes

(Tested on QB64)

Thanks to @DLosc for golfing my IF statement with a mathematical equivalent.  That was worth 12 bytes.

General Method:

Loop through each cell one at a time and determine whether it should be a _,  , or | depending on its location.  MOD statements and boolean logic are used to determine brick boundaries and how much to stagger the bricks.

Code:

INPUT F,W,H
FOR y=0TO H-1:FOR x=0TO W-1
?CHR$((y MOD 3>0)*(((x-(y MOD 6>3)*4)MOD 8=F)*92+63)+95);
NEXT:?:NEXT

Usage Note:

QBasic expects input to be numbers separated by commas.


答:
Julia: <s>150</s> <s>128</s> <s>116</s> <s>108</s> 107 bytes

```<code># in codegolf.jl
r=repmat;b=r([' '],6,8);b[[1,4],:]='_';b[[2,3,23,24]]='|';b=r(b,h,w)[1:h,o+=1:o+w];b[:,end]=10;print(b'...)
</code>```

to run with arguments: julia -e 'o=2;h=18;w=40;include("codegolf.jl")'

If you feel calling from bash is cheating and you want a function inside the interpreter, then the function version is 117 bytes :)

```<code>f(o,h,w)=(r=repmat;b=r([' '],6,8);b[[1,4],:]='_';b[[2,3,23,24]]='|';b=r(b,h,w)[1:h,o+=1:o+w];b[:,end]=10;print(b'...))
</code>```

demo

(Thanks, @glen-o for the extra byte-saving tip!)

Title: All in all it's just, uh, another trick in code golf

Body:
The purpose of this challenge is to produce an ASCII version of the cover of this great album by the rock band Pink Floyd.

The brick junctions are made of characters _ and |. Bricks have width 7 and height 2 characters, excluding junctions. So the basic unit, including the junctions, is:

```<code>_________
|       |
|       |
_________
</code>```

Each row of bricks is offset by half a brick width (4 chars) with respect to the previous row:

```<code>________________________________________
  |       |       |       |       |
  |       |       |       |       |
________________________________________
      |       |       |       |       |
      |       |       |       |       |
________________________________________
  |       |       |       |       |
  |       |       |       |       |
</code>```

The wall is parameterized as follows. All parameters are measured in chars including junctions:

Horizontal offset of first row, F. This is the distance between the left margin and the first vertical junction of the upmost row. (Remember also the half-brick relative offset between rows). Its possible values are 0, 1, ..., 7.

Total width, W. This includes junctions. Its value is a positive integer.

Total height, H. This includes junctions. Its value is a positive integer.

The top of the wall always coincides with the top of a row. The bottom may be ragged (if the total height is not a multiple of 3). For example, here's the output for 6, 44, 11:

```<code>____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
  |       |       |       |       |       |
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
</code>```

and a visual explanation of parameters:

```<code>          F=6
         ......
     .   ____________________________________________
     .         |       |       |       |       |
     .         |       |       |       |       |
     .   ____________________________________________
     .     |       |       |       |       |       |
H=11 .     |       |       |       |       |       |
     .   ____________________________________________
     .         |       |       |       |       |
     .         |       |       |       |       |
     .   ____________________________________________
     .     |       |       |       |       |       |

         ............................................
                             W=44
</code>```

Additional rules

You may provide a program or a function.

Input format is flexible as usual. Output may be through STDOUT or an argument returned by a function. In this case it may be a string with newlines or an array of strings.

Trailing spaces or newlines are allowed.

Shortest code in bytes wins.

Test cases

Inputs are in the order given above, that is: horizontal offset of first row, total width, total height.

```<code>6, 44, 11:
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
  |       |       |       |       |       |
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |

2, 20, 10:
____________________
  |       |       |
  |       |       |
____________________
      |       |
      |       |
____________________
  |       |       |
  |       |       |
____________________

1, 1, 1:
_

1, 2, 3:
__
 |
 |

3, 80, 21:
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
</code>```

Body:
Julia: <s>150</s> <s>128</s> <s>116</s> <s>108</s> 107 bytes

# in codegolf.jl
r=repmat;b=r([' '],6,8);b[[1,4],:]='_';b[[2,3,23,24]]='|';b=r(b,h,w)[1:h,o+=1:o+w];b[:,end]=10;print(b'...)

to run with arguments: julia -e 'o=2;h=18;w=40;include("codegolf.jl")'

If you feel calling from bash is cheating and you want a function inside the interpreter, then the function version is 117 bytes :)

f(o,h,w)=(r=repmat;b=r([' '],6,8);b[[1,4],:]='_';b[[2,3,23,24]]='|';b=r(b,h,w)[1:h,o+=1:o+w];b[:,end]=10;print(b'...))

demo

(Thanks, @glen-o for the extra byte-saving tip!)


问:
How many lights are on?
You are little speck on a Cartesian plane. Pondering your existence, you decide to roam around your plane and touch things. You notice that every coordinate pair you visit has a light switch. To entertain yourself, you decide to toggle every switch that you come across.

The Challenge: Create a program that will take an input of random length, using only the characters v,^,<, and >. These characters correspond to movements.

< moves you one unit to the left

^ moves you one unit up

> moves you one unit to the right

v moves you one unit down

Using this randomly generated input, calculate how many switches will be left in the ON position, assuming you start at (0,0), all lights begin in the OFF state, and you don't turn on any lights until you make your first move. (Meaning, if you start at (0,0), and move up 1 unit to (0,1), there will now be 1 light on). If you come across a switch that is on the ON position, it will be turned OFF.

Test cases:

```<code>v>v<^^<v<<^<^><<>^^>>><v>vv^v>v^><><<^>><<<vvv^vvv>v>>v><vv^^<<>vv^^>v^<>>^^<^^>^^v<^>^<vvv^v^v><^<<v<<>><<>v>>^><^>^^<>>>>vv>^<<^<<><vvv<v^>>vvv>v^>>><<v^>^^^^v>>^>^v>v<vv^<>^<<v>vv>><^^<^><vv^^v<v<v^^^>v<^vv^v<><vv^^^>v^>v>vv<<^><v<^v><<v^^v>>v<vv<><^^^v<^v><><<^^<>^>><^^^>vv^<>>>>^<^<<<<>>>v<<v<v<vv><<vv<vv<^v^^^>>vv<>v>><<<v^>vv><v<<<v<<>^vvv^<v^v>^^v^v><<v^>>>v<v<v^>>>v><>>>^<><<<<>vv>v><v>v><^v<>v>>>vv<<>^>^>v<^><^<^vv^><^^>v<^^v>v^v<^^^^vv<>v<>><v^^><>v<<<>v^<v^^><>^<>^<>><>^^<>^v><>>><v<^^>>v>^^^<v
</code>```

yields 125 lights on.

```<code>>>><^>>>^vv><^^v^<<<>>^<>>^<^>^<<^^v^<v^>>^<<><<>^v<^^^vv>v><^>>^<^<v><^v<^<<^^v><>>^v<^>^v<vvv<<<v^vv>>^vv>^^<>>vv>^<^>vv<>v^<^v<^^<v^^^<<^><><>^v>vvv<^vvv<vv><vv<^^v^^<^^>>><<<>^<>>><^<<<>><>^v><^^vv<>>><^^^<^>>>>v<v^><<>v<v<v^<<^><v^^><>v>^<>^^^vvv<v^>^^^^v>v<v>>>v^^<v<vv>><<>^vv><<vv<<>^^v>>v<^^v>><v<v<<>^^vv>>^v>v>v<>^>^v<>>><>v>v<<v<^<>>>vv>>v>^<>vv^v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<v^>v><v^<^^v<<<<v<<<>^v<^>^v>v^^>v^^vvv>vv<>^>v><v<>^<vv><>>><<^>>><<v>v^^<^<<<<v^<>>>v<<<^v^vv<>^v>v<<<<>^^>><v><>v<v><^^>><>^>^>v>>><v>^vvvv<><><^>>^v^><<>^v<><><^><<<>v^^>v>^>v^<v^vv<>><^vv^^>^^><vv<<>v>v^^>><v^>^<^<>>>vv<>^>v>v^<>v<^<<v>>>^<>v^>v>>vv^^<>>v<v<<^<>v>v^<^^^>v^^>v>v>vv<^<v>v^^><<<v<><>^^<>v>v>^^v>v>v^v>>^<v^v>><>^^>^<>>>^vv^><v^<^>v^>^v><^>^^^vv^^v<>vv<>>^><<^v>^v^>>v>^v^<<^^^vv<<vvv>^vv^v<<<v^^<<><vv<>>^^vv>^^^vv>><><v>v<^v^>>>vv^><>><v<^v<>^><v<^^^^>><^<>v>^v<^vv>v>v<^<>v>v>^<vv>v<^>vvv<v^<vv<vv<>v>^><v^v<>>>>>v>><^v<>v>^v><v^v^vv<>^<vvv^>><v^<vvv^^<^vvv^v^<>><v>v^^v<><>v^^^v<<<^><v<<<>><<vv<<><vvv^v>>v^v<v^>>><<v<>^v><>vv<<v>v^vv>v^v<^<vv<><><^v>^<vv>v^^>>^^^><vv<><^>>>^<v^<<^^>^>vv^><v<vvv>^^>>>^><<vv>vv>^<>>^^><^v><<>^<<<v^>^
</code>```

yields 1408 lights on.

To generate input, you may use the following Python script:

import random
length = random.randint(15, 10000)
walk = ''
chars = ['v', '<', '>', '^']
for i in range(length):
    walk += random.choice(chars)
print(walk)
```

Standard code-golf scoring, winner is the smallest number of bytes.

答:
R, 172 156  137  101 96 bytes

```<code>n=function(a)sum(table(cumsum(sapply(strsplit(a,"")[[1]],switch,v=-1,"^"=1,">"=1i,"<"=-1i)))%%2)
</code>```

Using @LeakyNun's complex plane idea.

ungolfed

```<code>n=function(a){
    b=strsplit(a,"")[[1]]                        #Splits String up
    p=sapply(b,switch,v=-1,"^"=1,">"=1i,"<"=-1i) #Replaces characters with directions
    q=cumsum(p)                                  #Finds each location visitied
    t=table(q)%%2                                #Determines if spots were visited an odd # of times
    sum(t)                                       #counts odd visited spots
}
</code>```

Title: How many lights are on?

Body:
R, 172 156  137  101 96 bytes

n=function(a)sum(table(cumsum(sapply(strsplit(a,"")[[1]],switch,v=-1,"^"=1,">"=1i,"<"=-1i)))%%2)

Using @LeakyNun's complex plane idea.

ungolfed

n=function(a){
    b=strsplit(a,"")[[1]]                        #Splits String up
    p=sapply(b,switch,v=-1,"^"=1,">"=1i,"<"=-1i) #Replaces characters with directions
    q=cumsum(p)                                  #Finds each location visitied
    t=table(q)%%2                                #Determines if spots were visited an odd # of times
    sum(t)                                       #counts odd visited spots
}


问:
Play a sound, any sound
Your program has to make the computer produce a sound, any sound.

Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins.

The program should run on a reasonable, not too uncommon personal computer.

Opening a pop-up, message box, etc. (for example, on a web page) does not count, as they might or might not produce a sound, depending on a lot of settings.

Just entering a wrong command or invalid character on a console and receiving a warning beep does not count, just as the compiler/interpreter/OS beeping on an error or crash does not count either. Your code must be a valid program.

答:
Golfscript 3

```<code>'.'
</code>```

(where the . is in fact a BELL character)

The HEX representation of the above code is:

```<code>27 07 27
</code>```

Title: Play a sound, any sound

Body:
Golfscript 3

'.'

(where the . is in fact a BELL character)

The HEX representation of the above code is:

27 07 27


问:
Identify a string from its substrings

Introduction

I've previously created two challenges where the idea is to reconstruct an object using as few query-type operations as possible; this will be the third.

The task

Your inputs shall be a non-empty string S over the alphabet abc and its length, and your output shall be S.
With no restrictions, this would of course be a trivial task; the catch is that you're not allowed to access S directly.
The only thing you're allowed to do to S is to call the function num_occur(T, S), where T is some other string, and num_occur counts the number of occurrences of T in S.
Overlapping occurrences are counted as distinct, so num_occur(T, S) really returns the number of indices i such that

```<code>S[i, i+1, …, i+length(T)-1] == T</code>```

For example, num_occur("aba", "cababaababb") will return 3.
Note also that num_occur(S, S) will return 1.
The result of num_occur("", S) is undefined, and you should not call the function on an empty string.

In short, you should write a function or program that takes S and length(S) as inputs, calls num_occur on some shorter strings and S some number of times, reconstructs S from that information and returns it.

Rules and scoring

Your goal is to write a program that makes as few calls to num_occur as possible.
In this repository, you will find a file called abc_strings.txt.
The file contains 100 strings, each on its own line, between lengths 50 and 99.
Your score is the total number of calls to num_occur on these inputs, lower score being better.
Your solution will preferably keep track of this number as it runs, and print it upon finishing.
The strings are generated by choosing uniformly random letters from abc; you are allowed to optimize for this method of generating the strings, but not the strings themselves.

There is no time limit, except that you should run your solution on the test cases before submitting it.
You solution should work for any valid input S, not just the test cases.

You are encouraged to share your implementation of num_occur too, if you're not using someone else's.
To get the ball rolling, here's an implementation in Python:

```<code>def num_occur(needle, haystack):
    num = 0
    for i in range(len(haystack) - len(needle) + 1):
        if haystack[i : i + len(needle)] == needle:
            num += 1
    return num
</code>```

答:
Python, 15205 calls

```<code>def findS(S, len_s, alphabeth = "abc"):
    if len_s == 0:
        return ""
    current = ""
    add_at_start = True
    while len(current) < len_s:
        worked = False
        for letter in alphabeth:
            if add_at_start:
                current_new = current + letter
            else:
                current_new = letter + current
            if num_occur(current_new, S) > 0:
                current = current_new
                worked = True
                break
        if not worked:
            add_at_start = False
    return current
</code>```

This submission is most likely suboptimal, because it only uses num_occur to check if a string is a substring of S, and it never uses it to actually count the amount of substrings.

The algorithm works by storing a string current which is built up to be equal to S in the end. Here are all the steps in the algorithm:

We set current equal to ''

Go through each letter in the alphabet, and do the following:

2.1. Create a new string current_new, and set it equals to current followed by the letter.

2.2. Check if current_new is included in S by running num_occur on it and see if the result is greater than one.

2.3. If current_new is included in S, set current to current_new and go back to step 2. Else, we go to the next letter.

If the length of current is equal to the length of S we can say that we are done. Else, we go back to step 2, but modify step 2.1 to make current_new equal to the letter followed by current instead. When we reach this step again, we are done.

Title: Identify a string from its substrings

Body:
Python, 15205 calls

def findS(S, len_s, alphabeth = "abc"):
    if len_s == 0:
        return ""
    current = ""
    add_at_start = True
    while len(current) < len_s:
        worked = False
        for letter in alphabeth:
            if add_at_start:
                current_new = current + letter
            else:
                current_new = letter + current
            if num_occur(current_new, S) > 0:
                current = current_new
                worked = True
                break
        if not worked:
            add_at_start = False
    return current

This submission is most likely suboptimal, because it only uses num_occur to check if a string is a substring of S, and it never uses it to actually count the amount of substrings.

The algorithm works by storing a string current which is built up to be equal to S in the end. Here are all the steps in the algorithm:

We set current equal to ''

Go through each letter in the alphabet, and do the following:

2.1. Create a new string current_new, and set it equals to current followed by the letter.

2.2. Check if current_new is included in S by running num_occur on it and see if the result is greater than one.

2.3. If current_new is included in S, set current to current_new and go back to step 2. Else, we go to the next letter.

If the length of current is equal to the length of S we can say that we are done. Else, we go back to step 2, but modify step 2.1 to make current_new equal to the letter followed by current instead. When we reach this step again, we are done.


问:
Print/Output all positive numbers in which every multi-digit substring in its decimal representation is also prime.

Task

Your task is to print or output all positive numbers in which every multi-digit substring in its decimal representation is also prime. If the number has at least 2 digits, this would imply that the number itself also needs to be prime.

Example

6197 is in the sequence because every multi-digit substring in 6197 is prime, namely: 61, 19, 97, 619, 197, 6197 (itself).

Note that 6 is not a prime but 6197 is still in the sequence because 6 is not a multi-digit substring of 6197.

8 is also in the sequence because every multi-digit substring in 8 is prime. There is no multi-digit substring in 8, so this is a case of vacuous truth.

Specs

Standard loopholes apply, except that you are allowed to hardcode the output or store information related to the output in your program.

The numbers in the output can be in any order.

The numbers in the output are allowed to have duplicates.

You may use any separator, if you choose to print instead of output.

You are allowed to prefix and/or postfix output if you choose to print instead of output.

The separator and the prefix and the postfix may not contain any digits (U+0030 to U+0039).

Full list (58 items)

```<code>1
2
3
4
5
6
7
8
9
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
113
131
137
173
179
197
311
313
317
373
379
419
431
479
613
617
619
673
719
797
971
1373
3137
3797
6131
6173
6197
9719
</code>```

Reference

OEIS A131648 (incomplete list)

As always, please feel free to address in the comments anything I should clarify.

答:
Ruby, 81 + 8 = 89 bytes

+8 bytes for -rprime.

```<code>puts (?1..?9*4).select{|m|(r=2..m.size).all?{|i|r.all?{|j|m[i-2,j].to_i.prime?}}}
</code>```

See it on repl.it: https://repl.it/CniR/2

Body:
Ruby, 81 + 8 = 89 bytes

+8 bytes for -rprime.

puts (?1..?9*4).select{|m|(r=2..m.size).all?{|i|r.all?{|j|m[i-2,j].to_i.prime?}}}

See it on repl.it: https://repl.it/CniR/2


答:
Perl 6, <s> 47 44 </s> 43 bytes

<s>for 1..9719 {all(m:ex/..+/).Int.is-prime&&.say}
put grep {is-prime +all(m:ex/..+/):},1..9719</s>
put grep {is-prime +all m:ex/..+/:},1..9719```

<h2>Explanation:</h2>

<pre class="lang-perl6 prettyprint-override"><code># print the values space separated, with trailing newline
put

# that match
grep -> $_ {

  # call the method ｢.is-prime｣ ( that is what ｢:｣ is for )
  # (autothreaded)
  is-prime

  # convert following to numeric (autothreaded)
  +
  # a junction of
  all(
    # all substrings 2 characters or greater
    $_ ~~ m :exhaustive / . .+ /
  )

  # needed to indicate that ｢is-prime｣ is a method call
  :

},

# in this Range
1..9719
</code>```

Title: Print/Output all positive numbers in which every multi-digit substring in its decimal representation is also prime.

Body:
Task

Your task is to print or output all positive numbers in which every multi-digit substring in its decimal representation is also prime. If the number has at least 2 digits, this would imply that the number itself also needs to be prime.

Example

6197 is in the sequence because every multi-digit substring in 6197 is prime, namely: 61, 19, 97, 619, 197, 6197 (itself).

Note that 6 is not a prime but 6197 is still in the sequence because 6 is not a multi-digit substring of 6197.

8 is also in the sequence because every multi-digit substring in 8 is prime. There is no multi-digit substring in 8, so this is a case of vacuous truth.

Specs

Standard loopholes apply, except that you are allowed to hardcode the output or store information related to the output in your program.

The numbers in the output can be in any order.

The numbers in the output are allowed to have duplicates.

You may use any separator, if you choose to print instead of output.

You are allowed to prefix and/or postfix output if you choose to print instead of output.

The separator and the prefix and the postfix may not contain any digits (U+0030 to U+0039).

Full list (58 items)

```<code>1
2
3
4
5
6
7
8
9
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
113
131
137
173
179
197
311
313
317
373
379
419
431
479
613
617
619
673
719
797
971
1373
3137
3797
6131
6173
6197
9719
</code>```

Reference

OEIS A131648 (incomplete list)

As always, please feel free to address in the comments anything I should clarify.

Body:
Perl 6, <s> 47 44 </s> 43 bytes

<s>for 1..9719 {all(m:ex/..+/).Int.is-prime&&.say}
put grep {is-prime +all(m:ex/..+/):},1..9719</s>
put grep {is-prime +all m:ex/..+/:},1..9719

Explanation:

# print the values space separated, with trailing newline
put

# that match
grep -> $_ {

  # call the method ｢.is-prime｣ ( that is what ｢:｣ is for )
  # (autothreaded)
  is-prime

  # convert following to numeric (autothreaded)
  +
  # a junction of
  all(
    # all substrings 2 characters or greater
    $_ ~~ m :exhaustive / . .+ /
  )

  # needed to indicate that ｢is-prime｣ is a method call
  :

},

# in this Range
1..9719


答:
MATL, <s>42</s> <s>36</s> 33 bytes

```<code>:-Q'_ | |'[DClCl]Y"8et4YShwi:3$)!
</code>```

Input format is: nCols, offset, nRows

Try it Online

The approach here is that we setup a "template" which we then index into by using the row indices ([1 2 ... nRows]) and column indices  shifted by the first input ([1 2 ... nCols] - shift). Thanks to MATL's modular indexing, it will automatically result in a tiled output. As a side-note, to save some space, technically I work with a transposed version of the template and then just take a transpose (!) at the end.

The template is this:

```<code>________
       |
       |
________
  |
  |
</code>```

Body:
MATL, <s>42</s> <s>36</s> 33 bytes

:-Q'_ | |'[DClCl]Y"8et4YShwi:3$)!

Input format is: nCols, offset, nRows

Try it Online

The approach here is that we setup a "template" which we then index into by using the row indices ([1 2 ... nRows]) and column indices  shifted by the first input ([1 2 ... nCols] - shift). Thanks to MATL's modular indexing, it will automatically result in a tiled output. As a side-note, to save some space, technically I work with a transposed version of the template and then just take a transpose (!) at the end.

The template is this:

________
       |
       |
________
  |
  |


答:
Python 2, <s>14952</s> 14754 calls

Very similar to the first answer, but doesn't try next characters which result in impossible substrings that:

we know from num_occur that they don't occur in the target (from previous calls)

we already used the substring more often than it occurs according to num_occur

<s>(will add counting of substrings in a minute)</s> done

```<code>def get_that_string(h,l,alpha = "abc"):
    dic = {}
    s = ""
    ##costs 1 additional call per example, but its worth it
    char_list = [num_occur(j,h) for j in alpha[:-1]]
    char_list.append(l - sum(char_list))
    for y, z in zip(char_list,alpha):
        dic[z] = y
    end_reached = False
    while len(s) < l:
        for t in alpha:
            if not end_reached:
                neu_s = s + t
                substrings = [neu_s[i:]   for i in range(len(neu_s))]
            else:
                neu_s = t + s
                substrings = [neu_s[:i+1] for i in range(len(neu_s))]
            ## Test if we know that that can't be the next char
            all_in_d = [suff for suff in substrings if suff in dic.keys()]
            poss=all(map(dic.get,all_in_d))
            if poss:
                if not neu_s in dic.keys():
                    dic[neu_s] = num_occur(neu_s,h)
                if dic[neu_s] > 0:
                    s=neu_s
                    for suff in all_in_d:
                        dic[suff] -= 1
                    break
        else:
            end_reached = True
    ##print s
    return s

## test suite start
import urllib

def num_occur(needle, haystack):
    global calls
    calls += 1
    num = 0
    for i in range(len(haystack) - len(needle) + 1):
        if haystack[i : i + len(needle)] == needle:
            num += 1
    return num

calls = 0
url = "https://raw.githubusercontent.com/iatorm/random-data/master/abc_strings.txt"
inputs = urllib.urlopen(url).read().split("\n")
print "Check: ", inputs == map(lambda h: get_that_string(h, len(h)), inputs)
print "Calls: ", calls
</code>```

Title: Identify a string from its substrings

Body:
Introduction

I've previously created two challenges where the idea is to reconstruct an object using as few query-type operations as possible; this will be the third.

The task

Your inputs shall be a non-empty string S over the alphabet abc and its length, and your output shall be S.
With no restrictions, this would of course be a trivial task; the catch is that you're not allowed to access S directly.
The only thing you're allowed to do to S is to call the function num_occur(T, S), where T is some other string, and num_occur counts the number of occurrences of T in S.
Overlapping occurrences are counted as distinct, so num_occur(T, S) really returns the number of indices i such that

```<code>S[i, i+1, …, i+length(T)-1] == T</code>```

For example, num_occur("aba", "cababaababb") will return 3.
Note also that num_occur(S, S) will return 1.
The result of num_occur("", S) is undefined, and you should not call the function on an empty string.

In short, you should write a function or program that takes S and length(S) as inputs, calls num_occur on some shorter strings and S some number of times, reconstructs S from that information and returns it.

Rules and scoring

Your goal is to write a program that makes as few calls to num_occur as possible.
In this repository, you will find a file called abc_strings.txt.
The file contains 100 strings, each on its own line, between lengths 50 and 99.
Your score is the total number of calls to num_occur on these inputs, lower score being better.
Your solution will preferably keep track of this number as it runs, and print it upon finishing.
The strings are generated by choosing uniformly random letters from abc; you are allowed to optimize for this method of generating the strings, but not the strings themselves.

There is no time limit, except that you should run your solution on the test cases before submitting it.
You solution should work for any valid input S, not just the test cases.

You are encouraged to share your implementation of num_occur too, if you're not using someone else's.
To get the ball rolling, here's an implementation in Python:

```<code>def num_occur(needle, haystack):
    num = 0
    for i in range(len(haystack) - len(needle) + 1):
        if haystack[i : i + len(needle)] == needle:
            num += 1
    return num
</code>```

Body:
Python 2, <s>14952</s> 14754 calls

Very similar to the first answer, but doesn't try next characters which result in impossible substrings that:

we know from num_occur that they don't occur in the target (from previous calls)

we already used the substring more often than it occurs according to num_occur

<s>(will add counting of substrings in a minute)</s> done

def get_that_string(h,l,alpha = "abc"):
    dic = {}
    s = ""
    ##costs 1 additional call per example, but its worth it
    char_list = [num_occur(j,h) for j in alpha[:-1]]
    char_list.append(l - sum(char_list))
    for y, z in zip(char_list,alpha):
        dic[z] = y
    end_reached = False
    while len(s) < l:
        for t in alpha:
            if not end_reached:
                neu_s = s + t
                substrings = [neu_s[i:]   for i in range(len(neu_s))]
            else:
                neu_s = t + s
                substrings = [neu_s[:i+1] for i in range(len(neu_s))]
            ## Test if we know that that can't be the next char
            all_in_d = [suff for suff in substrings if suff in dic.keys()]
            poss=all(map(dic.get,all_in_d))
            if poss:
                if not neu_s in dic.keys():
                    dic[neu_s] = num_occur(neu_s,h)
                if dic[neu_s] > 0:
                    s=neu_s
                    for suff in all_in_d:
                        dic[suff] -= 1
                    break
        else:
            end_reached = True
    ##print s
    return s

## test suite start
import urllib

def num_occur(needle, haystack):
    global calls
    calls += 1
    num = 0
    for i in range(len(haystack) - len(needle) + 1):
        if haystack[i : i + len(needle)] == needle:
            num += 1
    return num

calls = 0
url = "https://raw.githubusercontent.com/iatorm/random-data/master/abc_strings.txt"
inputs = urllib.urlopen(url).read().split("\n")
print "Check: ", inputs == map(lambda h: get_that_string(h, len(h)), inputs)
print "Calls: ", calls


Body:
JavaScript, <s>172</s> <s>168</s> <s>165</s> <s>157</s> <s>147</s> <s>142</s> 137 bytes

(O,W,H)=>{t='_'.repeat(W),x='|       '.repeat(W),f=t+`
`;for(i=0;++i<H;)f+=(!(i%3)?t:(i%6)>3?x.substr(O,W):x.substr(8-O,W))+`
`;return f}

N = (O,W,H)=>{t='_'.repeat(W),x='|       '.repeat(W),f=t+`
`;for(i=0;++i<H;)f+=(!(i%3)?t:(i%6)>3?x.substr(O,W):x.substr(8-O,W))+`
`;return f}

let test_data = [[6,44,11],
                 [2,20,10],
                 [1,1,1],
                 [1,2,3],
                 [3,80,21]];

for (test of test_data)
    console.log(N(...test));


答:
C# <s>210</s> <s>205</s> <s>139</s> <s>138</s> <s>135</s> <s>128</s> 113 Bytes

```<code>using System.Linq;int f(string s,int x=0,int y=0)=>s.GroupBy(c=>(x+=c%6%3-1)+s+(y-=c/3%6-2)).Sum(g=>g.Count()%2);
</code>```

Explanation

```<code>//Have X and Y as default params allows us to use a expression bodied member
//and then remove the return statement
int f(string s, int x = 0, int y = 0) =>

    //treat the string as a char array
    s.GroupBy(c =>

            //Using the unerlying int of the char this math reduces down to either x - 1, x + 1, x + 0, y - 1 or y + 1, or y + 0
            //Concat the resulting values with the original string to ensure uniqueness ie x=1 and y=11 vs x=11 and y=1 for the grouping
            (x += c % 6 % 3 - 1) + s + (y -= c / 3 % 6 - 2))

     //Mod 2 will return either 1 or 0 so we can use sum to count the groups with odd counts
     .Sum(g => g.Count() % 2);
</code>```

Thanks to VisualMelon for 5 bytes switching Count to Sum

Thanks again to VisualMelon, this time for 66 bytes by suggesting some fancy math to get the translations.

VisualMelon to the rescue again with combining the select and group by for 13 bytes and just using the input string for the x/y separator for another 2

Title: How many lights are on?

Body:
C# <s>210</s> <s>205</s> <s>139</s> <s>138</s> <s>135</s> <s>128</s> 113 Bytes

using System.Linq;int f(string s,int x=0,int y=0)=>s.GroupBy(c=>(x+=c%6%3-1)+s+(y-=c/3%6-2)).Sum(g=>g.Count()%2);

Explanation

//Have X and Y as default params allows us to use a expression bodied member
//and then remove the return statement
int f(string s, int x = 0, int y = 0) =>

    //treat the string as a char array
    s.GroupBy(c =>

            //Using the unerlying int of the char this math reduces down to either x - 1, x + 1, x + 0, y - 1 or y + 1, or y + 0
            //Concat the resulting values with the original string to ensure uniqueness ie x=1 and y=11 vs x=11 and y=1 for the grouping
            (x += c % 6 % 3 - 1) + s + (y -= c / 3 % 6 - 2))

     //Mod 2 will return either 1 or 0 so we can use sum to count the groups with odd counts
     .Sum(g => g.Count() % 2);

Thanks to VisualMelon for 5 bytes switching Count to Sum

Thanks again to VisualMelon, this time for 66 bytes by suggesting some fancy math to get the translations.

VisualMelon to the rescue again with combining the select and group by for 13 bytes and just using the input string for the x/y separator for another 2


问:
Output "Fit" numbers

"Fit Numbers"

Sam has a "brilliant" idea for compression! Can you help?

Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.

```
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17 -> 10001
65535 -> 111111111111111
```

Now replace any group of one or more zeros with a single zero. This is because the number has gotten leaner. Your binary string now will look like this.

```
1 -> 1 -> 1
9 -> 1001 -> 101
15 ->1111 -> 1111
13 ->1101 -> 1101
16 -> 10000 -> 10
17 -> 10001 -> 101
65535 -> 111111111111111 -> 111111111111111
```

Now you convert the binary string back to a base 10 representation, and output it in any acceptable format. Here are your test cases. The first integer represents an input, and the last integer represents an output. Note that some numbers do not change, and thus can be called "fit"

```
1 -> 1 -> 1 -> 1
9 -> 1001 -> 101 -> 5
15 ->1111 -> 1111 -> 15
13 ->1101 -> 1101 -> 13
16 -> 10000 -> 10 -> 2
17 -> 10001 -> 101 -> 5
65535 -> 1111111111111111 -> 1111111111111111 -> 65535
65000 -> 1111110111101000 -> 11111101111010 -> 16250
```

You may use any language, but please note that Sam hates standard loopholes. This is code golf so the code can be as short as possible to make room for the "compressed" numbers".

Note:This is NOT an acceptable compression scheme. Using this will promptly get you fired.

Citation-Needed: I do not take credit for this concept. This comes from @Conor O' Brien's blog here see this OEIS of fit numbers. https://oeis.org/A090078

答:
Reference Implementation in S.I.L.O.S "only" 417 bytes

Golfed

```<code>readIO :
i + 1
I = i
z = 1
n = 32
b = n
z = 1
n = b
lbla
n - 1
GOSUB p
j = i
j - p
if j b
if z c
z = 1
GOTO e
lblc
b - 1
if n a
GOTO f
lblb
z = 0
A = a
A + 1000
set A 1
i - p
lble
a + 1
if n a
lblf
q = 1000
e = q
e + b
i = 0
lbl>
d = q
d - e
if d ?
n = b
n - i
GOSUB p
g = get q
g * p
o + g
i + 1
q + 1
GOTO >
lbl?
o / 2
printInt o
GOTO z
funcp
p = 1
Z = n
lblQ
if Z C
GOTO D
lblC
Z - 1
p * 2
GOTO Q
lblD
return
lblz
</code>```

Here is the reference implementation fully ungolfed. As a bonus feature it outputs the steps needed to come to an answer.

```<code>/**
*Reference Implementation in the high quality S.I.L.O.S language.
*/
readIO Enter a number to "compress"
//some declarations
i + 1
I = i
z = 1
//the above is a flag which shows whether or not a zero was last outputted
n = 32
b = n
//maximum number of input bits
printLine Original Binary

lblbinLoop
n - 1
GOSUB pow
j = I
j - p
if j printOne
if z ENDLOOP
print 0
GOTO ENDLOOP
lblprintOne
z = 0
print 1
I - p
lblENDLOOP
if n binLoop

printLine
printLine Binary "Compressed"

z = 1
n = b

lbltopA
n - 1
GOSUB pow
j = i
j - p
if j printAOne
if z DontPrint
z = 1
print 0
GOTO ENDLOOPA
lblDontPrint
b - 1
if n topA
GOTO endOfBin
lblprintAOne
z = 0
print 1
A = a
A + 1000
set A 1
i - p
lblENDLOOPA
a + 1
if n topA

lblendOfBin

printLine
printLine -----------
printLine Base 10 Output
print Out Bits:
printInt b

q = 1000
e = q
e + b
i = 0
lblOutputDec
d = q
d - e
if d DONE
n = b
n - i
GOSUB pow
g = get q
g * p
o + g
i + 1
q + 1
GOTO OutputDec
lblDONE
printLine
printLine ---------
o / 2
printInt o

GOTO funcs
//function declarations must be wrapped in gotoes to avoid the interpreter from complaining (breaking)

/**
*This will store the nth power of two in the "p" variable
*/
funcpow
p = 1
Z = n
lbltop
if Z continue
GOTO end
lblcontinue
Z - 1
p * 2
GOTO top
lblend
return

lblfuncs
</code>```

By request the transpilation has been deleted. Feel free to view the edit history to recover it, otherwise go to this repo for an interpreter.

Sample output for 65000

```<code>Enter a number to "compress"
65000
Original Binary
1111110111101000
Binary "Compressed"
11111101111010
-----------
Base 10 Output
Out Bits:14
---------
16250
</code>```

Title: Output "Fit" numbers

Body:
Reference Implementation in S.I.L.O.S "only" 417 bytes

Golfed

readIO :
i + 1
I = i
z = 1
n = 32
b = n
z = 1
n = b
lbla
n - 1
GOSUB p
j = i
j - p
if j b
if z c
z = 1
GOTO e
lblc
b - 1
if n a
GOTO f
lblb
z = 0
A = a
A + 1000
set A 1
i - p
lble
a + 1
if n a
lblf
q = 1000
e = q
e + b
i = 0
lbl>
d = q
d - e
if d ?
n = b
n - i
GOSUB p
g = get q
g * p
o + g
i + 1
q + 1
GOTO >
lbl?
o / 2
printInt o
GOTO z
funcp
p = 1
Z = n
lblQ
if Z C
GOTO D
lblC
Z - 1
p * 2
GOTO Q
lblD
return
lblz

Here is the reference implementation fully ungolfed. As a bonus feature it outputs the steps needed to come to an answer.

/**
*Reference Implementation in the high quality S.I.L.O.S language.
*/
readIO Enter a number to "compress"
//some declarations
i + 1
I = i
z = 1
//the above is a flag which shows whether or not a zero was last outputted
n = 32
b = n
//maximum number of input bits
printLine Original Binary

lblbinLoop
n - 1
GOSUB pow
j = I
j - p
if j printOne
if z ENDLOOP
print 0
GOTO ENDLOOP
lblprintOne
z = 0
print 1
I - p
lblENDLOOP
if n binLoop

printLine
printLine Binary "Compressed"

z = 1
n = b

lbltopA
n - 1
GOSUB pow
j = i
j - p
if j printAOne
if z DontPrint
z = 1
print 0
GOTO ENDLOOPA
lblDontPrint
b - 1
if n topA
GOTO endOfBin
lblprintAOne
z = 0
print 1
A = a
A + 1000
set A 1
i - p
lblENDLOOPA
a + 1
if n topA

lblendOfBin

printLine
printLine -----------
printLine Base 10 Output
print Out Bits:
printInt b

q = 1000
e = q
e + b
i = 0
lblOutputDec
d = q
d - e
if d DONE
n = b
n - i
GOSUB pow
g = get q
g * p
o + g
i + 1
q + 1
GOTO OutputDec
lblDONE
printLine
printLine ---------
o / 2
printInt o

GOTO funcs
//function declarations must be wrapped in gotoes to avoid the interpreter from complaining (breaking)

/**
*This will store the nth power of two in the "p" variable
*/
funcpow
p = 1
Z = n
lbltop
if Z continue
GOTO end
lblcontinue
Z - 1
p * 2
GOTO top
lblend
return

lblfuncs

By request the transpilation has been deleted. Feel free to view the edit history to recover it, otherwise go to this repo for an interpreter.

Sample output for 65000

Enter a number to "compress"
65000
Original Binary
1111110111101000
Binary "Compressed"
11111101111010
-----------
Base 10 Output
Out Bits:14
---------
16250


答:
Mathematica 6

This will evoke the system beep.  On my computer, it is currently a chirp.

```<code>Beep[]
</code>```

Title: Play a sound, any sound

Body:
Your program has to make the computer produce a sound, any sound.

Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins.

The program should run on a reasonable, not too uncommon personal computer.

Opening a pop-up, message box, etc. (for example, on a web page) does not count, as they might or might not produce a sound, depending on a lot of settings.

Just entering a wrong command or invalid character on a console and receiving a warning beep does not count, just as the compiler/interpreter/OS beeping on an error or crash does not count either. Your code must be a valid program.

Body:
Mathematica 6

This will evoke the system beep.  On my computer, it is currently a chirp.

Beep[]


答:
Actually, 14 bytes

```<code>├`'0;;+(Æ`Y2@¿
</code>```

Try it online!

Explanation:

```<code>├`'0;;+(Æ`Y2@¿
├               bin(input) (automatically discards leading zeroes)
 `'0;;+(Æ`Y     call this function until the output stops changing:
  '0;;+           push "0", "00"
       (Æ         replace "00" with "0" in binary string
           2@¿  convert from binary to decimal
</code>```

Title: Output "Fit" numbers

Body:
"Fit Numbers"

Sam has a "brilliant" idea for compression! Can you help?

Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.

```
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17 -> 10001
65535 -> 111111111111111
```

Now replace any group of one or more zeros with a single zero. This is because the number has gotten leaner. Your binary string now will look like this.

```
1 -> 1 -> 1
9 -> 1001 -> 101
15 ->1111 -> 1111
13 ->1101 -> 1101
16 -> 10000 -> 10
17 -> 10001 -> 101
65535 -> 111111111111111 -> 111111111111111
```

Now you convert the binary string back to a base 10 representation, and output it in any acceptable format. Here are your test cases. The first integer represents an input, and the last integer represents an output. Note that some numbers do not change, and thus can be called "fit"

```
1 -> 1 -> 1 -> 1
9 -> 1001 -> 101 -> 5
15 ->1111 -> 1111 -> 15
13 ->1101 -> 1101 -> 13
16 -> 10000 -> 10 -> 2
17 -> 10001 -> 101 -> 5
65535 -> 1111111111111111 -> 1111111111111111 -> 65535
65000 -> 1111110111101000 -> 11111101111010 -> 16250
```

You may use any language, but please note that Sam hates standard loopholes. This is code golf so the code can be as short as possible to make room for the "compressed" numbers".

Note:This is NOT an acceptable compression scheme. Using this will promptly get you fired.

Citation-Needed: I do not take credit for this concept. This comes from @Conor O' Brien's blog here see this OEIS of fit numbers. https://oeis.org/A090078

Body:
Actually, 14 bytes

├`'0;;+(Æ`Y2@¿

Try it online!

Explanation:

├`'0;;+(Æ`Y2@¿
├               bin(input) (automatically discards leading zeroes)
 `'0;;+(Æ`Y     call this function until the output stops changing:
  '0;;+           push "0", "00"
       (Æ         replace "00" with "0" in binary string
           2@¿  convert from binary to decimal


答:
JavaScript (ES6), 41 bytes

```<code>n=>+`0b${n.toString(2).replace(/0+/g,0)}`
</code>```

Title: Output "Fit" numbers

Body:
JavaScript (ES6), 41 bytes

n=>+`0b${n.toString(2).replace(/0+/g,0)}`


答:
05AB1E, <s>8</s> 6 bytes

```<code>b00¬:C
</code>```

Explanation

```<code>b        # convert input to binary
 00¬:    # replace 00 with 0 while possible
     C   # convert to int
</code>```

Try it online

Saved 2 bytes thanks to Adnan

Title: Output "Fit" numbers

Body:
05AB1E, <s>8</s> 6 bytes

b00¬:C

Explanation

b        # convert input to binary
 00¬:    # replace 00 with 0 while possible
     C   # convert to int

Try it online

Saved 2 bytes thanks to Adnan


答:
PowerShell v2+, 69 bytes

```<code>[convert]::ToInt32(([convert]::ToString($args[0],2)-replace'0+',0),2)
</code>```

(feature-requestA shorter way to convert to/from binary in PowerShell)

Takes input $args[0], uses the .NET built-in [convert]::ToString(int,base) to convert the input integer into a binary base string. That's filtered through the -replace to strip out any runs of one-or-more-zeros to just 0. That resultant string is sent back through the other direction via [convert]::ToInt32(string,base) to turn the binary back into an integer. That integer is left on the pipeline and output is implicit.

Test Cases

```<code>PS C:\Tools\Scripts\golfing> 1,9,15,13,16,17,65535,65000|%{"$_ -> " +(.\output-fit-number.ps1 $_)}
1 -> 1
9 -> 5
15 -> 15
13 -> 13
16 -> 2
17 -> 5
65535 -> 65535
65000 -> 16250
</code>```

Title: Output "Fit" numbers

Body:
PowerShell v2+, 69 bytes

[convert]::ToInt32(([convert]::ToString($args[0],2)-replace'0+',0),2)

(feature-requestA shorter way to convert to/from binary in PowerShell)

Takes input $args[0], uses the .NET built-in [convert]::ToString(int,base) to convert the input integer into a binary base string. That's filtered through the -replace to strip out any runs of one-or-more-zeros to just 0. That resultant string is sent back through the other direction via [convert]::ToInt32(string,base) to turn the binary back into an integer. That integer is left on the pipeline and output is implicit.

Test Cases

PS C:\Tools\Scripts\golfing> 1,9,15,13,16,17,65535,65000|%{"$_ -> " +(.\output-fit-number.ps1 $_)}
1 -> 1
9 -> 5
15 -> 15
13 -> 13
16 -> 2
17 -> 5
65535 -> 65535
65000 -> 16250


答:
Python 3, <s>55</s>, 50 bytes.

Saved 4 bytes thanks to Sp3000.

Pretty straightforward solution.

```<code>import re
f=lambda x:eval(re.sub('0+','0',bin(x)))
</code>```

Title: Output "Fit" numbers

Body:
Python 3, <s>55</s>, 50 bytes.

Saved 4 bytes thanks to Sp3000.

Pretty straightforward solution.

import re
f=lambda x:eval(re.sub('0+','0',bin(x)))


答:
Ruby, <s>35</s> 31 bytes

-2 bytes thanks to @Doorknob

```<code>->n{eval ("0b%b"%n).squeeze ?0}
</code>```

See it on repl.it: https://repl.it/CnnQ/2

Title: Output "Fit" numbers

Body:
Ruby, <s>35</s> 31 bytes

-2 bytes thanks to @Doorknob

->n{eval ("0b%b"%n).squeeze ?0}

See it on repl.it: https://repl.it/CnnQ/2


答:
JavaScript (ES6), <s>96</s> 95 bytes

g=
(f,w,h)=>[...Array(h)].map((_,i)=>(i%3?`       |`:`_`).repeat(w+7).substr(f^7^i%6&4,w)).join`
`
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div onchange=o.textContent=g(f.value,w.value,+h.value)><input id=f type=number min=0 max=7 placeholder=Offset><input id=w type=number min=0 placeholder=Width><input id=h type=number min=0 placeholder=Height></div><pre id=o></code>```

Explanation: Creates a string of either the repeating 7 spaces plus | pattern or just repeated _s, but at least long enough to be able to extract the w characters required for each row. The first three rows start at position f^7 and then the next three rows start at position f^3, so I achieve this by <s>toggling bit 2 of f on every third row</s> using the opposite bit 2 on the last two rows of each block of 6 for a saving of 1 byte.

Body:
The purpose of this challenge is to produce an ASCII version of the cover of this great album by the rock band Pink Floyd.

The brick junctions are made of characters _ and |. Bricks have width 7 and height 2 characters, excluding junctions. So the basic unit, including the junctions, is:

```<code>_________
|       |
|       |
_________
</code>```

Each row of bricks is offset by half a brick width (4 chars) with respect to the previous row:

```<code>________________________________________
  |       |       |       |       |
  |       |       |       |       |
________________________________________
      |       |       |       |       |
      |       |       |       |       |
________________________________________
  |       |       |       |       |
  |       |       |       |       |
</code>```

The wall is parameterized as follows. All parameters are measured in chars including junctions:

Horizontal offset of first row, F. This is the distance between the left margin and the first vertical junction of the upmost row. (Remember also the half-brick relative offset between rows). Its possible values are 0, 1, ..., 7.

Total width, W. This includes junctions. Its value is a positive integer.

Total height, H. This includes junctions. Its value is a positive integer.

The top of the wall always coincides with the top of a row. The bottom may be ragged (if the total height is not a multiple of 3). For example, here's the output for 6, 44, 11:

```<code>____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
  |       |       |       |       |       |
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
</code>```

and a visual explanation of parameters:

```<code>          F=6
         ......
     .   ____________________________________________
     .         |       |       |       |       |
     .         |       |       |       |       |
     .   ____________________________________________
     .     |       |       |       |       |       |
H=11 .     |       |       |       |       |       |
     .   ____________________________________________
     .         |       |       |       |       |
     .         |       |       |       |       |
     .   ____________________________________________
     .     |       |       |       |       |       |

         ............................................
                             W=44
</code>```

Additional rules

You may provide a program or a function.

Input format is flexible as usual. Output may be through STDOUT or an argument returned by a function. In this case it may be a string with newlines or an array of strings.

Trailing spaces or newlines are allowed.

Shortest code in bytes wins.

Test cases

Inputs are in the order given above, that is: horizontal offset of first row, total width, total height.

```<code>6, 44, 11:
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
  |       |       |       |       |       |
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |

2, 20, 10:
____________________
  |       |       |
  |       |       |
____________________
      |       |
      |       |
____________________
  |       |       |
  |       |       |
____________________

1, 1, 1:
_

1, 2, 3:
__
 |
 |

3, 80, 21:
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
</code>```

Body:
JavaScript (ES6), <s>96</s> 95 bytes

g=
(f,w,h)=>[...Array(h)].map((_,i)=>(i%3?`       |`:`_`).repeat(w+7).substr(f^7^i%6&4,w)).join`
`
;

<div onchange=o.textContent=g(f.value,w.value,+h.value)><input id=f type=number min=0 max=7 placeholder=Offset><input id=w type=number min=0 placeholder=Width><input id=h type=number min=0 placeholder=Height></div><pre id=o>

Explanation: Creates a string of either the repeating 7 spaces plus | pattern or just repeated _s, but at least long enough to be able to extract the w characters required for each row. The first three rows start at position f^7 and then the next three rows start at position f^3, so I achieve this by <s>toggling bit 2 of f on every third row</s> using the opposite bit 2 on the last two rows of each block of 6 for a saving of 1 byte.


答:
Java 8 (Full Program), <s>257</s> 249 bytes

```<code>interface M{static void main(String[]a)throws Exception{int i=0,j;while((j=System.in.read())>10)i=i*10+j-48;System.out.print(L(i));}static String L(int i){if(i==0)return "0";String s=Integer.toString(i,2);return "1"+L(s.length()-1)+s.substring(1);}}
</code>```

Readable Version w/ Explanation (It's mostly just recursion):

```<code>interface M {
    static void main(String[]a) throws Exception { // Using Exception is unadvised in real coding, but this is Code Gold
        int i = 0, j; // i stores the input; j is a temporary variable
        while ((j = System.in.read()) > 10) // Read the input to j and stop if it is a newline. Technically this stops for tabulators as well, but we shouldn't encounter any of those...
            i = i * 10 + j - 48; // Looping this step eventually reads the whole number in from System.in without using a reader (those take up a lot of bytes)
        System.out.print(L(i)); // Make a method call
    }

    static String L(int i) { // This gets the actual Levenshtein Code
        if (i == 0)
            return "0"; // The program gets a StackOverflowException without this part
        String s = Integer.toString(i, 2); // Shorter than toBinaryString
        return "1" + L(s.length() - 1) + s.substring(1); // Write in the first character (which is always a one), followed by the next L-code, followed by the rest of the binary string
    }
}
</code>```

EDIT 1: Saved 8 bytes: The first character of the binary string is always 1; therefore, rather than using s.charAt(0), a better option is simply "1".

Title: Given an integer, compute its Levenshtein code

Body:
Disclaimer: Levenshtein coding is completely unrelated to the Levenshtein edit distance metric.

<Insert long story about why Levenshtein codes need to be calculated here.>

The code

Levenshtein coding is a system of assigning binary codes to nonnegative integers that retains some weird property in probability which isn't relevant for this challenge. We will denote this code as L(n). Wikipedia describes this as a five-step process:

Initialize the step count variable C to 1.

Write the binary representation of the number without the leading 1 to the beginning of the code.

Let M be the number of bits written in step 2.

If M is not 0, increment C, repeat from step 2 with M as the new number.

Write C 1 bits and a 0 to the beginning of the code.

However, the code can also be described recursively:

If the number is 0, then its code is 0.

Write the binary representation of the number without the leading 1 to the beginning of the code.

Let M be the number of bits written in step 2.

Write L(M) to the beginning of the code.

Write a 1 bit to the beginning of the code.

For those who prefer examples, here is the recursive process for L(87654321), with  denoting concatenation:

The challenge

Write a program or function that, given a number n, outputs the bitstring L(n) in any reasonable format (this includes returning a number with said bits). Standard loopholes are, as always, disallowed.

Examples

Input: 5

Output: 1110001

Input: 30

Output: 111100001110

Input: 87654321

Output: 111110000101001001110010111111110110001

Input: 0

Output: 0

Body:
Java 8 (Full Program), <s>257</s> 249 bytes

interface M{static void main(String[]a)throws Exception{int i=0,j;while((j=System.in.read())>10)i=i*10+j-48;System.out.print(L(i));}static String L(int i){if(i==0)return "0";String s=Integer.toString(i,2);return "1"+L(s.length()-1)+s.substring(1);}}

Readable Version w/ Explanation (It's mostly just recursion):

interface M {
    static void main(String[]a) throws Exception { // Using Exception is unadvised in real coding, but this is Code Gold
        int i = 0, j; // i stores the input; j is a temporary variable
        while ((j = System.in.read()) > 10) // Read the input to j and stop if it is a newline. Technically this stops for tabulators as well, but we shouldn't encounter any of those...
            i = i * 10 + j - 48; // Looping this step eventually reads the whole number in from System.in without using a reader (those take up a lot of bytes)
        System.out.print(L(i)); // Make a method call
    }

    static String L(int i) { // This gets the actual Levenshtein Code
        if (i == 0)
            return "0"; // The program gets a StackOverflowException without this part
        String s = Integer.toString(i, 2); // Shorter than toBinaryString
        return "1" + L(s.length() - 1) + s.substring(1); // Write in the first character (which is always a one), followed by the next L-code, followed by the rest of the binary string
    }
}

EDIT 1: Saved 8 bytes: The first character of the binary string is always 1; therefore, rather than using s.charAt(0), a better option is simply "1".


答:
MATL, <s>11</s> <s>9</s> 8 bytes

```<code>BFFOZtXB
</code>```

This version works only in MATLAB since strrep in MATLAB can handle logical inputs. Here is a version that will work in Octave (9 bytes) (and thus the online interpreter) which explicitly casts the logical inputs to type double.

Try it online

Explanation

```<code>    % Implicitly grab input
B   % Convert decimal to binary
FF  % Create the array [0 0]
O   % Number literal
Zt  % Replaces all [0 0] with [0] (will replace any number of 0's with 0)
XB  % Convert binary to decimal
    % Implicitly display
</code>```

Title: Output "Fit" numbers

Body:
MATL, <s>11</s> <s>9</s> 8 bytes

BFFOZtXB

This version works only in MATLAB since strrep in MATLAB can handle logical inputs. Here is a version that will work in Octave (9 bytes) (and thus the online interpreter) which explicitly casts the logical inputs to type double.

Try it online

Explanation

    % Implicitly grab input
B   % Convert decimal to binary
FF  % Create the array [0 0]
O   % Number literal
Zt  % Replaces all [0 0] with [0] (will replace any number of 0's with 0)
XB  % Convert binary to decimal
    % Implicitly display


Title: Output "Fit" numbers

Body:
Perl 6, <s> 31 </s> 27 bytes

<s>{:2(.base(2).subst(:g,/0+/,0))}</s>
{:2(.base(2)~~{S:g/0+/0/})}

Explanation:

-> $_ {
  # convert from base 2
  :2(

    # convert to base 2
    $_.base(2)

    # substitute
    .subst(
      :global,
      / 0+ /,  # all substrings made of 0s
      '0'      # with one 0
    )
  )
}

Example:

my &fit-compress = {:2(.base(2)~~{S:g/0+/0/})}
say fit-compress 1;     # 1
say fit-compress 9;     # 5
say fit-compress 15;    # 15
say fit-compress 13;    # 13
say fit-compress 16;    # 2
say fit-compress 17;    # 5
say fit-compress 65535; # 65535
say fit-compress 65000; # 16250

# number created with ｢:2( [~] <0 1>.roll: 256 )｣
say fit-compress 80794946326210692074631955353531749442835289622757526957697718534769445507500
# 4240335298301026395935723255481812004519990428936918


答:
sh 7

```<code>w|aplay
</code>```

Plays a short noise.

Also 7:

```<code>aplay *
</code>```

Assembly

Another non-bell solution. Resulting binary is just 15 bytes.

```<code>mov al, 182
out 43h, al
out 42h, al
mov al, 16
out 42h, al
mov al, 3
out 61h, al
ret
</code>```

Assemble with nasm sound.asm -o sound.com. Can be tried with dosbox sound.com.

Title: Play a sound, any sound

Body:
sh 7

w|aplay

Plays a short noise.

Also 7:

aplay *

Assembly

Another non-bell solution. Resulting binary is just 15 bytes.

mov al, 182
out 43h, al
out 42h, al
mov al, 16
out 42h, al
mov al, 3
out 61h, al
ret

Assemble with nasm sound.asm -o sound.com. Can be tried with dosbox sound.com.


答:
Bash (sed + bc), <s>60</s> <s>55</s> 43 bytes

```<code>echo $[2#`bc<<<obase=2\;$1|sed s/00\*/0/g`]
</code>```

edit:

changed sed -E 's/0+ to sed 's/00* and changed echo and pipe used to pass the value to bc with <<<.

Brilliant suggestion by @Digital Trauma!

example:

```<code>$ bash script.sh 65000
16250
$ bash script.sh 15
15
$ bash script.sh 9
5
</code>```

Title: Output "Fit" numbers

Body:
Bash (sed + bc), <s>60</s> <s>55</s> 43 bytes

echo $[2#`bc<<<obase=2\;$1|sed s/00\*/0/g`]

edit:

changed sed -E 's/0+ to sed 's/00* and changed echo and pipe used to pass the value to bc with <<<.

Brilliant suggestion by @Digital Trauma!

example:

$ bash script.sh 65000
16250
$ bash script.sh 15
15
$ bash script.sh 9
5


问:
Quick Golf: The Gold Leader

Challenge

Using data from the API here, output the names of the three countries with the most Olympic gold medals at the 2016 Rio Olympic Games (i.e. the first element of the returned list).

For example, at the time of posting (18:23 UTC+1, Monday, 15th August), the USA, the UK and China have the most gold medals, so the output would be:

```<code>United States
Great Britain
China
</code>```

The country names must be separated by newlines and you may have a leading or trailing newlines.

Once the Olympics have finished, the program does not have to work as expected.

URL shorteners are disallowed but JSON parsing libraries are allowed.

This is code golf, so the shortest code in bytes wins.

I'm going to keep trying to get an Olympics themed challenge in here

Leaderboard

var QUESTION_ID=89919,OVERRIDE_USER=30525;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="
"+e.body.replace(OVERRIDE_REG,"")+"
")});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;/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;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

答:
Kotlin (Script), <s>125</s> <s>121</s> 119 bytes

```<code>java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().filter{'m' in it}.take(3).map{println(it.split('"')[3])}
</code>```

Runnable with kotlinc -script <filename> or through IDEA as *.kts file.

now, if we make a VERY big assumption about the format, including numbers of lines, we can trim it to:

```<code>java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().slice(setOf(3,12,21)).map{println(it.split('"')[3])}
</code>```

or even

```<code>java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().slice(3..21 step 9).map{println(it.split('"')[3])}
</code>```

Thanks to folks at Kotlin slack team for helping me trim a couple dozens of bytes!

Title: Quick Golf: The Gold Leader

Body:
Kotlin (Script), <s>125</s> <s>121</s> 119 bytes

java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().filter{'m' in it}.take(3).map{println(it.split('"')[3])}

Runnable with kotlinc -script <filename> or through IDEA as *.kts file.

now, if we make a VERY big assumption about the format, including numbers of lines, we can trim it to:

java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().slice(setOf(3,12,21)).map{println(it.split('"')[3])}

or even

java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().slice(3..21 step 9).map{println(it.split('"')[3])}

Thanks to folks at Kotlin slack team for helping me trim a couple dozens of bytes!


问:
Is it a wordinian?
What is the shortest way to see if an input is a wordinian using any programming language?

A wordinian is a word that contains words of length 1 to the original word's length. For example,

bin

'I' is a word

  'in' is a word

  'bin' is a word

Or,

stage

'a' is a word

  'ta' is a word (yes it is)

  'age' is a word

  'stag' is a word

  'stage' is a word

Input

Your code should take a word and a dictionary as inputs, in any reasonable format.

Output

The output should be a value to indicate true or false, to tell us if the word is a wordinian.

For more info on wordinians click here.

Here is a list of words that I will be using as inputs and subwords. Also, in response to @xnor, it has to contain subwords of each length, not a chain of subwords. Note that only one word will be used as an input.

答:
JavaScript (Firefox 30-57), 68 bytes

```<code>(w,a)=>new Set((for(x of a)if(~w.search(x))x.length)).size==w.length
</code>```

Using a generator comprehension avoids creating an intermediate array. 73 byte ES6 version:

```<code>(w,a)=>new Set(a.filter(x=>~w.search(x)).map(x=>x.length)).size==w.length
</code>```

Title: Is it a wordinian?

Body:
JavaScript (Firefox 30-57), 68 bytes

(w,a)=>new Set((for(x of a)if(~w.search(x))x.length)).size==w.length

Using a generator comprehension avoids creating an intermediate array. 73 byte ES6 version:

(w,a)=>new Set(a.filter(x=>~w.search(x)).map(x=>x.length)).size==w.length


答:
Jellyfish, 20 bytes

```<code>p
d
# S
,1
*
\dbi
 2
</code>```

Try it online!

Explanation

i is input.

b converts it to binary (list of digits)

\d with arguments 2 and the digit list applies d (binary digits to number) to every length-2 substring of the digit list.

* takes signum of the results: 00 goes to 0, everything else to 1.

,1 tacks a 1 to the end, so the last digit is not lost.

# S selects from bi those digits which have a 1 on the list computed above: those that are not the left halves of 00.

d converts back to number, and p prints the result.

Title: Output "Fit" numbers

Body:
"Fit Numbers"

Sam has a "brilliant" idea for compression! Can you help?

Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.

```
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17 -> 10001
65535 -> 111111111111111
```

Now replace any group of one or more zeros with a single zero. This is because the number has gotten leaner. Your binary string now will look like this.

```
1 -> 1 -> 1
9 -> 1001 -> 101
15 ->1111 -> 1111
13 ->1101 -> 1101
16 -> 10000 -> 10
17 -> 10001 -> 101
65535 -> 111111111111111 -> 111111111111111
```

Now you convert the binary string back to a base 10 representation, and output it in any acceptable format. Here are your test cases. The first integer represents an input, and the last integer represents an output. Note that some numbers do not change, and thus can be called "fit"

```
1 -> 1 -> 1 -> 1
9 -> 1001 -> 101 -> 5
15 ->1111 -> 1111 -> 15
13 ->1101 -> 1101 -> 13
16 -> 10000 -> 10 -> 2
17 -> 10001 -> 101 -> 5
65535 -> 1111111111111111 -> 1111111111111111 -> 65535
65000 -> 1111110111101000 -> 11111101111010 -> 16250
```

You may use any language, but please note that Sam hates standard loopholes. This is code golf so the code can be as short as possible to make room for the "compressed" numbers".

Note:This is NOT an acceptable compression scheme. Using this will promptly get you fired.

Citation-Needed: I do not take credit for this concept. This comes from @Conor O' Brien's blog here see this OEIS of fit numbers. https://oeis.org/A090078

Body:
Jellyfish, 20 bytes

p
d
# S
,1
*
\dbi
 2

Try it online!

Explanation

i is input.

b converts it to binary (list of digits)

\d with arguments 2 and the digit list applies d (binary digits to number) to every length-2 substring of the digit list.

* takes signum of the results: 00 goes to 0, everything else to 1.

,1 tacks a 1 to the end, so the last digit is not lost.

# S selects from bi those digits which have a 1 on the list computed above: those that are not the left halves of 00.

d converts back to number, and p prints the result.


答:
Octave <s>80</s> 76 bytes

```<code>% in file codegolf.m
c(6,8)=0;c([1,4],:)=63;c([2,3,23,24])=92;char(repmat(c+32,h,w)(1:h,o+1:o+w))
</code>```

to run from terminal: octave --eval "o=2;h=18;w=44; codegolf"

(alternatively, if you think the terminal call is cheating :p then an anonymous function implementation takes 86 bytes :)

```<code>c(6,8)=0;c([1,4],:)=63;c([2,3,23,24])=92;f=@(o,h,w)char(repmat(c+32,h,w)(1:h,o+1:o+w))
</code>```

Call f(2,18,44) at the octave interpreter.

Body:
Octave <s>80</s> 76 bytes

% in file codegolf.m
c(6,8)=0;c([1,4],:)=63;c([2,3,23,24])=92;char(repmat(c+32,h,w)(1:h,o+1:o+w))

to run from terminal: octave --eval "o=2;h=18;w=44; codegolf"

(alternatively, if you think the terminal call is cheating :p then an anonymous function implementation takes 86 bytes :)

c(6,8)=0;c([1,4],:)=63;c([2,3,23,24])=92;f=@(o,h,w)char(repmat(c+32,h,w)(1:h,o+1:o+w))

Call f(2,18,44) at the octave interpreter.


答:
Java, <s>152</s> <s>143</s> 138 bytes

```<code>interface C{static void main(String[]b){Integer i=0;System.out.print(i.parseInt(i.toString(i.parseInt(b[0]),2).replaceAll("0+","0"),2));}}
</code>```

9 bytes less thanks to @RohanJhunjhunwala. I prefer to keep it as a fully functioning program with main and the like. However, of course it can be golfed more otherwise.

5 bytes less thanks to @LeakyNun's suggestions.

Title: Output "Fit" numbers

Body:
Java, <s>152</s> <s>143</s> 138 bytes

interface C{static void main(String[]b){Integer i=0;System.out.print(i.parseInt(i.toString(i.parseInt(b[0]),2).replaceAll("0+","0"),2));}}

9 bytes less thanks to @RohanJhunjhunwala. I prefer to keep it as a fully functioning program with main and the like. However, of course it can be golfed more otherwise.

5 bytes less thanks to @LeakyNun's suggestions.


答:
Bash + GNU utilities, 27

```<code>dc -e2o?p|tr -s 0|dc -e2i?p
</code>```

Input read from STDIN.

Title: Output "Fit" numbers

Body:
Bash + GNU utilities, 27

dc -e2o?p|tr -s 0|dc -e2i?p

Input read from STDIN.


答:
PHP, 53 51 Bytes

```<code><?=bindec(preg_replace("/0+/",0,decbin($argv[1])));
</code>```

Takes an argument from the console.

Thanks to:

@manatwork replace "0" with 0

Title: Output "Fit" numbers

Body:
PHP, 53 51 Bytes

<?=bindec(preg_replace("/0+/",0,decbin($argv[1])));

Takes an argument from the console.

Thanks to:

@manatwork replace "0" with 0