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

Haskell, 116 96 82 76 bytes

 f x=signum$sum$zipWith(*)[-length(fst$span(<'^')x)..]$(`mod`16).fromEnum<$>x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^. Multiply the input string and the list of weights which starts at - length-of-first-part. The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trickmod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

Haskell, 116 96 82 76 bytes

 f x=signum$sum$zipWith(*)[-length(fst$span(<'^')x)..]$(`mod`16).fromEnum<$>x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^. Multiply the input string and the list of weights which starts at - length-of-first-part. The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

Haskell, 116 96 82 76 bytes

 f x=signum$sum$zipWith(*)[-length(fst$span(<'^')x)..]$(`mod`16).fromEnum<$>x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^. Multiply the input string and the list of weights which starts at - length-of-first-part. The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

deleted 2 characters in body
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100

Haskell, 116 96 82 7876 bytes

 f x=signum$sum$zipWith(*)[-length(fst$span(<'^')x)..]$map(]$(`mod`16).fromEnum)xfromEnum<$>x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^. Multiply the input string and the list of weights which starts at - length-of-first-part. The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

Haskell, 116 96 82 78 bytes

 f x=signum$sum$zipWith(*)[-length(fst$span(<'^')x)..]$map((`mod`16).fromEnum)x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^. Multiply the input string and the list of weights which starts at - length-of-first-part. The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

Haskell, 116 96 82 76 bytes

 f x=signum$sum$zipWith(*)[-length(fst$span(<'^')x)..]$(`mod`16).fromEnum<$>x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^. Multiply the input string and the list of weights which starts at - length-of-first-part. The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

added 11 characters in body
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100

Haskell, 116 96 8282 78 bytes

 x|(h,_)<-span(<'^')f x=signum$sum$zipWith(*)[-length h(fst$span(<'^')x)..]$map((`mod`16).fromEnum)x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^ (->h). Multiply the input string and the list of weights which starts at - length(h)-of-first-part. The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

Haskell, 116 96 82 bytes

 x|(h,_)<-span(<'^')x=signum$sum$zipWith(*)[-length h..]$map((`mod`16).fromEnum)x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^ (->h). Multiply the input string and the list of weights which starts at - length(h). The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

Haskell, 116 96 82 78 bytes

 f x=signum$sum$zipWith(*)[-length(fst$span(<'^')x)..]$map((`mod`16).fromEnum)x 

Output is 0 for balanced, -1 for left-heavy and 1 for right-heavy.

Usage example: f "321^ 12" -> -1

How it works: find the part before the ^. Multiply the input string and the list of weights which starts at - length-of-first-part. The ^ has a weight of 0 and doesn't add to the sum. I'm using @xnor's mod 16 trick to convert digits/spaces to integer values. If the sum is negative (positive), the lever is left-heavy (right-heavy) and balanced if the sum is 0.

added 138 characters in body
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100
Loading
output format is free to choose
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100
Loading
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100
Loading