Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Python, 245 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(*map(int,sys.argv[1:]))),key=lambda y:y[1])[0]

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Edit:

With respect to the bonus, my experiments suggest the following:

Conjecture 1. For every n ∈ ℕ, the number in n with the largest SNDD must contain solely the digits 1, 4, and 9.

Conjecture 2.n ∈ ℕ ∀ i ∈ ℕn : SNDD(n) ≥ SNDD(i).

Proof sketch. The set of squares with digits 1, 4, and 9 are likely finite. ∎

Python, 245 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(*map(int,sys.argv[1:]))),key=lambda y:y[1])[0]
  • 256 → 245: Cleaned up the argument parsing code thanks to a tip from Keith Randall.

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Edit:

With respect to the bonus, my experiments suggest the following:

Conjecture 1. For every n ∈ ℕ, the number in n with the largest SNDD must contain solely the digits 1, 4, and 9.

Conjecture 2.n ∈ ℕ ∀ i ∈ ℕn : SNDD(n) ≥ SNDD(i).

Proof sketch. The set of squares with digits 1, 4, and 9 are likely finite. ∎

Python, 245 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(*map(int,sys.argv[1:]))),key=lambda y:y[1])[0]
  • 256 → 245: Cleaned up the argument parsing code thanks to a tip from Keith Randall.

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Edit:

With respect to the bonus, my experiments suggest the following:

Conjecture 1. For every n ∈ ℕ, the number in n with the largest SNDD must contain solely the digits 1, 4, and 9.

Conjecture 2.n ∈ ℕ ∀ i ∈ ℕn : SNDD(n) ≥ SNDD(i).

Proof sketch. The set of squares with digits 1, 4, and 9 are likely finite. ∎

added 454 characters in body
Source Link
ESultanik
  • 1.1k
  • 8
  • 11

Python, 245 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(*map(int,sys.argv[1:]))),key=lambda y:y[1])[0]
  • 256 → 245: Cleaned up the argument parsing code thanks to a tip from Keith Randall.

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Edit:

With respect to the bonus, my experiments suggest the following:

Conjecture 1. For every n ∈ ℕ, the number in n with the largest SNDD must contain solely the digits 1, 4, and 9.

Conjecture 2.n ∈ ℕ ∀ i ∈ ℕn : SNDD(n) ≥ SNDD(i).

Proof sketch. The set of squares with digits 1, 4, and 9 are likely finite. ∎

Python, 245 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(*map(int,sys.argv[1:]))),key=lambda y:y[1])[0]
  • 256 → 245: Cleaned up the argument parsing code thanks to a tip from Keith Randall.

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Python, 245 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(*map(int,sys.argv[1:]))),key=lambda y:y[1])[0]
  • 256 → 245: Cleaned up the argument parsing code thanks to a tip from Keith Randall.

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Edit:

With respect to the bonus, my experiments suggest the following:

Conjecture 1. For every n ∈ ℕ, the number in n with the largest SNDD must contain solely the digits 1, 4, and 9.

Conjecture 2.n ∈ ℕ ∀ i ∈ ℕn : SNDD(n) ≥ SNDD(i).

Proof sketch. The set of squares with digits 1, 4, and 9 are likely finite. ∎

added 173 characters in body
Source Link
ESultanik
  • 1.1k
  • 8
  • 11

Python, 256245 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(int*map(sys.argv[1]),int(,sys.argv[2]argv[1:]))),key=lambda y:y[1])[0]
  • 256 → 245: Cleaned up the argument parsing code thanks to a tip from Keith Randall.

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Python, 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(int(sys.argv[1]),int(sys.argv[2]))),key=lambda y:y[1])[0]

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Python, 245 256

import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(*map(int,sys.argv[1:]))),key=lambda y:y[1])[0]
  • 256 → 245: Cleaned up the argument parsing code thanks to a tip from Keith Randall.

This could be a lot shorter if the range were read from stdin as opposed to the command line arguments.

Source Link
ESultanik
  • 1.1k
  • 8
  • 11
Loading