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

Post Undeleted by Dom Hastings
added 314 characters in body
Source Link
Dom Hastings
  • 24.6k
  • 4
  • 58
  • 94

Perl 5 , 1 byte per line, 275 bytes

Perl 5 , 2 bytes per line, 182 bytes

$
#
_
#
=
#
'
x
d
!
K
z
o
Q
U
9
$
Z
o
Q
U
?
v
.
&
%
e
*
$
6
)
'
#
^
#
{'
c
~
"
z
fEr
#0h
.|R
/hR
Wo
"'#
c^#
#'I
. O
/Ro
W3f
v+~
U'#
.
l
x
;
$
4
'
#
^
(#
pp#
#|#
;Y#
)#
&
}#
{
(#
'
E
O
0
|
f
s
o'z
';d
#y"
^"z
#7#
'vU
aW
XzZ
07#
ovU
kgW
h..
~
'
#
^
#
C
#
.
#
(
#
a
#
^
#
a
#4e
)r;
#|6
x'#
#^#
(
#
9
#
+'
#xR
4~R
#KR
)fR
#QR
./R
#$R
(cR
#QR
Y/R
#vR
^UR
#%R
zxR
#$R
^'#
.#
Z
#4#
)
#
})

Try it online! Try it online!

Explanation

Perl's syntax is very forgiving, so the basicsa lot of this are pretty simple to achieve. Variables are normally declared like $_=... but yougaps can have whitespace separatingbe added to the sigil $code and the variable namecomments added, which means it's possible to assign to variables without any complicated tricks. To buildmakes the actualcore idea fairly straightforward. The main aim with this code is to generatebuild a string containing the FizzBu-ApplePie numbers, it's possiblecode we want to XOR two stringsrun, utilising the newlines so that additional whitespace doesn't need to be removed. I used this script to generate the strings to XOR.

The resultant strings end up with aand NULeval byte at the start and a trailing newline whichit. In Perl won't like in the call, so that needs to be XORed again to switch outit's possible to the desired characters. Oncecall a function using a string or variable with the desired code is in $_&{...} notation, all that needs to happen is a call to eval.

Apparentlyunfortunately however, eval doesn't exist at aisn't callable location the way we want to call itin this form, but fortunately, evalbytes exists withinis, as long as you call it via the CORE:: namespace. Using the sub sigil (&) we can build aBuilding that string was fairly straightforward and pass in (&{"CORE::evalbytes"}) in much the same way as the main stringprogram is built.

I'd hopedpassed directly to be ablethis call. The strings are built utilising the newlines as part of the XOR, to usebuild these s///eI used this script . To keep this valid, but a newline between the final delimiter and the modifiers seemedfew places have had to cause problemshave comments placed, so that removing the newlines would result in non-functioning code.

The FizzBuzz routine was taken from primo's excellent answer.


Perl 5 , 1 byte per line, 172 bytes

So, I (now) know this is invalid, because a bunch of the newlines can be removed, but since this was my original approach to the problem I'm adding it. It was fun see how far you can push Perl's syntax! I enjoyed this problem on its own merit, even though it's invalid.

&
{
(
I
.
'
X
0
o
k
h
~
'
.
(
p
|
Y
)
)
^
'
E
O
0
|
f
s
o
'
}
(
'
x
d
!
K
z
o
Q
U
9
$
Z
o
Q
U
?
v
.
&
%
e
*
$
6
'
^
'
c
~
"
z
f
#
.
/
W
"
c
#
.
/
W
v
U
.
l
x
;
$
4
'
^
p
)

Try it online!

Perl 5 , 1 byte per line, 275 bytes

$
#
_
#
=
#
'
x
d
!
K
z
o
Q
U
9
$
Z
o
Q
U
?
v
.
&
%
e
*
$
6
)
'
#
^
#
'
c
~
"
z
f
#
.
/
W
"
c
#
.
/
W
v
U
.
l
x
;
$
4
'
#
^
#
p
#
;
#
&
#
{
#
'
E
O
0
|
f
s
o
'
#
^
#
'
X
0
o
k
h
~
'
#
^
#
C
#
.
#
(
#
a
#
^
#
a
#
)
#
x
#
(
#
9
#
+
#
4
#
)
#
.
#
(
#
Y
#
^
#
z
#
^
#
Z
#
)
#
}

Try it online!

Explanation

Perl's syntax is very forgiving, so the basics of this are pretty simple to achieve. Variables are normally declared like $_=... but you can have whitespace separating the sigil $ and the variable name, which means it's possible to assign to variables without any complicated tricks. To build the actual code to generate the FizzBu-ApplePie numbers, it's possible to XOR two strings, utilising the newlines so that additional whitespace doesn't need to be removed. I used this script to generate the strings to XOR.

The resultant strings end up with a NUL byte at the start and a trailing newline which Perl won't like in the call, so that needs to be XORed again to switch out to the desired characters. Once the desired code is in $_, all that needs to happen is a call to eval.

Apparently eval doesn't exist at a callable location the way we want to call it, but fortunately, evalbytes exists within the CORE:: namespace. Using the sub sigil (&) we can build a string and pass in (&{"CORE::evalbytes"}) in much the same way as the main string is built.

I'd hoped to be able to use s///e, but a newline between the final delimiter and the modifiers seemed to cause problems.

The FizzBuzz routine was taken from primo's excellent answer.

Perl 5 , 2 bytes per line, 182 bytes

&
#
{'
Er
0h
|R
hR
o
'#
^#
'I
 O
Ro
3f
+~
'#
.#
(#
p#
|#
Y#
)#
}#
(#
'z
;d
y"
"z
7#
vU
aW
zZ
7#
vU
gW
..
~.
4e
r;
|6
'#
^#
('
xR
~R
KR
fR
QR
/R
$R
cR
QR
/R
vR
UR
%R
xR
$R
'#
.#
4#
))

Try it online!

Perl's syntax is very forgiving, so a lot of gaps can be added to the code and comments added, which makes the core idea fairly straightforward. The main aim with this code is to build a string containing the code we want to run, and eval it. In Perl, it's possible to call a function using a string or variable with the &{...} notation, unfortunately however, eval isn't callable in this form, but evalbytes is, as long as you call it via the CORE:: namespace. Building that string was fairly straightforward and the program is passed directly to this call. The strings are built utilising the newlines as part of the XOR, to build these I used this script . To keep this valid, a few places have had to have comments placed, so that removing the newlines would result in non-functioning code.

The FizzBuzz routine was taken from primo's excellent answer.


Perl 5 , 1 byte per line, 172 bytes

So, I (now) know this is invalid, because a bunch of the newlines can be removed, but since this was my original approach to the problem I'm adding it. It was fun see how far you can push Perl's syntax! I enjoyed this problem on its own merit, even though it's invalid.

&
{
(
I
.
'
X
0
o
k
h
~
'
.
(
p
|
Y
)
)
^
'
E
O
0
|
f
s
o
'
}
(
'
x
d
!
K
z
o
Q
U
9
$
Z
o
Q
U
?
v
.
&
%
e
*
$
6
'
^
'
c
~
"
z
f
#
.
/
W
"
c
#
.
/
W
v
U
.
l
x
;
$
4
'
^
p
)

Try it online!

Post Deleted by Dom Hastings
Source Link
Dom Hastings
  • 24.6k
  • 4
  • 58
  • 94

Perl 5, 1 byte per line, 275 bytes

$
#
_
#
=
#
'
x
d
!
K
z
o
Q
U
9
$
Z
o
Q
U
?
v
.
&
%
e
*
$
6
)
'
#
^
#
'
c
~
"
z
f
#
.
/
W
"
c
#
.
/
W
v
U
.
l
x
;
$
4
'
#
^
#
p
#
;
#
&
#
{
#
'
E
O
0
|
f
s
o
'
#
^
#
'
X
0
o
k
h
~
'
#
^
#
C
#
.
#
(
#
a
#
^
#
a
#
)
#
x
#
(
#
9
#
+
#
4
#
)
#
.
#
(
#
Y
#
^
#
z
#
^
#
Z
#
)
#
}

Try it online!

Explanation

Perl's syntax is very forgiving, so the basics of this are pretty simple to achieve. Variables are normally declared like $_=... but you can have whitespace separating the sigil $ and the variable name, which means it's possible to assign to variables without any complicated tricks. To build the actual code to generate the FizzBu-ApplePie numbers, it's possible to XOR two strings, utilising the newlines so that additional whitespace doesn't need to be removed. I used this script to generate the strings to XOR.

The resultant strings end up with a NUL byte at the start and a trailing newline which Perl won't like in the call, so that needs to be XORed again to switch out to the desired characters. Once the desired code is in $_, all that needs to happen is a call to eval.

Apparently eval doesn't exist at a callable location the way we want to call it, but fortunately, evalbytes exists within the CORE:: namespace. Using the sub sigil (&) we can build a string and pass in (&{"CORE::evalbytes"}) in much the same way as the main string is built.

I'd hoped to be able to use s///e, but a newline between the final delimiter and the modifiers seemed to cause problems.

The FizzBuzz routine was taken from primo's excellent answer.

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