Activity for CrSb0001
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Edit | Post #293915 | Initial revision | — | 6 days ago |
Answer | — |
A: Compute the determinant Python 3.8+, 28 bytes ```python from numpy.linalg import det ``` Remember that `from ... import ...` can be used to save bytes. Note that this has already been mentioned in a comment section on @Quintec's answer, but I'm only posting this so this method specifically has its own answer, as it... (more) |
— | 6 days ago |
Edit | Post #293849 |
Post edited: -1 byte |
— | 19 days ago |
Edit | Post #293849 | Initial revision | — | 20 days ago |
Answer | — |
A: Caesar shift cipher Python 3, 86 85 bytes The reasoning behind why this works is basically that 1. we can directly compare the ordinal values of characters (apparently) and 2. we only need that if a character is alphanumeric, then 'A' which is very interesting to think about. Also, if we have an expression of th... (more) |
— | 20 days ago |
Comment | Post #284028 |
Since everything is comparable in Python 2, you could for example write
```python
if a<b<[]>c>d:foo()
```
for 19 bytes instead of
```python
if a<b and c>d:foo()
```
for 20 bytes since lists are always greater than integers here.
---
Note that this doesn't work in Python 3 due to some re... (more) |
— | 20 days ago |
Comment | Post #284147 |
We can further golf this using the following snippet:
```python
for i in range(150):print(i//15,'-',i%15)
```
This is 41 bytes (compared to your 49), unless we need `x` and/or `y` later.
As an alternative, if we need to use `y` later on, we can do this for 45 bytes:
```python
y=15
for i i... (more) |
— | 20 days ago |
Edit | Post #293759 |
Post edited: -2 bytes |
— | 26 days ago |
Edit | Post #293751 |
Post edited: -12 bytes |
— | 27 days ago |
Edit | Post #293712 |
Post edited: |
— | 27 days ago |
Edit | Post #293788 |
Post edited: |
— | 29 days ago |
Edit | Post #293788 |
Post edited: |
— | 29 days ago |
Edit | Post #293788 | Initial revision | — | 29 days ago |
Answer | — |
A: Cumulative Counts [Lean 4], 111 bytes ```lean def c(l:List Nat):List Nat:=((λx=>((l.reverse).drop x).count (l.reverse)[x]!)(List.range l.length)).reverse ``` [Try it online!] Given how verbose Lean syntax is, and how you can't really assign variables to keywords in a way that it saves bytes the vast majority ... (more) |
— | 29 days ago |
Edit | Post #293736 |
Post edited: -15 bytes |
— | 29 days ago |
Edit | Post #293785 | Initial revision | — | 29 days ago |
Answer | — |
A: Cumulative Counts Python 3, 50 bytes We can simply omit the lambda name since we don't refer to it anywhere in the lambda definition. ```python lambda l:[l[:i+1].count(j)for i,j in enumerate(l)] ``` Example usage in the terminal: ```python >>>(lambda l:[l[:i+1].count(j)for i,j in enumerate(l)])([1,1,2,2,2... (more) |
— | 29 days ago |
Edit | Post #293736 |
Post edited: -5 bytes |
— | 29 days ago |
Edit | Post #293750 |
Post edited: |
— | about 1 month ago |
Comment | Post #293750 |
Sorry, I can change it to “a positive integer >= 0” (more) |
— | about 1 month ago |
Comment | Post #293750 |
…isn’t that how integers are typically stored in computer memory? I don’t see what you’re trying to ask (more) |
— | about 1 month ago |
Edit | Post #293759 | Initial revision | — | about 1 month ago |
Answer | — |
A: Caesar shift cipher [Lean 4], 183 181 bytes ``` def c(t:String)(s:Nat):String:=t.map (λc=>if Char.isAlpha c then let b:=if Char.isLower c then 'a'else 'A';let h:=(Char.toNat c-Char.toNat b+s)%26+Char.toNat b;Char.ofNat h else c) ``` Try it online! Honestly it's surprising that 1) you can just throw everything o... (more) |
— | about 1 month ago |
Edit | Post #293751 |
Post edited: -5 bytes |
— | about 1 month ago |
Comment | Post #293750 |
@#53890 I'll keep the idea of first posting to the Sandbox in mind. (more) |
— | about 1 month ago |
Comment | Post #293750 |
I've updated the ruleset in the question @#53890 @#77222 (more) |
— | about 1 month ago |
Edit | Post #293750 |
Post edited: |
— | about 1 month ago |
Edit | Post #293736 |
Post edited: Updated bytecount to take into account non-printable characters. |
— | about 1 month ago |
Edit | Post #293751 |
Post edited: -3 bytes |
— | about 1 month ago |
Comment | Post #293750 |
If it’s a builtin function that takes in a base 10 number and outputs a number in base 16 as a string or whatever, it is banned. So both `toHex` and `.toString(16)` would be banned.
As for xxd, I would say that it does not apply in the context of this challenge, as it is used primarily to create o... (more) |
— | about 1 month ago |
Edit | Post #293751 | Initial revision | — | about 1 month ago |
Answer | — |
A: Convert to Hexadecimal Lean 4, 103 100 95 83 bytes ```lean def h:=λi=>if iif i| 00000010 3c 31 36 74 68 65 6e 20 73 21 22 7b 22 30 31 32 |<16then s!"{"012| 00000020 33 34 35 36 37 38 39 41 42 43 44 45 46 22 2e 67 |3456789ABCDEF".g| 00000030 65 74 20 e2 9f a8 69 e2 9f a9 7d 22 65 6c 73 65 |et ...i...}"else| 00000... (more) |
— | about 1 month ago |
Edit | Post #293750 | Initial revision | — | about 1 month ago |
Question | — |
Convert to Hexadecimal Challenge Write a program that takes in a number greater than or equal to 0 and outputs its representation in hexadecimal (base 16). Examples ```none 0 => 0 1 => 1 10 => A 15 => F 16 => 10 107 => 6B 153 => 99 207 => CF 1000 => 3E8 10381 => 288D 48821 =>... (more) |
— | about 1 month ago |
Edit | Post #293745 | Initial revision | — | about 1 month ago |
Answer | — |
A: "Hello, {name}!" Lean 4, 39 bytes ```lean def x(i:String):String:=s!"Hello, {i}!" ``` Try it online! (Note that TIO only supports Lean 3, so I sadly am unable to use a link from there.) (more) |
— | about 1 month ago |
Edit | Post #293736 |
Post edited: -6 bytes |
— | about 1 month ago |
Edit | Post #293739 | Initial revision | — | about 1 month ago |
Question | — |
Tips for golfing in Lean [Lean] is an interactive theorem prover and a functional programming language created in 2013. What tips do you have for golfing in Lean? Tips should be specific to Lean ("remove comments" is not an answer), and stick to one tip per answer. (more) |
— | about 1 month ago |
Edit | Post #293736 | Initial revision | — | about 1 month ago |
Answer | — |
A: Give the fool's fibonacci sequence [Lean 4], 115 109 104 89 bytes Note: had to update bytecount to take into account non-printable characters. For anyone who isn't familiar with Lean, it's basically an interactive theorem prover that can also be used for regular math computation. Those who are familiar with Haskell would pro... (more) |
— | about 1 month ago |
Edit | Post #293713 |
Post edited: -13 bytes, -69 bytes total. |
— | about 1 month ago |
Edit | Post #293713 |
Post edited: -56 bytes |
— | about 1 month ago |
Edit | Post #293713 | Initial revision | — | about 1 month ago |
Answer | — |
A: Give the fool's fibonacci sequence Python 3, 131 75 62 bytes ```python f=lambda n:n>0and 2+3f(n-1)+4f(n-2)+2sum(map(f,range(n-2))) ``` I know, a one-liner is boring. This is because I apparently didn't need a separate function/lambda to compute the sum of something. So there you have it, a 56 69 (nice) byte save in total. :D (more) |
— | about 1 month ago |
Edit | Post #293712 | Initial revision | — | about 1 month ago |
Answer | — |
A: Ratio limits of fibonacci-like series Python 3, 26 bytes ```python lambda n:(n+(nn+4).5)/2 ``` We can actually just compute this directly, although I could have taken an alternate path considering the fact that, given $Rn$ as the ratio between any two terms in the $n$-fibonacci sequence defined above (where $n\in\mathbb Z$), then... (more) |
— | about 1 month ago |
Edit | Post #293689 | Initial revision | — | about 1 month ago |
Answer | — |
A: "Hello, World!" [Emmental], 51 bytes ```none #72.#101.#108::..#111:.#44.#32.#87..#114..#100.#33. ``` [Try it online!] Basically what goes on is `#[num]` pushes the ASCII value of `num` onto the top of the stack, `:` duplicates the top of the stack, and `.` prints the top of the stack. Admittedly this i... (more) |
— | about 1 month ago |
Edit | Post #293673 | Initial revision | — | about 1 month ago |