Skip to main content
added 324 characters in body
Source Link
user12205
  • 9k
  • 3
  • 32
  • 65

Python, 88

This is no where near short, but this demonstrate how a normal mental division by five should be done. This assumes that the input must be of the form xx.xx

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[0]+'.'+a[1]+b),1)

Or for input of any length, an addition of 3 characters is required.

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[:-1]+'.'+a[-1]+b),1)

Explanation: We take the input as string, then move the decimal point one place forward (dividing by 10). We then cast it to a float, and use the ldexp function to multiply it by 2.

Note that in this answer, the + are string concatenation operators, and the -% and the signs forare used to format -1print.

If you insist on not using any of these characters, here is a 159 character solution:

import math
a,b=raw_input().split('.')
l=[a[0]]
l.append('.')
l.append(a[1])
l.append(b)
c=str(math.ldexp(float(''.join(l)),1))
print ''.join([c[0:2],c[2:4]])

Python, 88

This is no where near short, but this demonstrate how a normal mental division by five should be done. This assumes that the input must be of the form xx.xx

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[0]+'.'+a[1]+b),1)

Or for input of any length, an addition of 3 characters is required.

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[:-1]+'.'+a[-1]+b),1)

Explanation: We take the input as string, then move the decimal point one place forward (dividing by 10). We then cast it to a float, and use the ldexp function to multiply it by 2.

Note that in this answer, the + are string concatenation operators, and the - and the signs for -1.

Python, 88

This is no where near short, but this demonstrate how a normal mental division by five should be done. This assumes that the input must be of the form xx.xx

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[0]+'.'+a[1]+b),1)

Or for input of any length, an addition of 3 characters is required.

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[:-1]+'.'+a[-1]+b),1)

Explanation: We take the input as string, then move the decimal point one place forward (dividing by 10). We then cast it to a float, and use the ldexp function to multiply it by 2.

Note that in this answer, the + are string concatenation operators, and the % are used to format print.

If you insist on not using any of these characters, here is a 159 character solution:

import math
a,b=raw_input().split('.')
l=[a[0]]
l.append('.')
l.append(a[1])
l.append(b)
c=str(math.ldexp(float(''.join(l)),1))
print ''.join([c[0:2],c[2:4]])
edited body
Source Link
user12205
  • 9k
  • 3
  • 32
  • 65

Python, 8988

This is no where near short, but this demonstrate how a normal mental division by five should be done. This assumes that the input must be of the form xx.xx

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[0]+'.'+a[1]+b),-1)

Or for input of any length, an addition of 3 characters is required.

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[:-1]+'.'+a[-1]+b),-1)

Explanation: We take the input as string, then move the decimal point one place forward (dividing by 10). We then cast it to a float, and use the ldexp function to dividemultiply it by 2.

Note that in this answer, the + are string concatenation operators, and the - and the signs for -1.

Python, 89

This is no where near short, but this demonstrate how a normal mental division by five should be done. This assumes that the input must be of the form xx.xx

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[0]+'.'+a[1]+b),-1)

Or for input of any length, an addition of 3 characters is required.

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[:-1]+'.'+a[-1]+b),-1)

Explanation: We take the input as string, then move the decimal point one place forward (dividing by 10). We then cast it to a float, and use the ldexp function to divide it by 2.

Note that in this answer, the + are string concatenation operators, and the - and the signs for -1.

Python, 88

This is no where near short, but this demonstrate how a normal mental division by five should be done. This assumes that the input must be of the form xx.xx

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[0]+'.'+a[1]+b),1)

Or for input of any length, an addition of 3 characters is required.

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[:-1]+'.'+a[-1]+b),1)

Explanation: We take the input as string, then move the decimal point one place forward (dividing by 10). We then cast it to a float, and use the ldexp function to multiply it by 2.

Note that in this answer, the + are string concatenation operators, and the - and the signs for -1.

Source Link
user12205
  • 9k
  • 3
  • 32
  • 65

Python, 89

This is no where near short, but this demonstrate how a normal mental division by five should be done. This assumes that the input must be of the form xx.xx

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[0]+'.'+a[1]+b),-1)

Or for input of any length, an addition of 3 characters is required.

import math
a,b=raw_input().split('.')
print'%.2f'%math.ldexp(float(a[:-1]+'.'+a[-1]+b),-1)

Explanation: We take the input as string, then move the decimal point one place forward (dividing by 10). We then cast it to a float, and use the ldexp function to divide it by 2.

Note that in this answer, the + are string concatenation operators, and the - and the signs for -1.