Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement exercises #7

Open
24 of 26 tasks
ErikSchierboom opened this issue Nov 12, 2024 · 68 comments
Open
24 of 26 tasks

Implement exercises #7

ErikSchierboom opened this issue Nov 12, 2024 · 68 comments

Comments

@ErikSchierboom
Copy link
Member

ErikSchierboom commented Nov 12, 2024

Let's use this issue to claim exercises we want to add.

  • acronym- vaeng
  • armstrong-numbers - ErikSchierboom
  • bob- vaeng
  • collatz-conjecture - ErikSchierboom
  • darts - ErikSchierboom
  • difference-of-squares - ErikSchierboom
  • eliuds-eggs - ErikSchierboom
  • gigasecond - vaeng
  • grains - ErikShierboom
  • hamming - ErikSchierboom
  • isbn-verifier - vaeng
  • isogram - ErikSchierboom
  • largest-series-product - ErikSchierboom
  • leap- vaeng
  • pangram - ErikSchierboom
  • raindrops - ErikSchierboom
  • resistor-color - glaxxie
  • resistor-color-duo - glaxxie
  • resistor-color-trio - glaxxie
  • reverse-string - ErikSchierboom
  • rna-transcription - ErikSchierboom
  • rotational-cipher - glaxxie
  • series - ErikSchierboom
  • square-root - ErikSchierboom
  • sum-of-multiples - ErikSchierboom
  • two-fer- vaeng
@ErikSchierboom
Copy link
Member Author

I'd like to do largest-series-product

@vaeng
Copy link
Contributor

vaeng commented Nov 12, 2024

I'll start easy and try leap

@ErikSchierboom
Copy link
Member Author

That's actually not that easy, but there is a video to help out: https://www.youtube.com/watch?v=H7GJbSHgWjw&ab_channel=TacitSanctuary

@ErikSchierboom ErikSchierboom transferred this issue from exercism/uiua-test-runner Nov 12, 2024
@SleeplessByte
Copy link
Member

SleeplessByte commented Nov 12, 2024

/≠=0◿4_100_400 <input>

Apparently.

From the comment:

It's a variadic exclusive or. It's only true if an odd number of inputs are true; it fits here since each condition is a subset of the prior and reverses the result. xor can also be thought of as a conditional toggle (a xor b = if b then not a else a).

Always great when kagi gives no real results, but once I clicked / (reduce) + (not equals) + = (equals) + (modulus) + _ (array syntax), and then cried a little, I understand.

◿2_3_4_10_100 10_10_10_10_10

# equivalent
◿2_3_4_10_100 10

# returns
[0 1 2 0 10]

So first give me an array that is the remainder of input / value:

◿4_100_400 <input>

For each item, does it compare to 0 (aka is it divisible?)

=0◿4_100_400 2100
[1 1 0]

=0◿4_100_400 2024
[1 0 0]

=0◿4_100_400 2017
[0 0 0]

But with reduce, the function not equals is called against the previous value.

\≠=0◿4_100_400 2100
[1 0 0]

\≠=0◿4_100_400 2024
[1 1 1]

\≠=0◿4_100_400 2017
[0 0 0]

You can compare the answers (steps) here with the previous each result.
The first item in the array should always be the same.
Then, in the reduce against not equals, the value will be a 1 if the previous result does not match the current one.

[1 -> 1] these are the same so, 0
[1 -> 0] these are different, so 1

In the 2100 case, what happens is:

◿4_100_400 2100
[0 0 100]

=0◿4_100_400 2100
[1 1 0]

# In other words
2100 % 4   => 0    =>   0 == 0   => 1
2100 % 100 => 0    =>   0 == 0   => 1
2100 % 400 => 100  => 100 == 0   => 0

The first value (1) is the initial reduced value [1]
The second value (1) is compared to the result (1). 1 ≠ 1 => 0
The last value (0) is compared to the result (0) 0 ≠ 0 => 0

Therefore: not leap.

The 2024 case:

◿4_100_400 2024
[0 24 24]

=0◿4_100_400 2024
[1 0 0]

# In other words
2024% 4   => 0    =>   0 == 0   => 1
2024% 100 => 24   =>  24 == 0   => 0
2024% 400 => 24   =>  24 == 0   => 0

The first value (1) is the initial reduced value [1]
The second value (1) is compared to the result (0). 1 ≠ 0 => 1
The last value (0) is compared to the result (1) 0 ≠ 1 => 1

Therefore: leap.

It works because for each division the result (1 or 0) needs to be different from the previous, and you need an odd number of 1 (divisible by x) for the entire thing to be 1.

I can now rest in peace(s)

Playground (pad): https://www.uiua.org/pad?src=0_14_0-dev_2__TGVhcCDihpAgL-KJoD0w4pe_NF8xMDBfNDAwCgriiLVMZWFwIFsyMDAwIDIwMDEgMjAwNCAyMDE3IDIwMjQgMjEwMF0KIyBleHBlY3RlZDogWzEgMCAxIDAgMSAwXQo=

@vaeng
Copy link
Contributor

vaeng commented Nov 12, 2024

I think we found our first deep -dive 🎉🥳

@SleeplessByte
Copy link
Member

SleeplessByte commented Nov 12, 2024

Here are three more options:

The sum of "which are divisible" must be an odd number

I think, if my thought process is right, then the following is equivalent

=1◿2/+=0◿4_100_400 <input>

If each divisible item is counted as a 1 and each item that yields a remainder is 0, then the sum of all the 1 and 0 gives us an odd number when it's leap and even number when it's not.

Filter array for 1 (indicating divisibility) and get the length of the array

Alternatively, one can filter all the items for 1s (▽ =1.) and then count () the 1s

⧻▽ =1. <array> is always equivalent to /+ in this context because filtering for 1 and then getting the length, is the same as summing all the 1.

=1◿2⧻▽ =1. =0◿4_100_400 <input>

Simplify that

But then we don't need the earlier equality comparison and can count what's divisible exactly:

◿2⧻▽ =0. ◿4_100_400 <input>

@ErikSchierboom
Copy link
Member Author

Fantastic writeup! I'm happy for you to join in adding some exercises :) (if you'd like and have time)

@SleeplessByte
Copy link
Member

SleeplessByte commented Nov 12, 2024

Ok. One more and then I need to go do something else. This is way too interesting.

Here is big brain mode:

=⊢↘ 1 datetime °datetime [<input> 2 29] 2

Or alternatively written:

=2⊢↘1 datetime °datetime [<input> 2 29]
  • Convert the input array [year month day] to a timestamp using
    • ° (un) inverting the behaviour of the function
    • datetime timestamp to datetime array
  • Convert the timestamp back into a datetime array
  • (drop) the first element (the year)
  • (first) return the first element (the month)
  • ...it should be February!

And yes =29⊢↘2 works for the same reason.

If we need to turn this into a function, a bit of reshuffling is necessary.

Reordering the stack

Okay, the input is not at the end, so it cannot be "inserted" from the top, yay. But that can be fixed using:

  • (fork): Call two functions on the input (or with a|b|c|...|n, n function! This is called a function pack)
  • (gap): Discard the top stack value then call a function
  • (identity): Do nothing

The date we want looks like [<input> 2 29] (which is year-2-29). Therefore the input needs to be reordered

Reorder ← [⊃(⋅⋅∘|⋅∘|∘)]
  • [<make an array of what's here]
  • ⊃(call|on|each|function|from|right|to|left)
    • ⋅⋅∘: this is equivalent to drop(2).first on an array, so third on the stack
    • ⋅∘: this is equivalent to drop(1).first on an array, so second on the stack
    • : this is equivalent to first on an array, so top of the stack
Leap ← =2⊢↘1 datetime °datetime [⊃(⋅⋅∘|⋅∘|∘)] 29 2

∵Leap[2000 2001 2004 2017 2024 2100]
# expected: [1 0 1 0 1 0]

# [⊃(⋅⋅∘|⋅∘|∘)] 29 2 2000
# => [2000 ⊃(⋅⋅∘|⋅∘)]
# => [2000 2 ⊃(⋅⋅∘)]
# => [2000 2 29]

@ErikSchierboom
Copy link
Member Author

I'll do isogram

@SleeplessByte
Copy link
Member

@vaeng let me know when you have something. I'm happy to write all of the above as approaches.

@vaeng
Copy link
Contributor

vaeng commented Nov 12, 2024

@SleeplessByte

=1◿2/+=0◿4_100_400

It's my first dive into an array language, and this is what I came up with in #9, after I understood that I had an array in an array and thus needed deshaping. Fixed that, thank you

@SleeplessByte
Copy link
Member

=1 can always be dropped, so yeah nice! You basically did the condensed version of the first solution in #7 (comment)

#7 (comment) still my best one though.

I'll start writing deep dive docs

@ErikSchierboom
Copy link
Member Author

ErikSchierboom commented Nov 13, 2024

I'll do difference-of-squares

@ErikSchierboom
Copy link
Member Author

@vaeng I've done some course regex replaces on the 8th track's exercise (which is a stack-based language) to create Uiua test files. They'll not be perfect, but they are a good starting point. You can find the branch here: https://github.com/exercism/8th/tree/uiua

@ErikSchierboom
Copy link
Member Author

I'll do darts and hamming

@vaeng
Copy link
Contributor

vaeng commented Nov 13, 2024

@vaeng I've done some course regex replaces on the 8th track's exercise (which is a stack-based language) to create Uiua test files. They'll not be perfect, but they are a good starting point. You can find the branch here: https://github.com/exercism/8th/tree/uiua

That will speed things up, thanks!

@ErikSchierboom
Copy link
Member Author

I'll take pangram

@ErikSchierboom
Copy link
Member Author

I'll work on eliuds-eggs and collatz-conjecture.

@vaeng
Copy link
Contributor

vaeng commented Nov 13, 2024

I'll try acronym. Let's see some string magic.

@vaeng
Copy link
Contributor

vaeng commented Nov 13, 2024

Acronym was okay, let's see how Bob goes.

@glaxxie
Copy link
Contributor

glaxxie commented Nov 13, 2024

Let me start with something simple like resistor color first
I still need to set this up properly, it doesnt seem like it likes window much (at least on my end)

@glaxxie
Copy link
Contributor

glaxxie commented Nov 13, 2024

Done, however I was too hasty in declare "resistor color" as simple.

@SleeplessByte
Copy link
Member

I am halfway done writing the approaches. Maybe I'll do an exercise then.

In the meanwhile one of my colleagues solved leap... interestingly

@glaxxie
Copy link
Contributor

glaxxie commented Nov 14, 2024

I've done the first 3 exercises of the resistor color series and PR them.
The example solution might not be the best or clear idiomatic, but it has been fun so far

@ErikSchierboom
Copy link
Member Author

The example solution might not be the best or clear idiomatic, but it has been fun so far

Neither are mine. That's totally fine! Thanks for the PRs.

@ErikSchierboom
Copy link
Member Author

In the meanwhile one of my colleagues solved leap... interestingly

That's definitely worthy of an approach! 😮

@ErikSchierboom
Copy link
Member Author

I'll do raindrops and reverse-string

@ErikSchierboom
Copy link
Member Author

Whilst reading the docs, I came across the fact that you can document a function's parameters via comments: https://www.uiua.org/tutorial/documentation
This might be useful for stubs. What do you all think?

I'm not sure about giving the return value a name 🤷

@glaxxie
Copy link
Contributor

glaxxie commented Nov 15, 2024

Finished the rotational cipher !
I was stuck for quite some time despite having the right idea, finally discover the keyword switch and things just click into places.
End up quite happy with the final result.
Imma take a closer look at the language tour and the doc before picking up another new exercise, you guys have fun in the mean time!
Edit: also please add resistor-color-trio to the master list at the top as well, thank you Erik 😃

@vaeng
Copy link
Contributor

vaeng commented Nov 15, 2024

Edit: also please add resistor-color-trio to the master list at the top as well, thank you Erik 😃

Done.

@ErikSchierboom
Copy link
Member Author

I'll do scrabble-score

@ErikSchierboom
Copy link
Member Author

I'll take roman-numerals

@glaxxie
Copy link
Contributor

glaxxie commented Nov 15, 2024

Imma do anagram and resistor expert

@ErikSchierboom
Copy link
Member Author

resistor expert? I don't know that exercise

@ErikSchierboom
Copy link
Member Author

I'll do flatten-array

@glaxxie
Copy link
Contributor

glaxxie commented Nov 15, 2024

resistor expert? I don't know that exercise

It's this one
I just remember that this somehow doesn't exist on the problem-specifications, was it purged at some point or wasit python exclusive?
I think I ported this from python to powershell manually as well since it couldnt be pulled from the specs

@ErikSchierboom
Copy link
Member Author

Superficially it looks like resistor-color-trio but with one added suffix. If so, I don't think it's that interesting but 🤷

@glaxxie
Copy link
Contributor

glaxxie commented Nov 15, 2024

Yeah, trio to expert didn't really have a distinct feel compare to trio to duo. Imma just do anagram and find something later

@ErikSchierboom
Copy link
Member Author

I'll take allergies

@ErikSchierboom
Copy link
Member Author

And diamond

@glaxxie
Copy link
Contributor

glaxxie commented Nov 16, 2024

Imma take a crack at secret-handshake
Edit: Done!

@glaxxie
Copy link
Contributor

glaxxie commented Nov 17, 2024

Added atbash-cipher !

@ErikSchierboom
Copy link
Member Author

I'll do etl, high-scores and matrix

@ErikSchierboom
Copy link
Member Author

And pascals-triangle

@glaxxie
Copy link
Contributor

glaxxie commented Nov 18, 2024

Added luhn

@glaxxie
Copy link
Contributor

glaxxie commented Nov 18, 2024

Added crypto square
Edited: and protein translation

@ErikSchierboom
Copy link
Member Author

I'll do space-age

@ErikSchierboom
Copy link
Member Author

I'll tackle the song exercises: bottle-song, house, proverb and twelve-days

@ErikSchierboom
Copy link
Member Author

I'll do run-length-encoding

@ErikSchierboom
Copy link
Member Author

And saddle-points

@ErikSchierboom
Copy link
Member Author

I'll do kindergarten-garden, knapsack and simple-cipher

@ErikSchierboom
Copy link
Member Author

ErikSchierboom commented Nov 25, 2024

I'll work on matching-brackets, prime-factors, nth-prime and triangle

@vaeng
Copy link
Contributor

vaeng commented Nov 26, 2024

I'll try my luck on robot-simulator

@ErikSchierboom
Copy link
Member Author

I'll try game-of-life

@ErikSchierboom
Copy link
Member Author

I'll do strain and list-ops

@vaeng
Copy link
Contributor

vaeng commented Nov 27, 2024

I'll try to go OOP with dnd-character

@vaeng
Copy link
Contributor

vaeng commented Nov 27, 2024

I'll do yacht.

@ErikSchierboom
Copy link
Member Author

I'll do binary-search

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants