Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

save 1 byte
Source Link
janAkali
  • 410
  • 1
  • 7

Nim, 111(削除) 111 (削除ここまで) 110 bytes

echo"proc(n:int)=echo(case n"
for i in 0..4294967295<2 shl 32:echo "of ",i,":",repr ["even","odd"][i%%2]
echo"else: 0ドル)"

Wandbox (with 42 instead of 4294967295)

Generated function:

proc(n:int)=echo(case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: 0ドル)

Nim, 111 bytes

echo"proc(n:int)=echo(case n"
for i in 0..4294967295:echo "of ",i,":",repr ["even","odd"][i%%2]
echo"else: 0ドル)"

Wandbox (with 42 instead of 4294967295)

Generated function:

proc(n:int)=echo(case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: 0ドル)

Nim, (削除) 111 (削除ここまで) 110 bytes

echo"proc(n:int)=echo(case n"
for i in 0..<2 shl 32:echo "of ",i,":",repr ["even","odd"][i%%2]
echo"else: 0ドル)"

Wandbox (with 42 instead of 4294967295)

Generated function:

proc(n:int)=echo(case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: 0ドル)
deleted 573 characters in body
Source Link
janAkali
  • 410
  • 1
  • 7

Nim, 40111 bytes

echo"proc(n:int)=echo(case n"
for i in 0..4294967295:echo "O""of ",i,i%%2-2

Try it in Wandbox!

Generated program with header and footer:

#? replace(sub="O",by="of ") | replace(sub="-2",by=":\"even\"") | replace(sub="-1"",by=":\"odd\"")
proc p(n:int) = echo (caserepr n
O0-2
O1-1
O2-2
O3-1
O4-2
...
O4294967295-1["even","odd"][i%%2]
elseecho"else: raise newException(ValueError,"out of range")0ドル)"

Try generated program in Wandbox!

Explanation: It uses Nim's Source Code Filter Wandbox #? as pre-processor to transform:(with 42 instead of 4294967295)

  • O -> of
  • -2 -> :"even"
  • -1 -> :"odd"

Code with applied filters (as it's seen by parser)Generated function:

proc p(n:int) = echo =echo(case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: raise newException(ValueError,"out of range")0ドル)

Nim, 40 bytes

for i in 0..4294967295:echo "O",i,i%%2-2

Try it in Wandbox!

Generated program with header and footer:

#? replace(sub="O",by="of ") | replace(sub="-2",by=":\"even\"") | replace(sub="-1",by=":\"odd\"")
proc p(n:int) = echo (case n
O0-2
O1-1
O2-2
O3-1
O4-2
...
O4294967295-1
else: raise newException(ValueError,"out of range"))

Try generated program in Wandbox!

Explanation: It uses Nim's Source Code Filter #? as pre-processor to transform:

  • O -> of
  • -2 -> :"even"
  • -1 -> :"odd"

Code with applied filters (as it's seen by parser):

proc p(n:int) = echo (case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: raise newException(ValueError,"out of range"))

Nim, 111 bytes

echo"proc(n:int)=echo(case n"
for i in 0..4294967295:echo "of ",i,":",repr ["even","odd"][i%%2]
echo"else: 0ドル)"

Wandbox (with 42 instead of 4294967295)

Generated function:

proc(n:int)=echo(case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: 0ドル)
added 1 character in body
Source Link
janAkali
  • 410
  • 1
  • 7

Nim, 40 bytes

for i in 0..4294967295:echo "O",i,i%%2-2

Try it in Wandbox!

Generated program with header and footer:

#? replace(sub="O",by="of ") | replace(sub="-2",by=":\"even\"") | replace(sub="-1",by=":\"odd\"")
proc p(n:int) = echo (case n
O0-2
O1-1
O2-2
O3-1
O4-2
...
O4294967295-1
else: raise newException(ValueError,"out of range"))

Try generated program in Wandbox!

Explanation: We useIt uses Nim's Source Code Filter #? as pre-processor to transform:

  • O -> of
  • -2 -> :"even"
  • -1 -> :"odd"

Code with applied filters (onlyas it's seen by compilerparser):

proc p(n:int) = echo (case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: raise newException(ValueError,"out of range"))

Nim, 40 bytes

for i in 0..4294967295:echo "O",i,i%%2-2

Try it in Wandbox!

Generated program with header and footer:

#? replace(sub="O",by="of ") | replace(sub="-2",by=":\"even\"") | replace(sub="-1",by=":\"odd\"")
proc p(n:int) = echo (case n
O0-2
O1-1
O2-2
O3-1
O4-2
...
O4294967295-1
else: raise newException(ValueError,"out of range"))

Try generated program in Wandbox!

Explanation: We use Nim's Source Code Filter #? as pre-processor to transform:

  • O -> of
  • -2 -> :"even"
  • -1 -> :"odd"

Code with applied filters (only seen by compiler):

proc p(n:int) = echo (case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: raise newException(ValueError,"out of range"))

Nim, 40 bytes

for i in 0..4294967295:echo "O",i,i%%2-2

Try it in Wandbox!

Generated program with header and footer:

#? replace(sub="O",by="of ") | replace(sub="-2",by=":\"even\"") | replace(sub="-1",by=":\"odd\"")
proc p(n:int) = echo (case n
O0-2
O1-1
O2-2
O3-1
O4-2
...
O4294967295-1
else: raise newException(ValueError,"out of range"))

Try generated program in Wandbox!

Explanation: It uses Nim's Source Code Filter #? as pre-processor to transform:

  • O -> of
  • -2 -> :"even"
  • -1 -> :"odd"

Code with applied filters (as it's seen by parser):

proc p(n:int) = echo (case n
of 0:"even"
of 1:"odd"
of 2:"even"
of 3:"odd"
of 4:"even"
...
of 4294967295:"odd"
else: raise newException(ValueError,"out of range"))
Source Link
janAkali
  • 410
  • 1
  • 7
Loading

AltStyle によって変換されたページ (->オリジナル) /