logo
down
shadow

Code golf: the Mandelbrot set


Code golf: the Mandelbrot set

By : user3865313
Date : January 10 2021, 01:57 PM
may help you . There was a perl solution already some years ago posted in perlmonks, it reads:
code :


Share : facebook icon twitter icon
Code Golf: Shortest code to find a weighted median?

Code Golf: Shortest code to find a weighted median?


By : user1139589
Date : March 29 2020, 07:55 AM
hope this fix your issue J
Go ahead and type this directly into the interpreter. The prompt is three spaces, so the indented lines are user input.
code :
   m=:-:@+/@(((2*+/\)I.+/)"1@(,:(\:i.@#))@[{"0 1(,:(\:i.@#))@])
   1 1 1 1 m 1 2 3 4
2.5
   1 1 2 1 m 1 2 3 4
3
   1 2 2 5 m 1 2 3 4
3.5
   1 2 2 6 m 1 2 3 4
4
   (>:,:[)i.10
1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8  9
   (>:m[)i.10
6
   (([+<&6),:>:)i.9
1 2 3 4 5 6 6 7 8
1 2 3 4 5 6 7 8 9
   (([+<&6)m>:)i.9
6.5
   i =: (2 * +/\) I. +/
   j =: ,: (\: i.@#)
   k =: i"1 @ j @ [
   l =: k {"(0 1) j @ ]
   m =: -: @ +/ @ l
Code Golf: Tic Tac Toe

Code Golf: Tic Tac Toe


By : Andrew G. Stanton
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , C, 77 (83) characters
This is a variant of dmckee's solution, except that each pair of digits in the Compact Coding is now the base-9 digits of the ASCII characters.
code :
// "J)9\t8\r=,\0" == 82,45,63,10,62,14,67,48,00 in base 9.
char*k="J)9 8\r=,",c;f(int*b){return(c=*k++)?b[c/9]&b[c%9]&b[*k--%9]|f(b):0;}
f(int*b){char*k="J)9    8\r=,",s=0,c;while(c=*k++)s|=b[c%9]&b[c/9]&b[*k%9];return s;}
#include <stdio.h>  
void check(int* b) {
    int h0 = b[0]&b[1]&b[2];
    int h1 = b[3]&b[4]&b[5];
    int h2 = b[6]&b[7]&b[8];
    int h3 = b[0]&b[3]&b[6];
    int h4 = b[1]&b[4]&b[7];
    int h5 = b[2]&b[5]&b[8];
    int h6 = b[0]&b[4]&b[8];
    int h7 = b[2]&b[4]&b[6];
    int res = h0|h1|h2|h3|h4|h5|h6|h7;
    int value = f(b);
    if (value != res)
        printf("Assuming f({%d,%d,%d, %d,%d,%d, %d,%d,%d}) == %d; got %d instead.\n", 
            b[0],b[1],b[2], b[3],b[4],b[5], b[6],b[7],b[8], res, value);
}
#define MAKEFOR(i) for(b[(i)]=0;b[(i)]<=2;++b[(i)])

int main() {
    int b[9];

    MAKEFOR(0)
    MAKEFOR(1)
    MAKEFOR(2)
    MAKEFOR(3)
    MAKEFOR(4)
    MAKEFOR(5)
    MAKEFOR(6)
    MAKEFOR(7)
    MAKEFOR(8)
        check(b);

    return 0;
}
Code Golf - π day

Code Golf - π day


By : user1837720
Date : March 29 2020, 07:55 AM
may help you . In dc: 88 and 93 93 94 96 102 105 129 138 141 chars
Just in case, I am using OpenBSD and some supposedly non-portable extensions at this point.
code :
[rdPr1-d0<p]sp1?dsMdd*sRd2%--
[dd*lRr-vddlMr-32rlpxRR42r2*lpxRRAP4*2+lN+sN2+dlM>y]
dsyx5klNlR/p
1?dsMdd*sRd2%--sY[0lM-[dd*lYd*+lRr(2*d5*32+PlN+sN1+dlM!<x]dsxxAPlY2+dsYlM>y]
dsyx5klNlR/p
# Routines to print '*' or ' '. If '*', increase the counter by 2
[lN2+sN42P]s1
[32P]s2
# do 1 row
# keeping I in the stack
[
 # X in the stack
 # Calculate X^2+Y^2 (leave a copy of X)
 dd*lYd*+ 
 #Calculate X^2+Y^2-R^2...
 lR-d
 # .. if <0, execute routine 1 (print '*')
 0>1
 # .. else execute routine 2 (print ' ')
 0!>2 
 # increment X..
 1+
 # and check if done with line (if not done, recurse)
 d lM!<x
]sx
# Routine to cycle for the columns
# Y is on the stack
[
  # push -X
  0lM- 

  # Do row
  lxx 
  # Print EOL
  10P
  # Increment Y and save it, leaving 2 copies
  lY 2+ dsY 
  # Check for stop condition
  lM >y
]sy
# main loop
# Push Input value
[Input:]n?
# Initialize registers
# M=rows
d sM
# Y=1-(M-(M%2))
dd2%-1r-sY
# R=M^2
d*sR
# N=0
0sN
[Output:]p
# Main routine
lyx
# Print value of PI, N/R
5klNlR/p
Code Golf: Ghost Leg

Code Golf: Ghost Leg


By : user1947947
Date : March 29 2020, 07:55 AM
I hope this helps you . JavaScript: 169 158 148 141 127 125 123 122 Characters
Minified and Golfed:
code :
function g(n,s){for(l=s.split('\n'),n*=2;k=l.shift();)for(j=3;j;)n+=k[n-3]==(c=--j-1?'=':'-')?-2:k[n-1]==c?2:0;return n/2}
function g(n, str) {
   var c, i, j;
   var lines = str.split('\n');
   n = (n * 2) - 2;

   for (i = 0; i < lines.length; i++) {
      for (j = 0; j < 3; j++) {
         c = (j == 1) ? '-' : '=';

         if (lines[i].charAt(n-1) == c) n-=2;          // Move left
         else if (lines[i].charAt(n+1) == c) n+=2;     // Move right
      }
   }

   return 1+n/2;
}
var ghostLegs = [];

ghostLegs[0] = "|-| |=|-|=|\n" +
               "| |-| | |-|\n" +
               "|=| |-| | |\n" +
               "| | |-|=|-|";

ghostLegs[1] = "| | | | | | | |\n" +
               "|-| |=| | | | |\n" +
               "|-| | |-| |=| |\n" +
               "| |-| |-| | |-|";

ghostLegs[2] = "| | |=| |\n" +
               "|-| |-| |\n" +
               "| |-| | |";

ghostLegs[3] = "|=|-|";

for (var m = 0; m < ghostLegs.length; m++) {
   console.log('\nTest: ' + (m + 1) + '\n');

   for (var n = 1; n <= (ghostLegs[m].split('\n')[0].length / 2) + 1; n++) {
      console.log(n + ':' + g(n, ghostLegs[m]));
   }
}
Test: 1
1:6
2:1
3:3
4:5
5:4
6:2

Test: 2
1:1
2:3
3:2
4:4
5:5
6:6
7:8
8:7

Test: 3
1:3
2:1
3:4
4:2
5:5

Test: 4
1:3
2:2
3:1
Code Golf: 2D Platformer

Code Golf: 2D Platformer


By : user2111050
Date : March 29 2020, 07:55 AM
will help you Javascript:
Short Version (334 280 256 240 238 236 233 223 207 205 196 184 182 characters)
code :
a=prompt();j=i=0;while(a[++j*63]<(o="M"));while(++i<62){while(a[h=j*63+i]<"_")j++;if(a[h-63]>"B")o+="JJ";if(a[h+1]>"z")o+="J",j--;if(a[h+3]+a[h+1]=="_ ")o+="JMM",i+=2;o+="M"}alert(o)
a=prompt(); // Read the input //
j=i=0;
while(a[++j*63]<(o="M")); // Place the cursor at the "S" //
while(++i<62){ // While we are not at the end point //
 while(a[h=j*63+i]<"_")j++; // If we are on a space, we fall //
 if(a[h-63]>"B")o+="JJ";// We jump for coins //
 if(a[h+1]>"z")o+="J",j--; // We jump when we reach a wall //
 if(a[h+3]+a[h+1]=="_ ")o+="JMM",i+=2; // We jump on gap //
 o+="M" // We add the movemment in the output
}
alert(o) // Output
Related Posts Related Posts :
  • how to create a custom login page in salesforce.com?
  • Why does MPI_Init accept pointers to argc and argv?
  • How to create a Turing machine that takes a single digit decimal number from 0 - 9 and output the cube
  • Windbg + IDA: calculate an address in a module
  • Swing Panel Question
  • Spring-ws client from WSDL
  • New or not so well-known paradigms, syntax features and behaviours of programming languages?
  • How do I build a J2EE EAR file in RAD using Maven?
  • JPEG image with alpha channel on website
  • Graphics/Vision Interesting Topics
  • ASP Classic Session Variable Not Always Getting Set
  • Install avisynth under Linux via SSH
  • Drupal Views display newest content per taxonomy limit to one node
  • ejabberd component port
  • How to split table to new PowerPoint slide when content flows off current slide using Open XML SDK 2.0
  • How to Suppress Gendarme Defects?
  • Given a WAV file, its file size and sample rate, is it possible to calculate the sample count?
  • how can a Win32 App plugin load its DLL in its own directory
  • Specification Pattern and Boolean Operator Precedence
  • Building your own Interpreter that can function as a compiler
  • Static analysis framework for eclipse?
  • unable to read serialized data as message body in msmq c# 3.0
  • Planning Large Projects?
  • LaTeX - Changing the font size for a document, but in the preamble, not the document class?
  • Run Time for Linear Probing on Hash table
  • TF255440 error on configuring TFS 2010 upgrade from RC to RTM
  • I have a VSTO application as an add-in to MS Word and I want to set keyboard shortcuts to the ribbon buttons
  • Way to reduce size of .ttf fonts?
  • ASP.net 4.0 default.aspx problem on IIS6
  • XNA: How to convert a game to be compatible with the Xbox 360?
  • Inheritance of list-style-type property in Firefox (bug in Firebug?)
  • Dealing with &rest-parameters in common lisp
  • Rendering sass template from a sinatra app doesn't work. Is this due to v.1 incompatibility? Workaround?
  • Is there an external public archive of Gitorious projects?
  • 3D Character/Model Creator
  • Algorithm for Negating Sentences
  • Starting from which integer is it better to switch to another product brand versioning scheme (year-based, codenames, ..
  • The unmentioned parts of COBOL's history
  • Help me with this COUNT query for a php file
  • How does one add an "id" attribute to Html.LabelFor() in ASP.NET MVC2?
  • In freemarker is it possible to check to see if a file exists before including it?
  • What's the most effective way to interpolate between two colors? (pseudocode and bitwise ops expected)
  • mod_rewrite vs php parsing
  • problem in using appendchild in IE7
  • How does FlockDB compare with neo4j?
  • boost library gives errors on ubuntu
  • How to develop a web application in alfresco?
  • Developing an app with Camera Access and GPS
  • generalizing the pumping lemma for UNIX-style regular expressions
  • detecting pauses in a spoken word audio file using pymad, pcm, vad, etc
  • 2D Inverse Kinematics Implementation
  • Derivative of a program
  • CUDA: How to reuse kernels in multiple files (for unit testing)
  • windows mobile cab file launch main executable when complete
  • SSRS Data Driven Subscriptions and Email Bounce Backs
  • Parsing unicode character (0x2) using XML1.1
  • Mobile Handset Detection
  • How to stream image object in Sinatra
  • JNLP desktop shortcut creation with Windows 7 : "cannot create shortcut"
  • My OpenCL kernel is slower on faster hardware.. But why?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk