Open ErikSchierboom opened 2 weeks ago
I'd like to do largest-series-product
I'll start easy and try leap
That's actually not that easy, but there is a video to help out: https://www.youtube.com/watch?v=H7GJbSHgWjw&ab_channel=TacitSanctuary
/≠=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=
I think we found our first deep -dive 🎉🥳
Here are three more options:
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.
1
(indicating divisibility) and get the length of the arrayAlternatively, one can filter all the items for 1
s (▽ =1.
) and then count (⧻
) the 1
s
⧻▽ =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>
But then we don't need the earlier equality comparison and can count what's divisible exactly:
◿2⧻▽ =0. ◿4_100_400 <input>
Fantastic writeup! I'm happy for you to join in adding some exercises :) (if you'd like and have time)
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
=2⊢↘1 datetime °datetime [<input> 2 29]
[year month day]
to a timestamp using
↘
(drop) the first element (the year)⊢
(first) return the first element (the month)And yes =29⊢↘2
works for the same reason.
If we need to turn this into a function, a bit of reshuffling is necessary.
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 nothingThe 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 stackLeap ← =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]
I'll do isogram
@vaeng let me know when you have something. I'm happy to write all of the above as approaches.
@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
=1
can always be dropped, so yeah nice! You basically did the condensed version of the first solution in https://github.com/exercism/uiua/issues/7#issuecomment-2471454928
https://github.com/exercism/uiua/issues/7#issuecomment-2471474194 still my best one though.
I'll start writing deep dive docs
I'll do difference-of-squares
@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
I'll do darts
and hamming
@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!
I'll take pangram
I'll work on eliuds-eggs
and collatz-conjecture
.
I'll try acronym. Let's see some string magic.
Acronym was okay, let's see how Bob goes.
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)
Done, however I was too hasty in declare "resistor color" as simple.
I am halfway done writing the approaches. Maybe I'll do an exercise then.
In the meanwhile one of my colleagues solved leap... interestingly
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
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.
In the meanwhile one of my colleagues solved leap... interestingly
That's definitely worthy of an approach! 😮
I'll do raindrops
and reverse-string
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 🤷
I'm not sure about giving the return value a name
The built-in function's tooltips give something like dip: Temporarily pop ...
, so I would keep it that way.
The naming of return value(s) and parameters looks useful as a more relatable way to understand the signature of a function
I'll do gigasecond
@vaeng Let me know what you think: https://github.com/exercism/uiua/pull/29
I'll do grains
and rna-transcription
And armstrong-numbers
and nucleotide-count
I'll do hexadecimal next, if it weren't deprecated. isbn-verifier it is.
I'll do rotational cipher
I'll do square-root
and sum-of-multiples
21 exercises in two days. What an exciting language!
I'm so loving it!
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 :smiley:
Edit: also please add
resistor-color-trio
to the master list at the top as well, thank you Erik 😃
Done.
I'll do scrabble-score
I'll take roman-numerals
Imma do anagram
and resistor expert
resistor expert
? I don't know that exercise
I'll do flatten-array
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
Superficially it looks like resistor-color-trio but with one added suffix. If so, I don't think it's that interesting but 🤷
Yeah, trio
to expert
didn't really have a distinct feel compare to trio
to duo
. Imma just do anagram
and find something later
I'll take allergies
And diamond
Let's use this issue to claim exercises we want to add.
acronym
- vaengarmstrong-numbers
- ErikSchierboombob
- vaengcollatz-conjecture
- ErikSchierboomdarts
- ErikSchierboomdifference-of-squares
- ErikSchierboomeliuds-eggs
- ErikSchierboomgigasecond
- vaenggrains
- ErikShierboomhamming
- ErikSchierboomisbn-verifier
- vaengisogram
- ErikSchierboomlargest-series-product
- ErikSchierboomleap
- vaengpangram
- ErikSchierboomraindrops
- ErikSchierboomresistor-color
- glaxxieresistor-color-duo
- glaxxieresistor-color-trio
- glaxxiereverse-string
- ErikSchierboomrna-transcription
- ErikSchierboomrotational-cipher
- glaxxieseries
- ErikSchierboomsquare-root
- ErikSchierboomsum-of-multiples
- ErikSchierboomtwo-fer
- vaeng