weekly challenges

Perl weekly challenges are small programming challenges curated by Perl and Raku volunteers. My goal is to complete the ones that strike my interest using Uiua, my favorite programming language.


1.1 Write a script to replace the character 'e' with 'E' in the string "Perl Weekly Challenge". Also print the number of times the character 'e' is found in the string. Try it!

⊃/+⍜▽¯=@e.

1.2 Write a script to solve the FizzBuzz problem and print the numbers 1 through 20. However, any number divisible by 3 should be replaced by the word "Fizz" and any divisible by 5 by the word "Buzz." Those numbers that are both divisible by 3 and 5 become "FizzBuzz." Try it!

¤.+1⇡20 /+×1_2=0≡◿3_5 ∵(&p⟨∘|"Fizz"◌|"Buzz"◌|"FizzBuzz"◌⟩)

2.1 Write a script to remove leading zeros from positive numbers. Try it!

▽¬\×=@0.

2.2 Write a script that can convert integers to and from a base35 representation, using the characters 0-9 and A-Y. Try it!

A ← ⊂+@0⇡10+@a⇡25 ToPentatrigesimal ← ⊏:A◌⍢(⊙⊂⌊⊃÷◿35)±:[] FromPentatrigesimal ← /+×⇌ⁿ:35⇡⧻.⊗:A

3.1 Create a script to generate 5-smooth numbers, whose prime divisors are less or equal to 5. Try it!

▽/×<6°/×.+1⇡100

3.2 Create a script that generates Pascal Triangle. The Pascal Triangle should have at least 3 rows. Try it!

◌⍥(&p.↻1⊂1_1≡/+◫2):&p.¤1-1 6

4.1 Write a script to output the same number of PI digits as the size of your script. Say, if your script size is 10, it should print 3.141592653. Try it!

&pπ # a comment!

4.2 You are given a list of words and a list of letters. Print each word that can be made using only the given letters. You can use each letter only once, though there can be duplicates and you can use each of them once. You don't have to use all the letters. Try it!

▽:⟜≡◇(≥0/↧⬚0-°⊚-@a):¤°⊚-@a

5.1 Write a program which prints out all anagrams for a given word. Try it!

▽:⟜≡◇(≍⊏⍏.):¤⊏⍏.

5.2 Write a program to find the word with the most anagrams. Try it!

⊡⊢⍖°⊚⊛⍚(⊏⍏.).

6.1 Create a script which takes a list of numbers and returns its compact form. For example, if you pass "1,2,3,4,9,10,14,15,16" then it should return the compact form like "1-4,9,10,14-16". Try it!

⊂1+1\+≠1↘1°\+.⊜⋕≠@,. /$"_,_"⊜(□($"_-_"⊃⊢(⊢⇌)|/$"_,_")<3⧻.)

7.1 Print all the niven numbers from 0 to 50 inclusive, each on their own line. A niven number is a non-negative number that is divisible by the sum of its digits. Try it!

∵&p▽≡(=0◿/+-@0°⋕.).⇡51

8.1 Write a script that computes the first five perfect numbers. A perfect number is an integer that is the sum of its positive proper divisors (all divisors except itself). Try it!

≡(×⊃(ⁿ:2-1|-1ⁿ:2)) 2_3_5_7_13

8.2 Write a function whose argument is a list of strings, which will be lines of text. The function should insert spaces at the beginning of the lines of text so that if they were printed, the text would be centered, and return the modified lines. Try it!

⍚(⊂+@ ⊚)⌊÷2-⟜/↥∵◇⧻.

9.1 Write a script that finds the first square number that has at least 5 distinct digits. Try it!

×.⍢(+1|<5⧻◴°⋕×..)1

258.1 Write a script to find out how many integers in a list have an even number of digits. Try it!

/+¬◿2∵◇⧻°⋕

258.2 Write a script to find the sum of values whose indices' binary representation has exactly k number of bits set. Try it!

/+▽=⊙:≡/+⋯⇡⧻.

257.1 Write a script to find out how many integers in a list are smaller than each integer. Try it!

≡/+⊞<.

256.1 Write a script to find the number of pairs in the given array. A the items in a pair are reversals of each other. Try it!

/+-1°⊚⊛≡(⊏⍏.)