New answers tagged

0

Wren, 30 bytes Just a port of most answers. Fn.new{|i|(i*9+9).toString[0]} Try it online!


0

Keg -rr, 4 bytes ⑨9*÷ Try it online! Of course, uses the same approach as the 05AB1E answer. Also uses the new -rr (reverse and print raw) flag. Transpiles to: from KegLib import * from Stackd import Stack stack = Stack() printed = False increment(stack) integer(stack, 9) maths(stack, '*') item_split(stack) if not printed: reverse(stack) raw(...


0

J, 19 bytes 0{[:/:(-.,&(+/)-)@> Try it online! 0 { first element of... [: /: the grade up of... (indices with smallest item first) (-.,&(+/)-) the list of pairs , created by summing each of &(+/): 1 minus an input item -. and the negative of an input item - @> of each unboxed input item This turns each input item into a pair: <...


1

Mathematica, 180 172 bytes ToExpression[StringReplace[a,{"["->"{","]"->"}"," "->"=","True"->"-10^-9","False"->"1"}]];(If[Length[#]==1,#[[1]],-1]&@@Flatten[Position[#,Min[#]]]&/@{Total/@Streets})[[1]] We assume the input is already stored as text in the variable a. If the reformatting code is neglected (input is already stored in the ...


0

Jelly, 15 bytes ċþØ.N1¦ZM-¹L’$? Try it online! A monadic link taking a list of lists of Jelly booleans (0s and 1s). Returns the 1-indexed maximum list using the specified criteria, or -1 if there is more than one that is equal. The last 6 bytes are spent on converting multiple values into -1; if this could be dropped the answer would be 9 bytes.


2

Getting the solutions from @Delfad0r's program I extended @Delfad0r's program to output solutions. It also gives intermediate results, so you get output like this: Solving n = 8: a(8) >= 9 a(8) >= 10 a(8) >= 11 a(8) >= 12 a(8) >= 13 o . o . o o . o o . o o . o o o o o o . . o . . o o o . o . . o . o o o a(8) = 13 ...


2

R, 52 bytes function(l)order(lengths(l)-(m=sapply(l,sum)),-m)[1] Try it online! Minimizes the number of toothbrushes, then maximizes the pieces of candy, since this is apparently what OP is asking. If we want to first maximize the amount of candy, then minimize the number of toothbrushes (seems more plausible…) it becomes R, 51 bytes function(l)order(m&...


3

Python 2, 58 bytes lambda l:l.index(max(l,key=lambda s:(-s.count(0),sum(s)))) Try it online!


0

x86 Machine Code, 15 bytes 4F 89 F8 F7 D8 21 F8 0F AF C0 39 C7 19 C0 C3 These bytes define a function that takes the input argument (an unsigned integer) in the EDI register, following the standard System V calling convention for x86 systems, and it returns the result in the EAX register, like all x86 calling conventions. In assembler mnemonics: 4F ...


1

Japt, 12 10 9 bytes É&1-U)>Uq Try it online! Port of Dennis' Jelly answer again. - 1 thanks to @Shaggy.


0

ink, 60 bytes =p(n) ~n-=n>1 ~temp x=1 -(k){n%2:{n<x}->->} ~x+=x ~n=n/2 ->k Try it online! Based on @DSkoog's Maple answer - it wasn't the first of its kind to be posted, but it was the first of its kind that I saw. Ungolfed = is_proth(number) = /* It's easy to check if a number is one less than a Proth number. We take the number and ...


0

Ruby -p, 72 bytes puts$_=s=[*?1..$_]*'' puts$_ until s[gsub /\B{#{1&$.+=1}}(.)(.)/,'\2\1'] Try it online! Alternately replaces using the regexps /\B{0}(.)(.)/ and /\B{1}(.)(.)/. The latter matches any two characters other than at the beginning of the string, while the former just matches any two characters--{0} means "repeated zero times" turning the \...


0

05AB1E, 35 bytes ≠iL[ˆ¯DÁ2£ËNĀ*#θNÈi2ôëćs2ôsš}ε¸˜}í˜ Try it online or verify all test cases. Not too happy with it.. I have the feeling the duplicated 2ô could be golfed somehow, and some of the workarounds could be more elegant (/shorter). Could be 33 bytes if [1,1] instead of 1 is allowed as output; and could be 28 bytes if we'd only had to handle \$\...


0

C (gcc), 57 bytes x=0,y=1,s;main(){for(;;){s=x+y;printf("%d,",s);x=y;y=s;}} Try it online!


1

APL(NARS), 149 chars, 298 bytes r←f w;n;s;i;k (n s)←w⋄r←⍬⋄→0×⍳s<3⋄i←1 →0×⍳n<k←2÷⍨(i×i×s-2)-i×s-4⋄r←r,k⋄i+←1⋄→2 h←{0=≢b←((v←↑⍵)=+/¨a)/a←{0=≢⍵:⊂⍬⋄m,(⊂1⌷⍵),¨m←∇1↓⍵}f⍵:v⍴1⋄k←↑⍋≢¨b⋄k⊃b} if not find solutions "0=≢b" than return for (n s) input, n times 1; else it would return the sum of s numbers that has less addend... test: h 1 3 1 h 2 8 1 1 ...


1

C (gcc), 270 224 206 190 bytes Not a "winning" answer but a fun challenge. Thanks @ceilingcat for some good cleanup. Learned something new. Update: further golfed based on how I now know the game to be played. Further golfed by @ceilingcat #define w(x)for(i=x;i<n;i++) #define pb w(0)printf(b+i);puts(""); i,x,n;z(int*b){n=*b;w(0)b[i+n*4]=b[i]=i+49;do{...


3

Jelly, 25 bytes s2UF RÇŻÇfƊƭƬmn2$Ṃṭ$⁸>2¤¡ A monadic Link accepting a non-negative integer which yields a list of lists of non-negative integers. Try it online! (The footer calls the Link and formats the result as a grid) How? s2UF - helper Link: list e.g. [4, 2, 5, 1, 3] s2 - split into chunks of length two [[4, 2], [5, 1], [3]]...


0

Icon, 119 bytes procedure f(n) a:="";a||:=1to n&\z;b:=a n>1&o:=|(0|1)&write(b)&b[o+(k:=seq(1,2)\n)]:=:b[o+k+1]&b==a write(b);return end Try it online!


0

Red, 159 bytes func[n][r: collect[repeat i n[keep i]]repeat i either n < 3[n * n][2 * n + 1][print r: head r r: skip r i + 1 % 2 until[move r next r(index? r: skip r 2)> n]]] Try it online! If two 1s are allowed as a solution for 1: Red, 155 bytes func[n][r: collect[repeat i n[keep i]]b: copy r t: on until[print b if t: not t[b: next b]until[move ...


2

Perl 6, 52 bytes {$_,|({S:g:p($++%2)/(.)(.)/$1$0/}...$_)}o{[~] 1..$_} Try it online! Explanation {[~] 1..$_} # Concat numbers 1..n { }o # Feed into block $_, # Start with first string ... # Sequence constructor { ...


1

JavaScript (ES6), 99 bytes n=>(z=0,g=a=>[a=a.map((v,i)=>v?a[i+=i+z&1||-1]||v:i+1),...z++^2*n^'027'[n]?g(a):[]])([...Array(n)]) Try it online! Commented n => ( // n = input z = 0, // z = counter g = a => [ // g = recursive function taking the list of bells a[] a = // ...


3

Zsh, 75 95 bytes s(){echo $a;a=;for x y;a+=($y $x)} a=({1..$1}) (($1-1))&&repeat $1 s $a&&s '' $a (($1-2))&&s $a Try it online! Try it online! Defines a function s which swaps each pair of arguments and assigns them to a. s is called once normally ABCD -> BADC and then once with an empty element prepended: ABCD -> ACBD; ...


5

Python 2, 93 bytes lambda n:[[.5+abs((n+j-i*(-1)**(i+j))%(2*n)-n+.5)for j in range(n)]for i in range(2*n+(n>2))] Try it online! Outputs a list of lists of integer-valued floats. The map (i,j) -> j-i*(-1)**(i+j) is very similar to multiplication in the dihedral group. This isn't a coincidence. If we let \$a\$ represent swapping every other element ...


3

J, 68 62 59 bytes [:>[:(]C.~_2<\(}.i.@#))&.>/@:|.\<@:>:@i.,(0;1)$~+:-1#.<&2 3 Try it online! 51 bytes if 1 case is allowed to return 2 lines: Try it online! Could likely be golfed more but I was happy with the idea. Essentially, everything flows from noting that to get from one element to the next, you apply 1 of two cyclic ...


2

Charcoal, 54 bytes NθFθ«Jι⁰≔⁻⁶∧‹⁺ι¬﹪ι²θ∨﹪ι²±¹ηF⎇‹θ³×θθ⊕⊗θ«✳ηI⊕ι≧⁺⁻¬ⅈ⁼⊕ⅈθη Try it online! Link is to verbose version of code. Explanation: Nθ Input n. Fθ« Loop over each bell. Jι⁰ Jump to its starting position. ≔⁻⁶∧‹⁺ι¬﹪ι²θ∨﹪ι²±¹η Calculate its starting direction. For odd bells this is normally 7 (south east) and for even bells this is normally 5 (...


3

PHP, 120 bytes for($b=$a=range(1,$argn);print join($b)." ",$a[1]&&!$i||$a!=$b;)for($j=$i++%2;$n=$b[++$j];$b[$j-2]=$n)$b[$j++]=$b[$j-2]; Try it online! for( $b=$a=range(1,$argn); // set $a and $b to an array of [1...n] print join($b)."\n", // on start of each iteration print $b $a[1]&& // stop when input is 1 (we only ...


1

Python 2, 110 104 bytes n=input() R=range s=R(1,n+1) for k in R(n*2-2/n+1): print s for i in R(k%2,n-1,2):s[i:i+2]=s[i+1],s[i] Try it online! Full program that prints a list of integers for each "change" in the "hunt".


1

Jelly, 28 bytes ¹©Rµ¬ɼks€2UFµ⁺⁻J$п;@WẋL’ẸƊƊ Try it online! A monadic link that takes an integer as its input and returns a list of lists of integers. Could be 16 bytes if only needed to handle numbers 3 and above, and 22 if only 2 and above.


4

Haskell, 83 bytes f(a:b:c)=b:a:f c f c=c q l|a:b<-f l=l:f l:q(a:f b) g n=take(2*n+sum[1|n>2])$q[1..n] Try it online!


1

C# (Visual C# Interactive Compiler), 128 bytes x=>{var m=Enumerable.Range(1,x).ToList();for(int i=0,j=0;i<x*2+1-2/x;j=++i%2)for(Print(m);j<x-1;)(m[j],m[++j])=(m[j],m[~-j++]);} Try it online!


1

Forth (gforth), 99 bytes : f >r 0 begin 1+ dup begin dup i < while dup 20 for 10 /mod >r + r> next + repeat i = until r> . ; Try it online! Largely similar to reffu's submission (106 bytes). The golfed parts are: Digit sum calculation (-6) Final cleanup (-1) by printing some garbage to stdout. (No problem because the result is returned on ...


0

PHP, 135 bytes for(;++$n<1e4;$p||print"$n ")for($p=$i=0;$i<$l=strlen($n);$i++)for($j=1;$j++<$l-$i;$p|=$k)for($k=($m=substr($n,$i,$j))-1;$k&&$m%$k--;); Try it online! for(; // level 1 loop on ++$n<1e4; // all numbers from 1 to 10,000, $n is current number $p||print"$n\n" // at ...


2

Python 3, 118 bytes r=range(9720) for n in r[1:]:all(all(l%k+9//l for k in r[2:l])for l in(n%10**(i%5)//10**(i//5)for i in r))and print(n) Try it online! Explanation Warning: no actual strings involved in this solution. r=range(9720) for n in r[1:]: # For each positive integer up to 9720 all( ... for l in(n%10**(i%...


9

An extension to @Grimy's code gets N=8 This just underlines that @Grimy deserves the bounty: I could prune the search tree by extending the code to check, after each finished polyomino, that the remaining free space is not partitioned into components of size not divisible by N. On a machine where the original code took 2m11s for N=7, this takes 1m4s, and ...


Top 50 recent answers are included