Skip to main content
Commonmark migration
Source Link

#Smalltalk (Smalltalk/X), 63/78#

Smalltalk (Smalltalk/X), 63/78

the first version creates an intermediate string (78):

t:=Number readFrom:Stdin.
((15to:1by:-1)collect:[:i|$0+(t>>i&1)]as:String)print

actually, there is no need to create the string; just output the chars (63):

t:=Number readFrom:Stdin.
15to:1by:-1 do:[:i|($0+(t>>i&1))print]

mhmh - is there a shorter way to read to a number?

#Smalltalk (Smalltalk/X), 63/78#

the first version creates an intermediate string (78):

t:=Number readFrom:Stdin.
((15to:1by:-1)collect:[:i|$0+(t>>i&1)]as:String)print

actually, there is no need to create the string; just output the chars (63):

t:=Number readFrom:Stdin.
15to:1by:-1 do:[:i|($0+(t>>i&1))print]

mhmh - is there a shorter way to read to a number?

Smalltalk (Smalltalk/X), 63/78

the first version creates an intermediate string (78):

t:=Number readFrom:Stdin.
((15to:1by:-1)collect:[:i|$0+(t>>i&1)]as:String)print

actually, there is no need to create the string; just output the chars (63):

t:=Number readFrom:Stdin.
15to:1by:-1 do:[:i|($0+(t>>i&1))print]

mhmh - is there a shorter way to read to a number?

Source Link
blabla999
  • 2k
  • 12
  • 11

#Smalltalk (Smalltalk/X), 63/78#

the first version creates an intermediate string (78):

t:=Number readFrom:Stdin.
((15to:1by:-1)collect:[:i|$0+(t>>i&1)]as:String)print

actually, there is no need to create the string; just output the chars (63):

t:=Number readFrom:Stdin.
15to:1by:-1 do:[:i|($0+(t>>i&1))print]

mhmh - is there a shorter way to read to a number?