code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
def a(n): n += 2 return n*(n**2 + 1)/2 def inv_a(x): k = 0 while k*(k**2+1)/2+2 < x: k+=1 return k if __name__ == '__main__': print(); for n in range(1, 20): print(int(a(n)), end = ); print(,int(a(1000))); for e in range(1, 20): print(f'10^{e}: {inv_a(10**...
601Magic constant
3python
hf2jw
use File::Path qw(make_path); make_path('path/to/dir')
595Make directory path
2perl
p3hb0
use strict; use warnings; use ntheory 'fromdigits'; my @sbox = ( [4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3], [14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9], [5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11], [7, 13, 10, 1, 0, 8, 9, 15, 14, 4, 6, 12, 11, 2, 5, 3], [6, 12, 7...
596Main step of GOST 28147-89
2perl
qlax6
import java.util.ArrayList; import java.util.List; public class MagnanimousNumbers { public static void main(String[] args) { runTask("Find and display the first 45 magnanimous numbers.", 1, 45); runTask("241st through 250th magnanimous numbers.", 241, 250); runTask("391st through 400th ma...
598Magnanimous numbers
9java
tj8f9
def Dijkstra(Graph, source): ''' + +---+---+ | 0 1 2 | +---+ + + | 3 4 | 5 +---+---+---+ >>> graph = ( ... (0,1,0,0,0,0,), ... (1,0,1,0,1,0,), ... (0,1,0,0,0,1,), ... (0,0,0,0,1,0,), ... ...
587Maze solving
3python
0ufsq
import java.security.MessageDigest String.metaClass.md5Checksum = { MessageDigest.getInstance('md5').digest(delegate.bytes).collect { String.format("%02x", it) }.join('') }
590MD5
7groovy
amx1p
package main import ( "fmt" "log" ) func magicSquareOdd(n int) ([][]int, error) { if n < 3 || n%2 == 0 { return nil, fmt.Errorf("base must be odd and > 2") } value := 1 gridSize := n * n c, r := n/2, 0 result := make([][]int, n) for i := 0; i < n; i++ { result[i] =...
600Magic squares of singly even order
0go
ayr1f
from errno import EEXIST from os import mkdir, curdir from os.path import split, exists def mkdirp(path, mode=0777): head, tail = split(path) if not tail: head, tail = split(head) if head and tail and not exists(head): try: mkdirp(head, mode) except OSError as e: ...
595Make directory path
3python
16kpc
int** doublyEvenMagicSquare(int n) { if (n < 4 || n % 4 != 0) return NULL; int bits = 38505; int size = n * n; int mult = n / 4,i,r,c,bitPos; int** result = (int**)malloc(n*sizeof(int*)); for(i=0;i<n;i++) result[i] = (int*)malloc(n*sizeof(int)); for (r = 0, i = 0; r < n; r++) { for (c = 0; c < n; c++, ...
603Magic squares of doubly even order
5c
ql7xc
Matrix = {} function Matrix.new( dim_y, dim_x ) assert( dim_y and dim_x ) local matrix = {} local metatab = {} setmetatable( matrix, metatab ) metatab.__add = Matrix.Add metatab.__mul = Matrix.Mul metatab.__pow = Matrix.Pow matrix.dim_y = dim_y matrix.dim_x = dim_x matrix.da...
591Matrix-exponentiation operator
1lua
nrfi8
extern crate rand; use rand::prelude::*; use std::io; fn main() { let mut input_line = String::new(); let colors_n; let code_len; let guesses_max; let colors_dup; loop { println!("Please enter the number of colors to be used in the game (2 - 20): "); input_line.clear(); ...
594Mastermind
15rust
m16ya
import Data.Digest.OpenSSL.MD5 (md5sum) import Data.ByteString (pack) import Data.Char (ord) main = do let message = "The quick brown fox jumped over the lazy dog's back" digest = (md5sum . pack . map (fromIntegral . ord)) message putStrLn digest
590MD5
8haskell
9e2mo
import qualified Data.Map.Strict as M import Data.List (transpose, intercalate) import Data.Maybe (fromJust, isJust) import Control.Monad (forM_) import Data.Monoid ((<>)) magic :: Int -> [[Int]] magic n = mapAsTable ((4 * n) + 2) (hiResMap n) hiResMap :: Int -> M.Map (Int, Int) Int hiResMap n = let mapLux = luxMa...
600Magic squares of singly even order
8haskell
zh0t0
require 'fileutils' FileUtils.mkdir_p()
595Make directory path
14ruby
empax
k8 = [ 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 ] k7 = [ 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 ] k6 = [ 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 ] k5 = [ 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 ] k4 = [ 2, 12, 4, 1, 7, 10, ...
596Main step of GOST 28147-89
3python
s2eq9
-- Create Table -- Distinct combination --- R:Red, B:Blue, G: Green, V: Violet, O: Orange, Y: Yellow DROP TYPE IF EXISTS color cascade;CREATE TYPE color AS ENUM ('R', 'B', 'G', 'V', 'O', 'Y'); DROP TABLE IF EXISTS guesses cascade; CREATE TABLE guesses ( FIRST color, SECOND color, ...
594Mastermind
19sql
us2vq
public class MagicSquareSinglyEven { public static void main(String[] args) { int n = 6; for (int[] row : magicSquareSinglyEven(n)) { for (int x : row) System.out.printf("%2s ", x); System.out.println(); } System.out.printf("\nMagic constant:%...
600Magic squares of singly even order
9java
o5a8d
use std::fs; fn main() { fs::create_dir_all("./path/to/dir").expect("An Error Occured!") }
595Make directory path
15rust
w91e4
new java.io.File("/path/to/dir").mkdirs
595Make directory path
16scala
s2wqo
use strict; use warnings; use feature 'say'; use ntheory 'is_prime'; sub magnanimous { my($n) = @_; my $last; for my $c (1 .. length($n) - 1) { ++$last and last unless is_prime substr($n,0,$c) + substr($n,$c) } not $last; } my @M; for ( my $i = 0, my $count = 0; $count < 400; $i++ ) { ...
598Magnanimous numbers
2perl
gol4e
use 5.10.0; use List::Util 'max'; my @sum; while (<>) { my @x = split; @sum = ($x[0] + $sum[0], map($x[$_] + max(@sum[$_-1, $_]), 1 .. @x-2), $x[-1] + $sum[-1]); } say max(@sum);
588Maximum triangle path sum
2perl
85f0w
null
600Magic squares of singly even order
11kotlin
xchws
typedef double * const __restrict MAT_OUT_t; typedef double * const restrict MAT_OUT_t; typedef const double * const MAT_IN_t; static inline void mat_mult( const int m, const int n, const int p, MAT_IN_t a, MAT_IN_t b, MAT_OUT_t c) { for (int row=0; row<m; row++) { for (int c...
604Matrix multiplication
5c
3kxza
class Maze def solve reset_visiting_state @queue = [] enqueue_cell([], @start_x, @start_y) path = nil until path || @queue.empty? path = solve_visit_cell end if path for x, y in path @path[x][y] = true end else put...
587Maze solving
14ruby
o4z8v
import sequtils, strutils type Square = seq[seq[int]] func magicSquareOdd(n: Positive): Square = ## Build a magic square of odd order. assert n >= 3 and (n and 1)!= 0, "base must be odd and greater than 2." result = newSeqWith(n, newSeq[int](n)) var r = 0 c = n div 2 value = 0 while value < n...
600Magic squares of singly even order
1lua
qlkx0
null
600Magic squares of singly even order
2perl
2xzlf
use std::convert::TryInto; use std::env; use std::num::Wrapping; const REPLACEMENT_TABLE: [[u8; 16]; 8] = [ [4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3], [14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9], [5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11], [7, 13, 10, 1, 0, 8, 9, 15,...
596Main step of GOST 28147-89
15rust
o5q83
use rand::{thread_rng, Rng, rngs::ThreadRng}; const WIDTH: usize = 16; const HEIGHT: usize = 16; #[derive(Clone, Copy, PartialEq)] struct Cell { col: usize, row: usize, } impl Cell { fn from(col: usize, row: usize) -> Cell { Cell {col, row} } } struct Maze { cells: [[bool; HEIGHT]; WIDTH...
587Maze solving
15rust
ig3od
void transpose(void *dest, void *src, int src_h, int src_w) { int i, j; double (*d)[src_h] = dest, (*s)[src_w] = src; for (i = 0; i < src_h; i++) for (j = 0; j < src_w; j++) d[j][i] = s[i][j]; } int main() { int i, j; double a[3][5] = {{ 0, 1, 2, 3, 4 }, { 5, 6, 7, 8, 9 }, { 1, 0, 0, 0, 42}}; doub...
605Matrix transposition
5c
ri3g7
enum errors: Error {
587Maze solving
17swift
85t0v
import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Digester { public static void main(String[] args) { System.out.println(hexDigest("Rosetta code", "MD5")); } static String hexDigest(String str, String digestNa...
590MD5
9java
th6f9
import math from sys import stdout LOG_10 = 2.302585092994 def build_oms(s): if s% 2 == 0: s += 1 q = [[0 for j in range(s)] for i in range(s)] p = 1 i = s j = 0 while p <= (s * s): q[i][j] = p ti = i + 1 if ti >= s: ti = 0 tj = j - 1 if tj < ...
600Magic squares of singly even order
3python
vq329
package main import ( "fmt" "log" "strings" ) const dimensions int = 8 func setupMagicSquareData(d int) ([][]int, error) { var output [][]int if d < 4 || d%4 != 0 { return [][]int{}, fmt.Errorf("Square dimension must be a positive number which is divisible by 4") } var bits uint = 0x9669
603Magic squares of doubly even order
0go
2xdl7
require magnanimouses = Enumerator.new do |y| (0..).each {|n| y << n if (1..n.digits.size-1).all? {|k| n.divmod(10**k).sum.prime?} } end puts puts magnanimouses.first(45).join(' ') puts puts magnanimouses.first(250).last(10).join(' ') puts puts magnanimouses.first(400).last(10).join(' ')
598Magnanimous numbers
14ruby
jdu7x
use strict; package SquareMatrix; use Carp; use overload ( '""' => \&_string, '*' => \&_mult, '*=' => \&_mult, '**' => \&_expo, '=' => \&_copy, ); sub make { my $cls = shift; my $n = @_; for ...
591Matrix-exponentiation operator
2perl
rnjgd
> magic(6) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 35 1 6 26 19 24 [2,] 3 32 7 21 23 25 [3,] 31 9 2 22 27 20 [4,] 8 28 33 17 10 15 [5,] 30 5 34 12 14 16 [6,] 4 36 29 13 18 11
600Magic squares of singly even order
13r
9admg
def odd_magic_square(n) n.times.map{|i| n.times.map{|j| n*((i+j+1+n/2)%n) + ((i+2*j-5)%n) + 1} } end def single_even_magic_square(n) raise ArgumentError, unless (n-2) % 4 == 0 raise ArgumentError, if n == 2 order = (n-2)/4 odd_square = odd_magic_square(n/2) to_add = (0..3).map{|f| f*n*n/4} quarts = t...
600Magic squares of singly even order
14ruby
50yuj
import Data.List (transpose, unfoldr, intercalate) import Data.List.Split (chunksOf) import Data.Bool (bool) import Control.Monad (forM_) magicSquare :: Int -> [[Int]] magicSquare n | rem n 4 > 0 = [] | otherwise = chunksOf n $ zipWith (flip (bool =<< (-) limit)) series [1 .. sqr] where sqr = n * n l...
603Magic squares of doubly even order
8haskell
ay51g
fn is_prime(n: u32) -> bool { if n < 2 { return false; } if n% 2 == 0 { return n == 2; } if n% 3 == 0 { return n == 3; } let mut p = 5; while p * p <= n { if n% p == 0 { return false; } p += 2; if n% p == 0 { ...
598Magnanimous numbers
15rust
hf5j2
import Foundation func isPrime(_ n: Int) -> Bool { if n < 2 { return false } if n% 2 == 0 { return n == 2 } if n% 3 == 0 { return n == 3 } var p = 5 while p * p <= n { if n% p == 0 { return false } p += 2 if n% p == 0 {...
598Magnanimous numbers
17swift
7nvrq
use std::env; fn main() { let n: usize = match env::args().nth(1).and_then(|arg| arg.parse().ok()).ok_or( "Please specify the size of the magic square, as a positive multiple of 4 plus 2.", ) { Ok(arg) if arg% 2 == 1 || arg >= 6 && (arg - 2)% 4 == 0 => arg, Err(e...
600Magic squares of singly even order
15rust
48m5u
int f(int n, int x, int y) { return (x + y*2 + 1)%n; } int main(int argc, char **argv) { int i, j, n; if(argc!=2) return 1; n = atoi(argv[1]); if (n < 3 || (n%2) == 0) return 2; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) printf(, f(n, n - j - 1, i)*n + f(n, j, i) + 1); putchar('\n'); } pri...
606Magic squares of odd order
5c
8u704
(defn transpose [s] (apply map vector s)) (defn nested-for [f x y] (map (fn [a] (map (fn [b] (f a b)) y)) x)) (defn matrix-mult [a b] (nested-for (fn [x y] (reduce + (map * x y))) a (transpose b))) (def ma [[1 1 1 1] [2 4 8 16] [3 9 27 81] [4 16 64 256]]) (def mb [[4 -3 4...
604Matrix multiplication
6clojure
ceo9b
public class MagicSquareDoublyEven { public static void main(String[] args) { int n = 8; for (int[] row : magicSquareDoublyEven(n)) { for (int x : row) System.out.printf("%2s ", x); System.out.println(); } System.out.printf("\nMagic constant:%...
603Magic squares of doubly even order
9java
jd97c
(defmulti matrix-transpose "Switch rows with columns." class) (defmethod matrix-transpose clojure.lang.PersistentList [mtx] (apply map list mtx)) (defmethod matrix-transpose clojure.lang.PersistentVector [mtx] (apply mapv vector mtx))
605Matrix transposition
6clojure
bzckz
>>> from operator import mul >>> def matrixMul(m1, m2): return map( lambda row: map( lambda *column: sum(map(mul, row, column)), *m2), m1) >>> def identity(size): size = range(size) return [[(i==j)*1 for i in size] for j in size] >>> def matrixExp(m, pow): assert pow>=0 an...
591Matrix-exponentiation operator
3python
7dhrm
def solve(tri): while len(tri) > 1: t0 = tri.pop() t1 = tri.pop() tri.append([max(t0[i], t0[i+1]) + t for i,t in enumerate(t1)]) return tri[0][0] data = print solve([map(int, row.split()) for row in data.splitlines()])
588Maximum triangle path sum
3python
o4t81
null
590MD5
11kotlin
o4d8z
(() => { 'use strict';
603Magic squares of doubly even order
10javascript
16up7
library(Biodem) m <- matrix(c(3,2,2,1), nrow=2) mtx.exp(m, 0) mtx.exp(m, 1) mtx.exp(m, 2) mtx.exp(m, 3) mtx.exp(m, 10)
591Matrix-exponentiation operator
13r
58guy
package main import ( "bytes" "fmt" "math/rand" "time" ) type maze struct { c []byte
597Maze generation
0go
go24n
int main() { int iX,iY; const int iXmax = 800; const int iYmax = 800; double Cx,Cy; const double CxMin=-2.5; const double CxMax=1.5; const double CyMin=-2.0; const double CyMax=2.0; double PixelWidth=(CxMax-CxMin)/iXm...
607Mandelbrot set
5c
s24q5
null
603Magic squares of doubly even order
11kotlin
50zua
package main import "fmt" func a(k int, x1, x2, x3, x4, x5 func() int) int { var b func() int b = func() int { k-- return a(k, b, x1, x2, x3, x4) } if k <= 0 { return x4() + x5() } return b() } func main() { x := func(i int) func() int { return func() int { return i } } fmt.Println(a(10, x(1), x(-1), x(...
599Man or boy test
0go
emja6
import Data.Array.ST (STArray, freeze, newArray, readArray, writeArray) import Data.STRef (STRef, newSTRef, readSTRef, writeSTRef) import System.Random (Random(..), getStdGen, StdGen) import Control.Monad (forM_, unless) import Control.Monad.ST (ST, stToIO) import Data.Array (Array, (!), bounds) import Data.Bool...
597Maze generation
8haskell
s2aqk
$ irb irb(main):001:0> require 'matrix' => true irb(main):002:0> m=Matrix[[3,2],[2,1]] => Matrix[[3, 2], [2, 1]] irb(main):003:0> m**0 => Matrix[[1, 0], [0, 1]] irb(main):004:0> m ** 1 => Matrix[[3, 2], [2, 1]] irb(main):005:0> m ** 2 => Matrix[[13, 8], [8, 5]] irb(main):006:0> m ** 5 => Matrix[[987, 610], [610, 377]] ...
591Matrix-exponentiation operator
14ruby
htbjx
use std::fmt; use std::ops; const WIDTH: usize = 6; #[derive(Clone)] struct SqMat { data: Vec<Vec<i64>>, } impl fmt::Debug for SqMat { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut row = "".to_string(); for i in &self.data { for j in i { row += ...
591Matrix-exponentiation operator
15rust
kzph5
include "NSLog.incl" local fn MapRange( s as double, a1 as double, a2 as double, b1 as double, b2 as double ) as double end fn = b1+(s-a1)*(b2-b1)/(a2-a1) NSInteger i for i = 0 to 10 NSLog( @"%2d maps to%5.1f", i, fn MapRange( i, 0, 10, -1, 0 ) ) next HandleEvents
602Map range
0go
8ub0g
package main import "fmt" type rangeBounds struct { b1, b2 float64 } func mapRange(x, y rangeBounds, n float64) float64 { return y.b1 + (n - x.b1) * (y.b2 - y.b1) / (x.b2 - x.b1) } func main() { r1 := rangeBounds{0, 10} r2 := rangeBounds{-1, 0} for n := float64(0); n <= 10; n += 2 { fmt....
602Map range
0go
8ub0g
import bitops, sequtils, strutils type Square = seq[seq[int]] func magicSquareDoublyEven(n: int): Square = ## Build a magic square of doubly even order. assert n >= 4 and (n and 3) == 0, "base must be a positive multiple of 4." result = newSeqWith(n, newSeq[int](n)) const bits = 0b1001_0110_0110_1001 # Pat...
603Magic squares of doubly even order
1lua
4835c
def a; a = { k, x1, x2, x3, x4, x5 -> def b; b = { a (--k, b, x1, x2, x3, x4) } k <= 0 ? x4() + x5(): b() } def x = { n -> { it -> n } }
599Man or boy test
7groovy
kt5h7
class Matrix[T](matrix:Array[Array[T]])(implicit n: Numeric[T], m: ClassManifest[T]) { import n._ val rows=matrix.size val cols=matrix(0).size def row(i:Int)=matrix(i) def col(i:Int)=matrix map (_(i)) def *(other: Matrix[T]):Matrix[T] = new Matrix( Array.tabulate(rows, other.cols)((row, col) => (...
591Matrix-exponentiation operator
16scala
1yepf
def mapRange(a1, a2, b1, b2, s) { b1 + ((s - a1) * (b2 - b1)) / (a2 - a1) } (0..10).each { s -> println(s + " in [0, 10] maps to " + mapRange(0, 10, -1, 0, s) + " in [-1, 0].") }
602Map range
7groovy
w9rel
import Data.Ratio import Text.Printf (PrintfType, printf) mapRange :: Fractional a => (a, a) -> (a, a) -> a -> a mapRange (a1, a2) (b1, b2) s = b1 + (s - a1) * (b2 - b1) / (a2 - a1) main :: IO () main = do putStrLn " mapM_ (\n -> prtD n . mapRange (0, 10) (-1, 0) $ fromIntegral n) [0 .. 10] putStrLn ...
602Map range
8haskell
lwdch
null
603Magic squares of doubly even order
2perl
o5b8x
import Data.IORef (modifyIORef, newIORef, readIORef) a :: (Enum a, Num b, Num a, Ord a) => a -> IO b -> IO b -> IO b -> IO b -> IO b -> IO b a k x1 x2 x3 x4 x5 = do r <- newIORef k let b = do k <- pred ! r a k b x1 x2 x3 x4 if k <= 0 then (+) <$> x4 <*> x5 else b where f !r = mo...
599Man or boy test
8haskell
3kozj
triangle = ar = triangle.each_line.map{|line| line.split.map(&:to_i)} puts ar.inject([]){|res,x| maxes = [0, *res, 0].each_cons(2).map(&:max) x.zip(maxes).map{|a,b| a+b} }.max
588Maximum triangle path sum
14ruby
nr3it
require "md5"
590MD5
1lua
igfot
public class Range { public static void main(String[] args){ for(float s = 0;s <= 10; s++){ System.out.println(s + " in [0, 10] maps to "+ mapRange(0, 10, -1, 0, s)+" in [-1, 0]."); } } public static double mapRange(double a1, double a2, double b1, double b2, double s){ return b1 + ((s - a1)*(b2 - b1...
602Map range
9java
3kszg
use std::cmp::max; fn max_path(vector: &mut Vec<Vec<u32>>) -> u32 { while vector.len() > 1 { let last = vector.pop().unwrap(); let ante = vector.pop().unwrap(); let mut new: Vec<u32> = Vec::new(); for (i, value) in ante.iter().enumerate() { new.push(max(last[i], last...
588Maximum triangle path sum
15rust
d76ny
package org.rosettacode; import java.util.Collections; import java.util.Arrays; public class MazeGenerator { private final int x; private final int y; private final int[][] maze; public MazeGenerator(int x, int y) { this.x = x; this.y = y; maze = new int[this.x][this.y]; generateMaze(0, 0); } public ...
597Maze generation
9java
16jp2
null
602Map range
10javascript
cen9j
object MaximumTrianglePathSum extends App {
588Maximum triangle path sum
16scala
zk9tr
(ns mandelbrot (:refer-clojure :exclude [+ * <]) (:use (clojure.contrib complex-numbers) (clojure.contrib.generic [arithmetic :only [+ *]] [comparison :only [<]] [math-functions :only [abs]]))) (defn mandelbrot? [z] (loop [c 1 m (i...
607Mandelbrot set
6clojure
nghik
def MagicSquareDoublyEven(order): sq = [range(1+n*order,order + (n*order)+1) for n in range(order) ] n1 = order/4 for r in range(n1): r1 = sq[r][n1:-n1] r2 = sq[order -r - 1][n1:-n1] r1.reverse() r2.reverse() sq[r][n1:-n1] = r2 sq[order -r - 1][n1:-n1] = r1 ...
603Magic squares of doubly even order
3python
i4pof
import java.util.function.DoubleSupplier; public class ManOrBoy { static double A(int k, DoubleSupplier x1, DoubleSupplier x2, DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) { DoubleSupplier B = new DoubleSupplier() { int m = k; public double getAsDouble...
599Man or boy test
9java
i4wos
function maze(x,y) { var n=x*y-1; if (n<0) {alert("illegal maze dimensions");return;} var horiz =[]; for (var j= 0; j<x+1; j++) horiz[j]= [], verti =[]; for (var j= 0; j<x+1; j++) verti[j]= [], here = [Math.floor(Math.random()*x), Math.floor(Math.random()*y)], path = [here], unvisited = []; for ...
597Maze generation
10javascript
ql1x8
magic <- function(n) { if (n%% 2 == 1) { p <- (n + 1)%/% 2 - 2 ii <- seq(n) outer(ii, ii, function(i, j) n * ((i + j + p)%% n) + (i + 2 * (j - 1))%% n + 1) } else if (n%% 4 == 0) { p <- n * (n + 1) + 1 ii <- seq(n) outer(ii, ii, function(i, j) ifelse((i%/% 2 - j%/% 2)%% 2 == 0, p - n * i - j...
603Magic squares of doubly even order
13r
s2jqy
function a(k, x1, x2, x3, x4, x5) { function b() { k -= 1; return a(k, b, x1, x2, x3, x4); } return (k > 0) ? b() : x4() + x5(); }
599Man or boy test
10javascript
zh8t2
null
602Map range
11kotlin
ngaij
package main import ( "fmt" "log" ) func ms(n int) (int, []int) { M := func(x int) int { return (x + n - 1) % n } if n <= 0 || n&1 == 0 { n = 5 log.Println("forcing size", n) } m := make([]int, n*n) i, j := 0, n/2 for k := 1; k <= n*n; k++ { m[i*n+j] = k ...
606Magic squares of odd order
0go
50dul
import java.util.* class MazeGenerator(val x: Int, val y: Int) { private val maze = Array(x) { IntArray(y) } fun generate(cx: Int, cy: Int) { Direction.values().shuffle().forEach { val nx = cx + it.dx val ny = cy + it.dy if (between(nx, x) && between(ny, y) && maze[...
597Maze generation
11kotlin
jd57r
import Data.List type Var = (Int, Int, Int, Int) magicSum :: Int -> Int magicSum x = ((x * x + 1) `div` 2) * x wrapInc :: Int -> Int -> Int wrapInc max x | x + 1 == max = 0 | otherwise = x + 1 wrapDec :: Int -> Int -> Int wrapDec max x | x == 0 = max - 1 | otherwise = x - 1 isZero :: [[Int...
606Magic squares of odd order
8haskell
xc5w4
def double_even_magic_square(n) raise ArgumentError, if n%4 > 0 block_size, max = n/4, n*n pre_pat = [true, false, false, true, false, true, true, false] pre_pat += pre_pat.reverse pattern = pre_pat.flat_map{|b| [b] * block_size} * block_size flat_ar = pattern.each_with_index.map{|yes, num| ye...
603Magic squares of doubly even order
14ruby
drans
use std::env; fn main() { let n: usize = match env::args() .nth(1) .and_then(|arg| arg.parse().ok()) .ok_or("Please specify the size of the magic square, as a positive multiple of 4.") { Ok(arg) if arg >= 4 && arg% 4 == 0 => arg, Err(e) => panic!(e), _ => panic!(...
603Magic squares of doubly even order
15rust
f7ed6
null
599Man or boy test
11kotlin
qlbx1
math.randomseed( os.time() )
597Maze generation
1lua
hf4j8
object MagicSquareDoublyEven extends App { private val n = 8 private def magicSquareDoublyEven(n: Int): Array[Array[Int]] = { require(n >= 4 || n % 4 == 0, "Base must be a positive multiple of 4.")
603Magic squares of doubly even order
16scala
3kqzy
function a(k,x1,x2,x3,x4,x5) local function b() k = k - 1 return a(k,b,x1,x2,x3,x4) end if k <= 0 then return x4() + x5() else return b() end end function K(n) return function() return n end end print(a(10, K(1), K(-1), K(-1), K(1), K(0)))
599Man or boy test
1lua
s2pq8
function map_range( a1, a2, b1, b2, s ) return b1 + (s-a1)*(b2-b1)/(a2-a1) end for i = 0, 10 do print( string.format( "f(%d) =%f", i, map_range( 0, 10, -1, 0, i ) ) ) end
602Map range
1lua
drenq
class Complex { double _r,_i; Complex(this._r,this._i); double get r => _r; double get i => _i; String toString() => "($r,$i)"; Complex operator +(Complex other) => new Complex(r+other.r,i+other.i); Complex operator *(Complex other) => new Complex(r*other.r-i*other.i,r*other.i+other.r*i); double...
607Mandelbrot set
18dart
16cp0
public class MagicSquare { public static void main(String[] args) { int n = 5; for (int[] row : magicSquareOdd(n)) { for (int x : row) System.out.format("%2s ", x); System.out.println(); } System.out.printf("\nMagic constant:%d ", (n * n + 1) ...
606Magic squares of odd order
9java
bz9k3
(function () {
606Magic squares of odd order
10javascript
w9ue2
null
606Magic squares of odd order
11kotlin
rizgo
rp[v_, pos_]:= RotateRight[v, (Length[v] + 1)/2 - pos]; rho[m_]:= MapIndexed[rp, m]; magic[n_]:= rho[Transpose[rho[Table[i*n + j, {i, 0, n - 1}, {j, 1, n}]]]]; square = magic[11] // Grid Print["Magic number is ", Total[square[[1, 1]]]]
606Magic squares of odd order
1lua
7n3ru
sub A { my ($k, $x1, $x2, $x3, $x4, $x5) = @_; my($B); $B = sub { A(--$k, $B, $x1, $x2, $x3, $x4) }; $k <= 0 ? &$x4 + &$x5 : &$B; } print A(10, sub{1}, sub {-1}, sub{-1}, sub{1}, sub{0} ), "\n";
599Man or boy test
2perl
vq620
use List::Util 'max'; my ($w, $h) = @ARGV; $w ||= 26; $h ||= 127; my $avail = $w * $h; my @cell = (map([(('1') x $w), 0], 1 .. $h), [('') x ($w + 1)]); my @ver = map([("| ") x $w], 1 .. $h); my @hor = map([("+--") x $w], 0 .. $h); sub walk { my ($x, $y) = @_; $cell[$y][$x] = ''; $avail-- or return; my @d = (...
597Maze generation
2perl
tjofg
use strict ; sub mapValue { my ( $range1 , $range2 , $number ) = @_ ; return ( $range2->[ 0 ] + (( $number - $range1->[ 0 ] ) * ( $range2->[ 1 ] - $range2->[ 0 ] ) ) / ( $range1->[ -1 ] - $range1->[ 0 ] ) ) ; } my @numbers = 0..10 ; my @interval = ( -1 , 0 ) ; print "The mapped value for $_ is " . m...
602Map range
2perl
7n9rh
<?php function A($k,$x1,$x2,$x3,$x4,$x5) { $b = function () use (&$b,&$k,$x1,$x2,$x3,$x4) { return A(--$k,$b,$x1,$x2,$x3,$x4); }; return $k <= 0? $x4() + $x5() : $b(); } echo A(10, function () { return 1; }, function () { return -1; }, function () { return -1; }, ...
599Man or boy test
12php
0v1sp
<?php class Maze { protected $width; protected $height; protected $grid; protected $path; protected $horWalls; protected $vertWalls; protected $dirs; protected $isDebug; public function __construct($x, $y, $debug = false) { $this->width = $x; $this->height = $y;...
597Maze generation
12php
ktghv